local export = {}
local pos_functions = {}
local PAGENAME = mw.title.getCurrentTitle().text
local lang = require("Module:languages").getByCode("io")
local except = require("Module:io-headword/exceptions")
local participle_pattern = "[aio]n?t[aeo]?$"
local function monosyllabic(word)
local _, n = mw.ustring.gsub(word, "[AEIOUaeiou]", "")
return n == 1
end
local function check(data, tracking_categories)
local catname = "標題行有紅鏈的伊多語名詞"
for _,entry in ipairs(data.check) do
local t = mw.title.new(entry)
if t and not t.exists then
table.insert(tracking_categories, catname)
end
end
end
local function getPOS(word)
-- delete anything after "de"
word = mw.ustring.gsub(word, " de .+$", "")
-- deal with letters
if mw.ustring.match(word,"^[aeiou]$") or mw.ustring.match(word,"^[bcdefghijklmnoprstuvwxyz]o$") then
return "名詞"
end
-- deal with some exceptions
if except[word] then
return except[word]
end
-- Words with only one vowel are always irregular
if monosyllabic(word) then
return nil
elseif word:find(participle_pattern) then -- detect this firstly
return "分詞"
elseif word:find("a$") then
return "形容詞"
elseif word:find("e$") then
return "副詞"
elseif word:find("u$") then
return "代詞"
elseif word:find("o$") then
if mw.ustring.find(word, "^%u") then
return "專有名詞"
else
return "名詞"
end
elseif word:find("i$") then
if mw.ustring.find(word, "^%u") then
return "專有名詞變格形"
else
return "名詞變格形"
end
elseif word:find("ar$") then
return "動詞"
elseif word:find("[iaou]s$") or word:find("ez$") then
return "動詞變位形式"
else
return nil
end
end
-- The main entry point
function export.show(frame)
local tracking_categories = {}
local poscat = frame:getParent().args["pos"] or frame.args["poscat"] or getPOS(PAGENAME)
if not poscat then
if mw.title.getCurrentTitle().nsText == "Template" then
poscat = "名詞"
else
error("Part of speech of \"" .. PAGENAME .. "\" cannot be automatically determined.")
end
end
local params = {
["head"] = {list = true},
["pos"] = {},
["suff"] = {type = "boolean"},
}
if pos_functions[poscat] then
for key, val in pairs(pos_functions[poscat].params) do
params[key] = val
end
end
local args = require("Module:parameters").process(frame:getParent().args, params)
local data = {lang = lang, pos_category = poscat, categories = {}, heads = args["head"], genders = {}, inflections = {}, check = {}}
if pos_functions[poscat] then
pos_functions[poscat].func(args, data)
end
check(data, tracking_categories)
return require("Module:headword").full_headword(data) .. require("Module:utilities").format_categories(tracking_categories, lang)
end
pos_functions["限定詞"] = {
params = {
},
func = function(args, data)
table.insert(data.inflections, {label = "複數", accel = {form = "p"}, PAGENAME .. "i"})
table.insert(data.check, PAGENAME .. "i")
end
}
pos_functions["名詞"] = {
params = {
[1] = {list = true, allow_holes = true},
},
func = function(args, data)
local stem = PAGENAME:sub(1, -2)
-- Get the parameters
local inflected_words_specified = false
local inflected_words = {}
for i = 1, args[1].maxindex do
local word = args[1][i]
if word == "+" or word == "-" then
word = nil
end
if word then
inflected_words[word] = true
inflected_words_specified = true
end
end
local pl = {}
-- Split multi-word terms
for word in mw.text.gsplit(PAGENAME, " ", true) do
local pos = getPOS(word)
-- Inflect each word separately
if (not inflected_words_specified or inflected_words[word]) and (pos == "形容詞" or pos == "名詞" or pos == "專有名詞") then
local is_letter = ""
if mw.ustring.match(word,"^[aeiou]$") or mw.ustring.match(word,"^[bcdefghijklmnoprstuvwxyz]o$")then
is_letter = "-o"
end
table.insert(pl, stem .. "i")
else
table.insert(pl, word)
end
end
-- Merge back together
pl = table.concat(pl, " ")
local pl2
if args[1][1] == "-" then
table.insert(data.inflections, {label = "[[Appendix:Glossary#不可數|不可數]]"})
table.insert(data.categories, lang:getCanonicalName() .. "不可數名詞")
else
table.insert(data.inflections, {label = "複數", accel = {form = "p"}, pl, pl2})
table.insert(data.check, pl)
end
end
}
pos_functions["專有名詞"] = {
params = {
[1] = {list = true, allow_holes = true},
},
func = function(args, data)
-- Get the parameters
local inflected_words_specified = false
local inflected_words = {}
for i = 1, args[1].maxindex do
local word = args[1][i]
if word == "+" or word == "-" then
word = nil
end
if word then
inflected_words[word] = true
inflected_words_specified = true
end
end
local pl = {}
local de = false
-- Split multi-word terms
for word in mw.text.gsplit(PAGENAME, " ", true) do
local pos = getPOS(word)
if word == "de" then de = true end
-- Inflect each word separately
if (not inflected_words_specified or inflected_words[word]) and (pos == "形容詞" or pos == "名詞" or pos == "專有名詞" or mw.ustring.match(word,'[aio]$') and not monosyllabic(word)) and not de then
table.insert(pl, word .. "i")
else
table.insert(pl, word)
end
end
-- Merge back together
pl = table.concat(pl, " ")
if args[1][1] == "+" then
table.insert(data.inflections, {label = "複數", accel = {form = "p"}, pl})
table.insert(data.check, pl)
else
end
end
}
pos_functions["動詞"] = {
params = {
},
func = function(args, data)
local stem = PAGENAME:sub(1, -3)
table.insert(data.inflections, {label = "現在時", stem .. "as"})
table.insert(data.inflections, {label = "過去時", stem .. "is"})
table.insert(data.inflections, {label = "未來時", stem .. "os"})
table.insert(data.inflections, {label = "條件式", stem .. "us"})
table.insert(data.inflections, {label = "命令式", stem .. "ez"})
end
}
pos_functions["名詞變格形"] = {
params = {
[1] = {},
},
func = function(args, data)
if args[1] == "p" or args[1] == "p+" then
table.insert(data.genders, "p")
data.categories = {"伊多語名詞", "伊多語唯複名詞"}
if args[1] == "p+" then
local singular = mw.ustring.gsub(PAGENAME, "i$", "")
table.insert(data.inflections, {label = "單數", singular})
table.insert(data.check, singular)
end
end
end
}
pos_functions["唯複名詞"] = {
params = {
[1] = {},
},
func = function(args, data)
table.insert(data.categories, 1, "伊多語名詞")
if args[1] == "+" then
local singular = mw.ustring.gsub(PAGENAME, "i$", "")
table.insert(data.inflections, {label = "單數", singular})
table.insert(data.check, singular)
end
end
}
pos_functions["分詞"] = {
params = {
[1] = {}, [2] = {}, --these will be phased out
},
func = function(args, data)
local ending = mw.ustring.match(PAGENAME, participle_pattern)
if ending then
local vowel, consonant = ending:match("([aeio])$")
if consonant == "" then
if vowel == "a" or vowel == "o" then
table.insert(data.inflections, {label = "複數", PAGENAME .. "j"})
table.insert(data.check, PAGENAME .. "i")
elseif vowel == "e" then
data.categories = {"伊多語副詞分詞"}
end
elseif vowel == "e" then
error("-e" .. consonant .. " is not a valid participle ending!")
end
if vowel == "a" then
data.categories = {"伊多語形容分詞"}
elseif vowel == "o" then
data.categories = {"伊多語名詞分詞"}
end
else
error("This term is not a participle!")
end
end
}
return export