This is a private module sandbox of Wyang, for their own experimentation. Items in this module may be added and removed at Wyang's discretion; do not rely on this module's stability.
local export = {}
local match = mw.ustring.match
local gsub = mw.ustring.gsub
local sub = mw.ustring.sub
local len = mw.ustring.len
function export.main(frame)
local m_zh = require("Module:zh")
local m_links = require("Module:links")
local availableParam = {}
local args = frame:getParent().args
local senses = { = { = {} }}
local mods = {
= true,
= true,
= true,
= true,
= true,
= true
}
i = 1
for _, arg in ipairs(args) do
arg = gsub(arg, "\n$", "")
if arg ~= "-" then
if match(arg, "^...?.?: ") and mods??")] then
senses??")] = match(arg, "^...?.?: (.+)")
elseif match(arg, "^x+: ") then
table.insert(senses, tostring( mw.html.create( "dd" ):wikitext( match(arg, "^x+: (.+)") )))
else
senses + 1] = arg
end
else
i = i + 1
senses = { = {} }
end
end
local paramSubset = {
{ 1, 1, "pos", nil },
{ 2, 2, "definition", nil },
{ 3, "mw", "cls", "" },
{ 4, "dial", "dial", "" },
{ 5, "syn", "syn", "" },
{ 6, "ant", "ant", "" },
{ 7, "also", "also", "" },
{ 8, "lb", "lb", nil },
}
table.sort(paramSubset, function(first, second) return first < second end)
local function makeClassifier(text)
if not text then return nil end
local lang_abbrev = {
= "Mandarin",
= "Cantonese", = "Gan", = "Hakka", = "Jin",
= "Min Dong", = "Min Nan", = "Teochew",
= "Wu", = "Xiang",
}
local result, categories = {}, {}
local m_zh_cat = require("Module:zh-cat")
for combination in mw.text.gsplit(text, ",") do
local varieties = match(combination, "^(+):") or nil
local remaining = match(combination, "^+:(.+)") or combination
local classifier = match(remaining, "^+") or nil
local gloss = match(remaining, "^+%-(.+)") or nil
local dialectTags = {}
if varieties then
for variety in mw.text.gsplit(varieties, "+") do
table.insert(dialectTags, lang_abbrev)
end
end
table.insert(result,
m_zh.link(frame, nil, { classifier, tr = "-" }, pagename) ..
(varieties
and (tostring( mw.html.create( "span" )
:css( "padding-left", ".5em" )
:css( "color", "#105E02" )
:css( "font-size", "80%" )
:wikitext( "[" .. table.concat( dialectTags ) ..
(gloss and " – " .. gloss or "") .. "]" )))
or "" ))
table.insert(categories, m_zh_cat.categorize("Classifier:" .. classifier))
end
return table.concat(result, ", ") .. (mw.title.getCurrentTitle().nsText == "" and table.concat(categories) or "")
end
local function makePoS(text)
local pos_aliases = {
= "noun",
= "proper noun",
= "verb",
= "adjective",
= "adverb",
= "postposition",
= "conjunction",
= "particle",
= "pronoun",
= "proverb",
= "idiom",
= "]",
= "phrase",
= "interjection",
= "abbreviation",
= "classifier",
= "determiner",
}
local pos_set = {}
for pos in mw.text.gsplit(text, ",") do
table.insert(pos_set, pos_aliases)
end
return tostring( mw.html.create( "span" )
:css( "padding-right", ".6em" )
:css( "color", "#5A5C5A" )
:css( "font-size", "80%" )
:wikitext( "" ))
end
local function makeLabel(label_text)
if not label_text then return "" end
local lang = require("Module:languages").getByCode("zh")
local labels = require("Module:labels").show_labels(mw.text.split(label_text, "+"), lang)
return
tostring( mw.html.create( "span" )
:css( "padding-right", ".6em" )
:css( "color", "#105E02" )
:css( "font-size", "80%" )
:wikitext(
tostring(mw.html.create( "span" ):wikitext( "[" )) ..
sub(labels, 56, -38 ) ..
tostring(mw.html.create( "span" ):wikitext( "]" ))))
end
local function makeDialectal(text)
if not text then return nil end
local dialectEquiv = {}
local m_zh_dial = require("Module:zh-dial-syn/inline")
for dialWord in mw.text.gsplit(text, ",") do
table.insert(dialectEquiv,
tostring( mw.html.create( "dd" )
:wikitext( m_zh_dial.main( dialWord ))))
end
return tostring( mw.html.create( "dl" )
:wikitext( table.concat( dialectEquiv )))
end
local def_text = {}
for sense_i, sense in ipairs(senses) do
local availableParam, sense_text, p = {}, {}, {}
for _, data in pairs(paramSubset) do
p] = sense] or nil
table.insert(availableParam, sense] and data or nil)
end
if #sense > 0 then
table.insert(availableParam, "")
end
local function makeOther(text, class, no_plural, additional_text)
if not text and not additional_text then return "" end
local word_set = {}
if not additional_text then
for word in mw.text.gsplit(text, ",") do
table.insert(word_set,
tostring(mw.html.create( "span" )
:css( "padding-right", ".6em")
:wikitext( m_zh.link(frame, nil, mw.text.split( "*" .. word, ":" )))))
end
end
word_set = additional_text == "" and sense or word_set
return
tostring( mw.html.create( "dd" )
:wikitext(
tostring( mw.html.create( "span" )
:css( "padding-right", ".6em" )
:css( "color", "#8F390A" )
:css( "font-weight", "bold" )
:css( "font-size", "90%")
:wikitext(
tostring( mw.html.create( "span" )
:css( "border-radius", "5px" )
:css( "border", "solid #C0C2C0 1px" )
:css( "padding", "3px" )
:wikitext( "<tt>" .. class .. ((#word_set > 1 and not no_plural) and "s" or "") .. "</tt>" )))) ..
(additional_text or table.concat(word_set))))
end
rand = gsub(
math.ceil(math.random() * 100000000) .. sub(p, 1, 100),
"",
mw.ustring.codepoint("%1"))
table.insert(sense_text, (sense_i ~= 1 and "\n" or "") .. "# ")
table.insert(sense_text,
tostring( mw.html.create( "div" )
:attr( "title", "expand" )
:attr( "class", "mw-customtoggle-" .. rand )
:css( "background", "#FAF8F2" )
:css( "line-height", "200%" )
:wikitext(
makePoS( p ) ..
makeLabel( p ) ..
m_links.english_links(p) ..
tostring( mw.html.create( "span" )
:css( "float", "right" )
:css( "font-size", "100%" )
:wikitext(
tostring( mw.html.create( "span" )
:css( "padding-right", ".5em" )
:css( "color", "#105E02" )
:css( "font-size", "90%" )
:wikitext( table.concat( availableParam, " " ))) ..
( #availableParam > 0 and "▼" or "" ))))))
if #availableParam > 0 then
table.insert(sense_text,
tostring( mw.html.create( "div" )
:attr( "class", "mw-collapsible mw-collapsed mw-collapsible-content" )
:attr( "id", "mw-customcollapsible-" .. rand )
:css( "line-height", "250%" )
:css( "background-color", "#f9f9f9" )
:wikitext(
tostring( mw.html.create( "dl" )
:wikitext(
makeOther( p, "Classifier", false, makeClassifier( p )) ..
makeOther( p, "Synonym" ) ..
makeOther( p, "Antonym" ) ..
makeOther( p, "See also", true ) ..
makeOther( p, "Dialectal equivalents", false, makeDialectal( p )) ..
( #sense > 0
and
makeOther( nil, "Example", false, "" ) ..
tostring( mw.html.create( "dl" ):wikitext( table.concat( sense )))
or "" ))))))
end
table.insert(def_text, table.concat(sense_text))
end
return table.concat(def_text, "")
end
return export