Modul:accel/fi
A modult a Modul:accel/fi/doc lapon tudod dokumentálni
return {generate = function (params, entry)
local headparam = {}
local formparam = {
['plural-nominative'] = 'case=nominative|pl=plural',
['singular-genitive'] = 'case=genitive|pl=singular',
['plural-genitive'] = 'case=genitive|pl=plural',
['singular-partitive'] = 'case=partitive|pl=singular',
['plural-partitive'] = 'case=partitive|pl=plural',
['singular-accusative'] = 'case=accusative|pl=singular',
['plural-accusative'] = 'case=accusative|pl=plural',
['singular-inessive'] = 'case=inessive|pl=singular',
['plural-inessive'] = 'case=inessive|pl=plural',
['singular-elative'] = 'case=elative|pl=singular',
['plural-elative'] = 'case=elative|pl=plural',
['singular-illative'] = 'case=illative|pl=singular',
['plural-illative'] = 'case=illative|pl=plural',
['singular-adessive'] = 'case=adessive|pl=singular',
['plural-adessive'] = 'case=adessive|pl=plural',
['singular-ablative'] = 'case=ablative|pl=singular',
['plural-ablative'] = 'case=ablative|pl=plural',
['singular-allative'] = 'case=allative|pl=singular',
['plural-allative'] = 'case=allative|pl=plural',
['singular-essive'] = 'case=essive|pl=singular',
['plural-essive'] = 'case=essive|pl=plural',
['singular-translative'] = 'case=translative|pl=singular',
['plural-translative'] = 'case=translative|pl=plural',
['plural-instructive'] = 'case=instructive|pl=plural',
['plural-comitative'] = 'case=comitative|pl=plural', -- needs alt forms
['singular-abessive'] = 'case=abessive|pl=singular',
['plural-abessive'] = 'case=abessive|pl=plural'}
local participle_heads = {
['pres|actv'] = 'present active participle',
['pres|pasv'] = 'present passive participle',
['past|actv'] = 'past active participle',
['past|pasv'] = 'past passive participle',
['agent'] = 'agent participle',
['neg'] = 'negative participle',
}
local function scan_vowel_harmony(word)
for pos = #word, 1, -1 do
local char = mw.ustring.sub(word, pos, pos)
if mw.ustring.match(char, "[aou]") then
return "a"
elseif mw.ustring.match(char, "[äöy]") then
return "ä"
end
end
return "ä"
end
local function generate_participle_declension(word, type)
local vhua = { ["u"] = "a", ["y"] = "ä" }
local lword = mw.ustring.len(word)
if type == "pres|actv" then -- ...vA
return "{{fi-decl-koira|pos=adj|" .. mw.ustring.sub(word, 1, lword - 1) .. "|||" .. mw.ustring.sub(word, lword, lword) .. "}}"
elseif type == "pres|pasv" then -- ...(t)tAvA
return "{{fi-decl-koira|pos=adj|" .. mw.ustring.sub(word, 1, lword - 1) .. "|||" .. mw.ustring.sub(word, lword, lword) .. "}}"
elseif type == "past|actv" then -- ...(n)Ut
return "{{fi-decl-kuollut|pos=adj|" .. mw.ustring.sub(word, 1, lword - 2) .. "|" .. vhua[mw.ustring.sub(word, lword - 1, lword - 1)] .. "}}"
elseif type == "past|pasv" then -- ...tU
-- this is the most complicated one
local special = mw.ustring.sub(word, lword - 2, lword - 2)
local final = mw.ustring.sub(word, lword, lword) -- U
final = final .. "|" .. vhua[final] -- U|A
if special == "l" or special == "n" or special == "r" then
return "{{fi-decl-valo|pos=adj|" .. mw.ustring.sub(word, 1, lword - 3) .. "|" .. special .. "t|" .. special .. special .. "|" .. final .. "}}"
elseif special == "t" then
return "{{fi-decl-valo|pos=adj|" .. mw.ustring.sub(word, 1, lword - 3) .. "|tt|t|" .. final .. "}}"
elseif special == "s" then
return "{{fi-decl-valo|pos=adj|" .. mw.ustring.sub(word, 1, lword - 1) .. "|||" .. final .. "}}"
else
return "{{fi-decl-valo|pos=adj|" .. mw.ustring.sub(word, 1, lword - 2) .. "|t|d|" .. final .. "}}"
end
elseif type == "agent" then -- ...mA
return "{{fi-decl-koira|pos=adj|" .. mw.ustring.sub(word, 1, lword - 1) .. "|||" .. mw.ustring.sub(word, lword, lword) .. "}}"
elseif type == "neg" then -- ...mAtOn
return "{{fi-decl-onneton|pos=adj|" .. mw.ustring.sub(word, 1, lword - 3) .. "|" .. mw.ustring.sub(word, lword - 3, lword - 3) .. "}}"
else
return nil -- ????
end
end
local was_rare = false
if params.form:sub(1, 5) == "rare-" then
was_rare = true
params.form = params.form:sub(6)
end
if params.form:sub(1, 11) == "comparative" then
local form, vh = unpack(mw.text.split(params.form, '|', true))
local vhfooter = scan_vowel_harmony(params.origin) .. "}} {{attention|fi|verify that vowel harmony is correct}}"
if vh == "a" or vh == "ä" then
vhfooter = vh .. "}}"
end
entry.head = '{{head|' .. params.lang .. '|comparative ' .. params.pos .. '}}'
entry.def = '{{comparative of|fi|' .. params.origin .. '|nocat=1}}'
if params.pos == "adjective" then
if mw.ustring.sub(params.target, -3) == "mpi" then
entry.declension = "{{fi-decl-vanhempi|pos=adj|" ..
mw.ustring.sub(params.target, 1, -4) .. "|" .. vhfooter
elseif mw.ustring.sub(params.target, -4) == "inen" then
entry.declension = "{{fi-decl-nainen|pos=adj|" ..
mw.ustring.sub(params.target, 1, -4) .. "|" .. vhfooter
else
entry.declension = "{{rfinfl|fi}}"
end
end
elseif params.form:sub(1, 11) == "superlative" then
local form, vh = unpack(mw.text.split(params.form, '|', true))
local vhfooter = scan_vowel_harmony(params.origin) .. "}} {{attention|fi|verify that vowel harmony is correct}}"
if vh == "a" or vh == "ä" then
vhfooter = vh .. "}}"
end
entry.head = '{{head|' .. params.lang .. '|superlative ' .. params.pos .. '}}'
entry.def = '{{superlative of|fi|' .. params.origin .. '|nocat=1}}'
if params.pos == "adjective" then
entry.declension = "{{fi-decl-sisin|pos=adj|" ..
mw.ustring.sub(params.target, 1, -3) .. "|" .. vhfooter
end
elseif params.form:sub(1, 15) == "part-possessive" then
-- possessive form of adverbial
entry.head = '{{head|' .. params.lang .. '|' .. params.pos .. ' form}}'
local form, poss = unpack(mw.text.split(params.form, '|', true))
-- replace 3s,3p => 3, because 3rd person singular and plural are identical and "third-person" is thus enough
entry.def = '{{inflection of|fi|' .. params.origin .. '||' .. poss:gsub("(%d)(%a)", "%1|%2|form"):gsub("3%|%a", "3") .. '}}'
elseif params.form:sub(1, 10) == "possessive" then
-- possessive form of nominal
if params.pos == "noun" then
entry.head = '{{head|' .. params.lang .. '|noun possessive form}}'
else
entry.head = '{{head|' .. params.lang .. '|' .. params.pos .. ' form}}'
end
local form, poss, decltype, inflection = unpack(mw.text.split(params.form, '|', true))
inflection = require('Module:base64').decode(inflection)
entry.def = '{{inflection of|fi|' .. params.origin .. '||' .. poss:gsub("(%d)(%a)", "%1|%2|poss"):gsub("3%|%a", "3") .. '}}'
-- copy declension for possessive from original entry
entry.declension = "{{fi-decl-" .. decltype .. "|poss=" .. poss .. "|" .. inflection .. "}}"
elseif params.form:sub(1, 11) == "participle-" then
-- participles; require declension
local infl = mw.ustring.sub(params.form, #"participle-" + 1)
local declension = generate_participle_declension(params.target, infl)
if declension == nil then error("Unsupported participle") end
entry.def = '{{inflection of|fi|' .. params.origin .. '||' .. infl .. '|part}}'
entry.head = '{{head|fi|' .. (participle_heads[infl] or 'participle') .. '}}'
entry.pos_header = "Participle"
entry.declension = declension
elseif mw.ustring.match(params.form, "^inf1l-") then
-- long first infinitive; requires alt forms for other persons
local vh = mw.ustring.match(params.form, "([aä])$")
if vh ~= "a" and vh ~= "ä" then error("Invalid vowel harmony") end
if not params.target:match("en$") then
error("Unsupported long first infinitive form")
end
entry.head = '{{head|fi|infinitive}}'
entry.def = '{{inflection of|fi|' .. params.origin .. '||3|form|of the|long|first|inf}}'
entry.altforms = '{{fi-alt-personal|' .. mw.ustring.sub(params.target, 1, mw.ustring.len(params.target) - 2) .. '|e|' .. vh .. '}}'
elseif mw.ustring.match(params.form, "^inf5-") then
-- fifth infinitive; requires alt forms for other persons
local vh = mw.ustring.match(params.form, "([aä])$")
if vh ~= "a" and vh ~= "ä" then error("Invalid vowel harmony") end
if not params.target:match("[aä]n$") then
error("Unsupported fifth infinitive form")
end
entry.head = '{{head|fi|infinitive}}'
entry.def = '{{inflection of|fi|' .. params.origin .. '||3|form|of the|fifth|inf}}'
entry.altforms = '{{fi-alt-personal|' .. mw.ustring.sub(params.target, 1, mw.ustring.len(params.target) - 2) .. '|' .. vh .. '|' .. vh .. '}}'
elseif mw.ustring.match(params.form, "|inf") then
entry.head = '{{head|fi|infinitive}}'
entry.def = '{{inflection of|fi|' .. params.origin .. '||' .. params.form .. '}}'
elseif mw.ustring.match(params.form, "com%-pl%-[aä]") then
-- comitative (plural only); requires alt forms for other persons
local vh = mw.ustring.match(params.form, "com%-pl%-([aä])")
if vh ~= "a" and vh ~= "ä" then error("Invalid vowel harmony") end
entry.head = '{{head|' .. params.lang .. '|'
.. (headparam[params.form] or params.pos .. ' form') .. '}}'
if params.target:match("en$") then
entry.altforms = '{{fi-alt-personal|' .. params.target:sub(1, (#params.target) - 2) .. '|e|' .. vh .. '}}'
entry.def = '{{inflection of|fi|' .. params.origin .. '||3|poss|form|of|com|p}}'
elseif params.target:match("ne$") then
entry.def = '{{inflection of|fi|' .. params.origin .. '||com|p}}'
else
error("Unsupported comitative form")
end
elseif formparam[params.form] then
entry.head = '{{head|' .. params.lang .. '|'
.. (headparam[params.form] or params.pos .. ' form') .. '}}'
entry.def = '{{fi-form of|' .. params.origin .. '|' .. formparam[params.form] .. '}}'
else
-- needed here because of code below
entry.def = '{{inflection of|fi|' .. params.origin .. '||' .. params.form .. '}}'
end
if was_rare then
entry.def = '{{lb|fi|nocat=1|rare}} ' .. entry.def
end
end}