Module:User:Vriullop

-- Sandbox: Module:headword local export = {}

local lemmas = { ["abbreviations"] = true, ["acronyms"] = true, ["adjectives"] = true, ["adnominals"] = true, ["adpositions"] = true, ["adverbs"] = true, ["affixes"] = true, ["articles"] = true, ["circumfixes"] = true, ["circumpositions"] = true, ["classifiers"] = true, ["cmavo"] = true, ["cmavo clusters"] = true, ["cmene"] = true, ["comparative adjectives"] = true, ["comparative adverbs"] = true, ["conjunctions"] = true, ["contractions"] = true, ["counters"] = true, ["determiners"] = true, ["diacritical marks"] = true, ["fu'ivla"] = true, ["gismu"] = true, ["Han tu"] = true, ["hanzi"] = true, ["hanja"] = true, ["idioms"] = true, ["infixes"] = true, ["interfixes"] = true, ["initialisms"] = true, ["interjections"] = true, ["kanji"] = true, ["letters"] = true, ["ligatures"] = true, ["lujvo"] = true, ["morphemes"] = true, ["non-constituents"] = true, ["nouns"] = true, ["numbers"] = true, ["numeral symbols"] = true, ["numerals"] = true, ["particles"] = true, ["phrases"] = true, ["postpositions"] = true, ["predicatives"] = true, ["prefixes"] = true, ["prepositions"] = true, ["prepositional phrases"] = true, ["preverbs"] = true, ["pronominal adverbs"] = true, ["pronouns"] = true, ["proverbs"] = true, ["proper nouns"] = true, ["punctuation marks"] = true, ["relatives"] = true, ["roots"] = true, ["suffixes"] = true, ["superlative adjectives"] = true, ["superlative adverbs"] = true, ["syllables"] = true, ["symbols"] = true, ["verbs"] = true, }

local nonlemmas = { ["active participles"] = true, ["adjectival participles"] = true, ["adjective forms"] = true, ["adjective comparative forms"] = true, ["adjective superlative forms"] = true, ["adverb forms"] = true, ["adverb comparative forms"] = true, ["adverb superlative forms"] = true, ["adverbial participles"] = true, ["agent participles"] = true, ["article forms"] = true, ["circumfix forms"] = true, ["combined forms"] = true, ["determiner comparative forms"] = true, ["determiner forms"] = true, ["determiner superlative forms"] = true, ["diminutive nouns"] = true, ["gerunds"] = true, ["infinitives"] = true, ["jyutping"] = true, ["kanji readings"] = true, ["misspellings"] = true, ["negative participles"] = true, ["nominal participles"] = true, ["noun case forms"] = true, ["noun forms"] = true, ["noun plural forms"] = true, ["numeral forms"] = true, ["participles"] = true, ["participle forms"] = true, ["particle forms"] = true, ["passive participles"] = true, ["past active participles"] = true, ["past participles"] = true, ["past participle forms"] = true, ["past passive participles"] = true, ["perfect active participles"] = true, ["perfect passive participles"] = true, ["pinyin"] = true, ["plurals"] = true, ["postposition forms"] = true, ["prefix forms"] = true, ["preposition contractions"] = true, ["preposition forms"] = true, ["prepositional pronouns"] = true, ["present active participles"] = true, ["present participles"] = true, ["present passive participles"] = true, ["pronoun forms"] = true, ["proper noun forms"] = true, ["rafsi"] = true, ["romanizations"] = true, ["romaji"] = true, ["singulatives"] = true, ["suffix forms"] = true, ["verb forms"] = true, ["verbal nouns"] = true, }

function export.full_headword(lang, sc, heads, tr, genders, inflections, categories, sort_key) local tracking_categories = {} heads = heads or {""} categories = categories or {} if #categories == 0 then if lang:getCode ~= "und" then table.insert(tracking_categories, "head tracking/no pos") require("Module:debug").track("head tracking/no pos") require("Module:debug").track("head tracking/no pos/lang/" .. lang:getCode) end else for _, cat in ipairs(categories) do if mw.ustring.sub(cat, 1, mw.ustring.len(lang:getCanonicalName) + 1) ~= lang:getCanonicalName .. " " then table.insert(tracking_categories, "head tracking/no lang category") require("Module:debug").track("head tracking/no lang category") require("Module:debug").track("head tracking/no lang category/lang/" .. lang:getCode) end end if mw.ustring.sub(categories[1], 1, mw.ustring.len(lang:getCanonicalName) + 1) == lang:getCanonicalName .. " " then local pos = mw.ustring.sub(categories[1], mw.ustring.len(lang:getCanonicalName) + 2) if lemmas[pos] or lemmas[pos:gsub("^reconstructed ", "")] then table.insert(categories, 1, lang:getCanonicalName .. " lemmas") elseif nonlemmas[pos] or nonlemmas[pos:gsub("^reconstructed ", "")] or lemmas[pos:gsub("^mutated ", "")] or nonlemmas[pos:gsub("^mutated ", "")] then table.insert(categories, lang:getCanonicalName .. " non-lemma forms") else table.insert(tracking_categories, "head tracking/unrecognized pos") require("Module:debug").track("head tracking/unrecognized pos") require("Module:debug").track("head tracking/unrecognized pos/lang/" .. lang:getCode) require("Module:debug").track("head tracking/unrecognized pos/pos/" .. pos) end end end -- Try to detect the script if it was not provided if not sc then sc = require("Module:scripts").findBestScript(heads[1] ~= "" and heads[1] or mw.title.getCurrentTitle.subpageText, lang) end -- Try to generate a transliteration if necessary -- Generate it if the script is not Latn or similar, and if no transliteration was provided if tr == "-" then tr = nil elseif not tr and not ((sc:getCode:find("Latn", nil, true)) or sc:getCode == "Latinx") then -- TODO: This should handle transliterations for each headword separately tr = lang:transliterate(heads[1] ~= "" and require("Module:links").remove_links(heads[1]) or mw.title.getCurrentTitle.subpageText, sc) end -- Format and return all the gathered information return format_headword(lang, sc, heads) .. format_transliteration(lang, sc, tr) .. format_genders(lang, sc, genders) .. format_inflections(lang, sc, inflections) .. require("Module:utilities").format_categories(categories, lang, sort_key) .. require("Module:utilities").format_categories(tracking_categories, lang, sort_key) end

-- Format a headword function format_headword(lang, sc, heads) local m_links = require("Module:links") local m_scriptutils = require("Module:script utilities") if type(heads) ~= "table" then heads = {heads} end -- Create a default headword. local default_head = mw.title.getCurrentTitle.subpageText -- Add links to multi-word page names when appropriate if default_head:find(" ", nil, false) then default_head = mw.text.split(default_head, " ", true) default_head = "" .. table.concat(default_head, " ") .. "" end if lang:getType == "reconstructed" or (lang:getType ~= "appendix-constructed" and mw.title.getCurrentTitle.nsText == "Appendix") then default_head = "*" .. default_head end -- If the list is empty, fill it with the default headword if #heads == 0 then heads = {default_head} end -- Try to detect the script if it was not provided if not sc then sc = require("Module:scripts").findBestScript(heads[1], lang) end for i, head in ipairs(heads) do		-- If the head is the empty string "", then replace it with the default if head == "" then head = default_head end -- Apply processing to the headword, for formatting links and such if head:find("[[", nil, true) then			head = m_links.language_link(head, nil, lang)		end		-- Add language and script wrapper		head = m_scriptutils.tag_text(head, lang, sc, "head")		heads[i] = head	end	return table.concat(heads, " or ") end

-- Format transliteration function format_transliteration(lang, sc, tr) if tr then local ret = " (" .. tr .. " )" if lang and mw.title.new(lang:getCanonicalName .. " transliteration", "Wiktionary").exists then ret = " •" .. ret end

return ret else return "" end end

function format_genders(lang, sc, genders) if genders and #genders > 0 then local gen = require("Module:gender and number") return " " .. gen.format_list(genders, lang) else return "" end end

-- Format the inflections following the headword function format_inflections(lang, sc, inflections) if inflections and #inflections > 0 then -- Format each inflection individually for key, infl in ipairs(inflections) do			-- If this inflection is a table, it contains parts -- consisting of alternating label-term pairs. Format them too. if type(infl) == "table" then inflections[key] = format_parts(lang, sc, infl) end end

return " (" .. table.concat(inflections, ", ") .. ")" else return "" end end

function format_parts(lang, sc, parts) local m_links = require("Module:links") for key, part in ipairs(parts) do		if type(part) ~= "table" then part = {term = part} end local qualifiers = "" if part.qualifiers and #part.qualifiers > 0 then qualifiers = mw.getCurrentFrame:expandTemplate{title = "qualifier", args = part.qualifiers} .. " "		end -- Convert the term into a full link -- Don't show a transliteration here, the consensus seems to be not to -- show them in headword lines to avoid clutter. local nolink = parts.nolink or (part.term == mw.title.getCurrentTitle.text) part = m_links.full_link(not nolink and part.term or nil, part.alt or (nolink and part.term or nil), lang, part.sc or sc, "bold", part.id, {genders = part.genders, tr = "-"}, mw.title.getCurrentTitle.prefixedText) if parts.accel then part = "" .. part .. " "		end part = qualifiers .. part parts[key] = part end return "''" .. parts.label .. "" .. (#parts > 0 and " " .. table.concat(parts, " or'' ") or "") end

return export