-- handles possessives for particles (adverbs, postpositions, etc.)
-- used to implement {{fi-adv-poss}} and {{fi-word-poss}}
local m_links = require("Module:links")
local m_sc = require("Module:script utilities")
local lang = require("Module:languages").getByCode("fi")
local export = {}
export.poss_table = function(frame)
local title = mw.title.getCurrentTitle().text
local args = frame:getParent().args
local word = args["title"] or title
local xsuffix = args["suffix"] or ""
local tableheader = args["header"] or "所有者"
local glosses = {}
local vh = args[1]
local allow_alt_form = nil
local nosuf = true
if vh ~= "a" and vh ~= "ä" then
error("You must supply 'a' or 'ä' as a parameter to this template.")
end
if (args["an"] or args["alt"]) ~= nil then
local val = args["an"] or args["alt"]
allow_alt_form = not (not val or val == "" or val == "0" or val == "no" or val == "n" or val == "false")
end
if mw.ustring.match(xsuffix, "^_") then
xsuffix = " " .. xsuffix:sub(2)
end
if args["poss"] then
-- already has possessive suffix. we lemmatize entries under 3rd
-- person singular, so the entry name must then end in -nsA, -An or -en
if mw.ustring.match(word, "an$") or mw.ustring.match(word, "en$") then
word = word:sub(1, #word - 2)
allow_alt_form = true
elseif mw.ustring.match(word, "än$") then
word = word:sub(1, #word - #"än") -- Lua + Unicode is messy
allow_alt_form = true
elseif mw.ustring.match(word, "nsa$") then
word = word:sub(1, #word - 3)
allow_alt_form = false
elseif mw.ustring.match(word, "nsä$") then
word = word:sub(1, #word - #"nsä") -- Lua + Unicode is messy
allow_alt_form = false
else
error("Unrecognized possessive form. Is this under the correct lemma (3rd person possessive)?")
end
nosuf = false
end
data = generate_possessive_forms(word, vh, allow_alt_form, nosuf, xsuffix)
if args["n"] == "sg" then
data["1p"] = nil
data["2p"] = nil
elseif args["n"] == "pl" then
data["1s"] = nil
data["2s"] = nil
end
for key, value in pairs(data) do
glosses[key] = args["t" .. key]
end
return "" .. make_possessive_table_internal(data, true, tableheader, glosses)
end
export.word_poss_table = function(frame)
local title = mw.title.getCurrentTitle().text
local args = frame:getParent().args
local word = args[1] or error("You must supply the stem as a parameter to this template.")
local xsuffix = args["suffix"] or ""
local tableheader = args["header"] or "所有者"
local glosses = {}
local vh = args[2]
local allow_alt_form = nil
if vh ~= "a" and vh ~= "ä" then
error("You must supply 'a' or 'ä' as a parameter to this template.")
end
if (args["an"] or args["alt"]) ~= nil then
local val = args["an"] or args["alt"]
allow_alt_form = not (not val or val == "" or val == "0" or val == "no" or val == "n" or val == "false")
end
if mw.ustring.match(xsuffix, "^_") then
xsuffix = " " .. xsuffix:sub(2)
end
data = generate_possessive_forms(word, vh, allow_alt_form, false, xsuffix)
if args["n"] == "sg" then
data["1p"] = nil
data["2p"] = nil
elseif args["n"] == "pl" then
data["1s"] = nil
data["2s"] = nil
end
for key, value in pairs(data) do
glosses[key] = args["t" .. key]
end
return "" .. make_possessive_table_internal(data, false, tableheader, glosses)
end
function generate_possessive_forms(word, vh, allow_alt_form, nosuf, xsuffix)
local result = {}
if nosuf then
result["np"] = word
end
if word:match("n$") then
word = word:sub(1, #word - 1)
end
if word:match("ksi$") then -- translative
word = word:sub(1, #word - 3) .. "kse"
end
if allow_alt_form == nil then
allow_alt_form = not (mw.ustring.match(word, "aa$") or mw.ustring.match(word, "ää$") or mw.ustring.match(word, "ee$"))
end
local thirdperson = { word .. "ns" .. vh .. xsuffix }
if allow_alt_form then
local alt_form = word
if mw.ustring.match(word, "e$") then
alt_form = alt_form .. "en"
elseif mw.ustring.match(word, "[aä]$") then
alt_form = alt_form .. vh .. "n"
else
allow_alt_form = false
end
if allow_alt_form then
table.insert(thirdperson, 1, alt_form .. xsuffix)
end
end
result["1s"] = { word .. "ni" .. xsuffix }
result["2s"] = { word .. "si" .. xsuffix }
result["1p"] = { word .. "mme" .. xsuffix }
result["2p"] = { word .. "nne" .. xsuffix }
result["3"] = thirdperson
return result
end
function make_possessive_table_internal(data, show_np, tableheader, glosses)
local link_words = show_np
local function show_form(forms, code, no_rare)
local form = forms[code]
if not form or #form < 1 then
return "—"
end
local ret = {}
for key, subform in ipairs(form) do
if link_words then
table.insert(ret, m_links.full_link({
lang = lang,
term = subform,
gloss = glosses[code],
accel = {
form = "part-possessive|" .. code
},
}))
else
table.insert(ret, m_sc.tag_text(subform, lang, lang:findBestScript(subform), nil))
end
end
return table.concat(ret, "<br/>")
end
local function repl(param)
if param == "lemma" then
return m_links.full_link({lang = lang, alt = mw.title.getCurrentTitle().text}, "term")
elseif param == "tableheader" then
return tableheader
elseif param == "npheader" then
return "無所有者"
elseif param == "np" then
if data["np"] then
return m_sc.tag_text(data["np"], lang, lang:findBestScript(data["np"]), "bold")
else
return "—"
end
else
return show_form(data, param)
end
end
local wikicode = ""
if show_np then
wikicode = [=[
{| class="inflection-table vsSwitcher" data-toggle-category="inflection" style="color: rgb(0%,0%,30%); border: solid 1px rgb(80%,80%,100%); text-align: center;" cellspacing="1" cellpadding="2"
|- style="background: #e2f6e2;"
! class="vsToggleElement" style="min-width: 30em; text-align: left;" colspan="3" | {{{lemma}}} 的人稱/[[Appendix:芬蘭語所有格後綴|所有格形式]]
|- class="vsHide"
! style="background:#e2f6e2" | {{{npheader}}}
| colspan="2" | {{{np}}}
|- class="vsHide"
! style="min-width: 11em; background:#c0e4c0" | {{{tableheader}}}
! style="min-width: 10em; background:#c0e4c0" | 單數
! style="min-width: 10em; background:#c0e4c0" | 複數
|- class="vsHide" style="background:rgb(95%,95%,100%)"
! style="background:#e2f6e2" | 第一人稱
| {{{1s}}}
| {{{1p}}}
|- class="vsHide" style="background:rgb(95%,95%,100%)"
! style="background:#e2f6e2" | 第二人稱
| {{{2s}}}
| {{{2p}}}
|- class="vsHide" style="background:rgb(95%,95%,100%)"
! style="background:#e2f6e2" | 第三人稱
| colspan="2" | {{{3}}}
|}]=]
else
wikicode = [=[
{| style="border: solid 1px; text-align: center;" cellspacing="1" cellpadding="2"
|-
! style="border: solid 1px; min-width: 11em" | {{{tableheader}}}
! style="border: solid 1px; min-width: 10em" | 單數
! style="border: solid 1px; min-width: 10em" | 複數
|-
! style="border: solid 1px;" | 第一人稱
| style="border: solid 1px;" | {{{1s}}}
| style="border: solid 1px;" | {{{1p}}}
|-
! style="border: solid 1px;" | 第二人稱
| style="border: solid 1px;" | {{{2s}}}
| style="border: solid 1px;" | {{{2p}}}
|-
! style="border: solid 1px;" | 第三人稱
| colspan="2" style="border: solid 1px;" | {{{3}}}
|}]=]
end
return mw.ustring.gsub(wikicode, "{{{([a-z0-9_:]+)}}}", repl)
end
return export