|
|
| (107 intermediate revisions by the same user not shown) |
| Line 1: |
Line 1: |
| local export = {} | | local export = {} |
| function full_headword(data) | | local pos_functions = {} |
| local tracking_categories = {}
| | |
| | local sub = mw.ustring.sub |
| | local find = mw.ustring.find |
| | local match = mw.ustring.match |
| | local gmatch = mw.ustring.gmatch |
| | local gsub = mw.ustring.gsub |
| | local u = mw.ustring.char |
| | local split = mw.text.split |
| | local gsplit = mw.text.gsplit |
| | |
| | local PAGENAME = mw.title.getCurrentTitle().text |
| | local NAMESPACE = mw.title.getCurrentTitle().nsText |
| | local SUBPAGENAME = mw.title.getCurrentTitle().subpageText |
| | |
| | local gender_key = { |
| | ["i"] = "in", |
| | ["a"] = "an", |
| | } |
| | |
| | local verb_key = { |
| | ["aditr"] = "agentive ditransitive", |
| | ["adit"] = "agentive ditransitive", |
| | ["ai"] = "agentive intransitive", |
| | ["asubj"] = "agentive subjective", |
| | ["at"] = "agentive transitive", |
| | ["imp"] = "impersonal", |
| | ["pass"] = "passive", |
| | ["udit"] = "unagentive ditransitive", |
| | ["ui"] = "unagentive intransitive", |
| | ["usubj"] = "unagentive subjective", |
| | ["ut"] = "unagentive transitive", |
| | ["utrans"] = "translative", |
| | ["?"] = "?", |
| | } |
| | |
| | local lang = require("Module:languages").getByCode("siwa") |
| | |
| | local function glossary_link(entry, text) |
| | return "[[wikt:Appendix:Glossary#" .. entry .. "|" .. (text or entry) .. "]]" |
| | end |
| | |
| | -- The main entry point. |
| | -- This is the only function that can be invoked from a template. |
| | function export.show(frame) |
| | if NAMESPACE == "Template" and SUBPAGENAME ~= "doc" then return end |
| | local parent_args = frame:getParent().args |
| | | |
| -- Script-tags the topmost header.
| | local poscat = frame.args[1] or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.") |
| local pagename = mw.title.getCurrentTitle().text
| | local class = frame.args[2]; if class == "" then class = nil end |
| local fullPagename = mw.title.getCurrentTitle().fullText
| | |
| local namespace = mw.title.getCurrentTitle().nsText
| | local data = { |
|
| | lang = lang, |
| if not data.lang or type(data.lang) ~= "table" or not data.lang.getCode then
| | heads = {}, |
| error("In data, the first argument to full_headword, data.lang should be a language object.")
| | inflections = {}, |
| end | | genders = {}, |
| | | pos_category = poscat, |
| if not data.sc then | | categories = {"Siwa " .. poscat} |
| data.sc = require("Module:scripts").findBestScript(data.heads and data.heads[1] ~= "" and data.heads[1] or pagename, data.lang)
| | } |
| else
| | |
| -- Track uses of sc parameter
| | if pos_functions[poscat] then |
| local best = require("Module:scripts").findBestScript(pagename, data.lang)
| | pos_functions[poscat](class, parent_args, data) |
| require("Module:debug").track("headword/sc")
| | end |
|
| | |
| if data.sc:getCode() == best:getCode() then
| | return require("Module:headword").full_headword(data) |
| require("Module:debug").track("headword/sc/redundant")
| | end |
| require("Module:debug").track("headword/sc/redundant/" .. data.sc:getCode())
| | |
| else
| | pos_functions.nouns = function(class, args, data) |
| require("Module:debug").track("headword/sc/needed")
| | local params = { |
| require("Module:debug").track("headword/sc/needed/" .. data.sc:getCode())
| | [1] = {required = true}, |
| end
| | [2] = {}, |
| end
| | ["m"] = {list = true}, |
|
| | ["head"] = {default = PAGENAME}, |
| local displayTitle
| | ["decl"] = {}, |
| -- Assumes that the scripts in "toBeTagged" will never occur in the Reconstruction namespace. | | ["cat2"] = {}, |
| -- Avoid tagging ASCII as Hani even when it is tagged as Hani in the | | ["cat3"] = {}, |
| -- headword, as in [[check]]. The check for ASCII might need to be expanded
| | ["sort"] = {}, |
| -- to a check for any Latin characters and whitespace or punctuation. | | ["affix"] = {list = true}, |
| if (namespace == "" and data.sc and toBeTagged[data.sc:getCode()]
| | } |
| and not pagename:find "^[%z\1-\127]+$")
| | |
| or (data.sc:getCode() == "Jpan" and (test_script(pagename, "Hira") or test_script(pagename, "Kana"))) then
| | local args = require("Module:parameters").process(args, params) |
| displayTitle = '<span class="' .. data.sc:getCode() .. '">' .. pagename .. '</span>'
| | data.heads = {args["head"]} |
| elseif namespace == "Reconstruction" then | | data.affix = args["affix"] |
| displayTitle, matched = mw.ustring.gsub(
| | |
| fullPagename,
| | table.insert(data.genders, gender_key[args[1]] or args[1]) |
| "^(Reconstruction:[^/]+/)(.+)$",
| | if args[2] then table.insert(data.genders, gender_key[args[2]] or args[2]) end |
| function(before, term)
| | |
| return before ..
| | data.inflections[1] = args.m |
| require("Module:script utilities").tag_text(
| | data.inflections[1].label = "marked" |
| term,
| | |
| data.lang,
| | if args.decl then table.insert(data.categories, "Siwa " .. args.decl .. "-declension " .. data.pos_category) end |
| data.sc
| | if args.cat2 then table.insert(data.categories, "Siwa " .. args["cat2"]) end |
| )
| | if args.cat3 then table.insert(data.categories, "Siwa " .. args["cat3"]) end |
| end
| | |
| )
| | data.sort_key = args["sort"] or nil |
|
| | end |
| if matched == 0 then
| | |
| displayTitle = nil
| | pos_functions["proper nouns"] = pos_functions.nouns |
| end
| | |
| end
| | pos_functions["proper nouns"] = pos_functions.nouns |
|
| | |
| if displayTitle then
| | pos_functions.verbs = function(class, args, data) |
| local frame = mw.getCurrentFrame()
| | local params = { |
| frame:callParserFunction(
| | [1] = {required = true}, |
| "DISPLAYTITLE",
| | [2] = {list = "inf", required = true}, |
| displayTitle
| | [3] = {list = "p", required = true}, |
| )
| | [4] = {type = "boolean"}, |
| end
| | ["head"] = {}, |
|
| | ["cat2"] = {}, |
| if data.force_cat_output then
| | ["sort"] = {}, |
| --[=[
| | ["affix"] = {list = true}, |
| [[Special:WhatLinksHere/Template:tracking/headword/force cat output]]
| | } |
| ]=]
| | |
| require("Module:debug").track("headword/force cat output")
| | local args = require("Module:parameters").process(args, params) |
| end
| | data.heads = {args["head"]} |
|
| | |
| if data.getCanonicalName then
| | for n, kind in ipairs(mw.text.split(args[1], "/")) do |
| error('The "data" variable supplied to "full_headword" should not be a language object.')
| | if kind ~= "?" then |
| end
| | data.inflections[n] = {nil} |
|
| | data.inflections[n].label = verb_key[kind] |
| -- Were any categories specified?
| | table.insert(data.categories, "Siwa " .. verb_key[kind] .. " verbs") |
| if data.categories and #data.categories > 0 then
| |
| local lang_name = require("Module:string").pattern_escape(data.lang:getCanonicalName())
| |
| for _, cat in ipairs(data.categories) do
| |
| -- Does the category begin with the language name? If not, tag it with a tracking category.
| |
| if not mw.ustring.find(cat, "^" .. lang_name) then
| |
| mw.log(cat, data.lang:getCanonicalName())
| |
| table.insert(tracking_categories, "head tracking/no lang category")
| |
|
| |
| --[=[
| |
| [[Special:WhatLinksHere/Template:tracking/head tracking/no lang category]]
| |
| ]=]
| |
| require("Module:debug").track{
| |
| "headword/no lang category",
| |
| "headword/no lang category/lang/" .. data.lang:getCode()
| |
| }
| |
| end
| |
| end
| |
|
| |
| if not data.pos_category
| |
| and mw.ustring.find(data.categories[1], "^" .. data.lang:getCanonicalName())
| |
| then
| |
| data.pos_category = mw.ustring.gsub(data.categories[1], "^" .. data.lang:getCanonicalName() .. " ", "")
| |
| table.remove(data.categories, 1)
| |
| end
| |
| end
| |
|
| |
| if not data.pos_category then
| |
| error(
| |
| 'No valid part-of-speech categories were found in the list '
| |
| .. 'of categories passed to the function "full_headword". '
| |
| .. 'The part-of-speech category should consist of a language\'s '
| |
| .. 'canonical name plus a part of speech.'
| |
| )
| |
| end | |
| | |
| -- Categorise for unusual characters | |
| local standard = data.lang:getStandardCharacters() | |
| | |
| if standard then | |
| if mw.ustring.len(title.subpageText) ~= 1 and not non_categorizable() then
| |
| for character in mw.ustring.gmatch(title.subpageText, "([^" .. standard .. "])") do
| |
| local upper = mw.ustring.upper(character)
| |
| if not mw.ustring.find(upper, "[" .. standard .. "]") then
| |
| character = upper
| |
| end
| |
| table.insert(
| |
| data.categories,
| |
| data.lang:getCanonicalName() .. " terms spelled with " .. character
| |
| )
| |
| end
| |
| end
| |
| end
| |
|
| |
| -- Categorise for palindromes
| |
| if title.nsText ~= "Reconstruction" and mw.ustring.len(title.subpageText)>1 | |
| and require('Module:palindromes').is_palindrome( | |
| title.subpageText, data.lang, data.sc
| |
| ) then
| |
| table.insert(data.categories, data.lang:getCanonicalName() .. " palindromes") | |
| end | | end |
| | end |
| | |
| | args[2].label = "infinitive" |
| | table.insert(data.inflections, args[2]) |
| | |
| | args[3].label = "past" |
| | table.insert(data.inflections, args[3]) |
| | |
| | if args[4] then table.insert(data.categories, "Siwa irregular verbs") end |
| | if args.cat2 then table.insert(data.categories, "Siwa " .. args["cat2"]) end |
| | |
| | if args[1] == "?" or args[2] == "?" or args[3] == "?" then table.insert(data.categories, "Contionary stubs") end |
| | | |
| -- This may add more categories (e.g. gender categories), so make sure it gets
| | data.sort_key = args["sort"] or nil |
| -- evaluated first.
| | data.affix = args["affix"] |
| local text = show_headword_line(data)
| | end |
| return
| |
| text ..
| |
| require("Module:utilities").format_categories(
| |
| data.categories, data.lang, data.sort_key, nil,
| |
| data.force_cat_output or test_force_categories, data.sc
| |
| ) ..
| |
| require("Module:utilities").format_categories(
| |
| tracking_categories, data.lang, data.sort_key, nil,
| |
| data.force_cat_output or test_force_categories, data.sc
| |
| )
| |
| end
| |
|
| |
|
| return export | | return export |