Module:qhv-headword: Difference between revisions
No edit summary |
No edit summary |
||
| (61 intermediate revisions by the same user not shown) | |||
| Line 12: | Line 12: | ||
local PAGENAME = mw.title.getCurrentTitle().text | local PAGENAME = mw.title.getCurrentTitle().text | ||
local NAMESPACE = mw.title.getCurrentTitle().nsText | |||
local SUBPAGENAME = mw.title.getCurrentTitle().subpageText | |||
local legal_gender = { | local legal_gender = { | ||
| Line 18: | Line 20: | ||
["sol"] = true, | ["sol"] = true, | ||
["ter"] = true, | ["ter"] = true, | ||
["?"] = true, | |||
} | } | ||
| Line 24: | Line 27: | ||
["lun"] = "lunar", | ["lun"] = "lunar", | ||
["sol"] = "solar", | ["sol"] = "solar", | ||
["ter"] = "terrestrial" | ["ter"] = "terrestrial", | ||
["?"] = "unknown", | |||
} | } | ||
| Line 39: | Line 43: | ||
local lang = require("Module:languages").getByCode("qhv") | local lang = require("Module:languages").getByCode("qhv") | ||
local m_data = require("Module:qhv-noun/data") | local m_data = require("Module:qhv-noun/data") | ||
local function glossary_link(entry, text) | |||
text = text or entry | |||
return "[[wikt:Appendix:Glossary#" .. entry .. "|" .. text .. "]]" | |||
end | |||
local function detect_gender(word) | local function detect_gender(word) | ||
local ending = sub( | local ending = word:sub(-1) | ||
if find(word | if word:find("illa$") then | ||
return "aq" | |||
elseif word:find("[aeioy]$") then | |||
return "lun" | return "lun" | ||
elseif ending == "r" then | elseif ending == "r" then | ||
| Line 53: | Line 64: | ||
end | end | ||
local function generate_gen_sg() | local function generate_gen_sg(word, rc, rp) | ||
local genitive = {} | local genitive = {} | ||
for alt in gmatch(require("Module:qhv-noun/head").pass_to_module("gen_sg"), "[^,]+") do | local r = rc and "gen_co" | ||
for alt in gmatch(require("Module:qhv-noun/head").pass_to_module((rc and "gen_co" or rp and "gen_pa" or "gen_sg"), word), "[^,]+") do | |||
table.insert(genitive, alt) | table.insert(genitive, alt) | ||
end | end | ||
| Line 61: | Line 73: | ||
end | end | ||
local function generate_nom_pl() | local function generate_nom_pl(word) | ||
local plural = {} | local plural = {} | ||
for alt in gmatch(require("Module:qhv-noun/head").pass_to_module("nom_pl"), "[^,]+") do | for alt in gmatch(require("Module:qhv-noun/head").pass_to_module("nom_pl", word), "[^,]+") do | ||
table.insert(plural, alt) | table.insert(plural, alt) | ||
end | end | ||
| Line 72: | Line 84: | ||
-- This is the only function that can be invoked from a template. | -- This is the only function that can be invoked from a template. | ||
function export.show(frame) | function export.show(frame) | ||
if NAMESPACE == "Template" and SUBPAGENAME ~= "doc" then return end | |||
local parent_args = frame:getParent().args | local parent_args = frame:getParent().args | ||
local head = parent_args["head"] | local head = parent_args["head"] or PAGENAME:match("%s") and require("Module:linkeach").link_for_modules(PAGENAME) or nil | ||
local poscat = frame.args[1] or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.") | local poscat = frame.args[1] or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.") | ||
| Line 85: | Line 98: | ||
genders = {}, | genders = {}, | ||
pos_category = poscat, | pos_category = poscat, | ||
categories = {}, | categories = {"Contionary"}, | ||
} | } | ||
| Line 98: | Line 111: | ||
local params = { | local params = { | ||
[1] = {default = detect_gender(PAGENAME)}, | [1] = {default = detect_gender(PAGENAME)}, | ||
[2] = {default = PAGENAME}, | |||
["nopl"] = {}, | ["nopl"] = {}, | ||
["noinf"] = {type = "boolean", default = false}, | |||
["gen"] = {}, | ["gen"] = {}, | ||
["pl"] = {}, | ["pl"] = {}, | ||
["head"] = {}, | ["head"] = {}, | ||
["rc"] = {type = "boolean"}, | |||
["rp"] = {type = "boolean"}, | |||
["og"] = {}, | |||
} | } | ||
local args = require("Module:parameters").process(args, params) | local args = require("Module:parameters").process(args, params) | ||
data.heads = {args["head"]} | --data.heads = {args["head"]} | ||
table.insert(data.genders, args[1]) | table.insert(data.genders, args[1]) | ||
table.insert(data.categories, "High Valyrian " .. args[1] .. " " .. data.pos_category) | table.insert(data.categories, "High Valyrian " .. (args[1] == "?" and "" or gender_names[args[1]]) .. " " .. data.pos_category) | ||
if not args["noinf"] then | |||
args["gen"] = generate_gen_sg(args["og"] or args[2], args["rc"], args["rp"]) | |||
for i, form in ipairs(args["gen"]) do | for i, form in ipairs(args["gen"]) do | ||
args["gen"][i] = {term = form} | args["gen"][i] = {term = form} | ||
| Line 119: | Line 137: | ||
args["gen"].label = "genitive" | args["gen"].label = "genitive" | ||
table.insert(data.inflections, args["gen"]) | table.insert(data.inflections, args["gen"]) | ||
end | |||
if data.pos_category == "nouns" and not args["noinf"] then | |||
if not args["nopl"] then | |||
args["pl"] = generate_nom_pl(args["og"] or args[2]) | |||
for i, form in ipairs(args["pl"]) do | |||
args["pl"][i] = {term = form} | |||
end | |||
args["pl"].label = "plural" | |||
table.insert(data.inflections, args["pl"]) | |||
end | |||
end | end | ||
end | end | ||
| Line 124: | Line 155: | ||
pos_functions.adjectives = function(class, args, data) | pos_functions.adjectives = function(class, args, data) | ||
local params = { | local params = { | ||
[1] = {list = "comp"}, | [1] = {list = "eq"}, | ||
[ | [2] = {list = "comp"}, | ||
[3] = {list = "sup"}, | |||
["unc"] = {type = "boolean"}, | |||
["indecl"] = {type = "boolean"}, | |||
["head"] = {}, | ["head"] = {}, | ||
} | } | ||
local args = require("Module:parameters").process(args, params) | local args = require("Module:parameters").process(args, params) | ||
local isdet = data.pos_category == "determiners" | |||
data.heads = {args["head"]} | data.heads = {args["head"]} | ||
if args[ | table.insert(data.categories, "High Valyrian " .. data.pos_category) | ||
table.insert(data.inflections, {label = "not comparable"}) | if args["unc"] or isdet then | ||
table.insert(data.categories, " | table.insert(data.inflections, {label = "not " .. glossary_link("comparable")}) | ||
if not isdet then table.insert(data.categories, "High Valyrian uncomparable adjectives") end | |||
elseif args["indecl"] then | |||
table.insert(data.inflections, {label = glossary_link("indeclinable")}) | |||
table.insert(data.categories, "High Valyrian indeclinable " .. data.pos_category) | |||
else | else | ||
args[1] = | args[1] = require("Module:qhv-adj/head").fetch("eq") | ||
args[2] = require("Module:qhv-adj/head").fetch("comp") | |||
args[3] = require("Module:qhv-adj/head").fetch("sup") | |||
args[1].label = glossary_link("equative") | |||
args[2].label = glossary_link("comparative") | |||
args[3].label = glossary_link("superlative") | |||
table.insert(data.inflections, args[1]) | |||
table.insert(data.inflections, args[2]) | |||
table.insert(data.inflections, args[3]) | |||
args[2] | |||
table.insert(data. | |||
end | end | ||
end | end | ||
pos_functions["proper nouns"] = pos_functions.nouns | pos_functions["proper nouns"] = pos_functions.nouns | ||
pos_functions["determiners"] = pos_functions.adjectives | |||
pos_functions.verbs = function(class, args, data) | pos_functions.verbs = function(class, args, data) | ||
local params = { | |||
[1] = {list = "pres"}, | |||
[2] = {list = "subj"}, | |||
[3] = {list = "pp"}, | |||
["head"] = {}, | |||
} | |||
local args = require("Module:parameters").process(args, params) | |||
data.heads = {args["head"]} | |||
table.insert(data.categories, "High Valyrian " .. data.pos_category) | |||
args[1] = require("Module:qhv-verb/head").fetch("act_ind_prs_1sg") | |||
args[2] = require("Module:qhv-verb/head").fetch("act_sub_prs_1sg") | |||
args[3] = require("Module:qhv-verb/head").fetch("act_part_prf") | |||
args[1].label = "first-person singular present indicative" | |||
args[2].label = "first-person singular present subjunctive" | |||
args[3].label = "perfect participle" | |||
table.insert(data.inflections, args[1]) | |||
table.insert(data.inflections, args[2]) | |||
table.insert(data.inflections, args[3]) | |||
table.insert(data.inflections, | |||
end | end | ||
return export | return export | ||