-- TODO: avoid duplicates with 'multi' with e.g. f1 and f2
local lang = require("Module:languages").getByCode("nn")
local accents = require("Module:no-diacritics")
local export = {}
function export.regular(frame)
local PAGENAME = mw.title.getCurrentTitle().text
local args = frame:getParent().args
local classType = frame.args
local class = ''
local data = {lang = lang, pos_category = "nouns", categories = {}, genders = {}, inflections = {}}
-- Gather parameters
local root = PAGENAME:gsub("e$", "")
local root_sg = nil
local root_pl = nil
if classType ~= 'multi' then
if args and args ~= '' and not args then
root_sg = args
root_pl = args
elseif args and args ~= '' then
root_pl = args
if args and args ~= '' then
root_sg = args
end
end
end
local gen_dsg = args; if gen_dsg == "" then gen_dsg = nil end
if args then
root_sg = args
root_pl = root_sg
end
if not classType:find('multi') then -- the word has only one possible inflection (normal)
class = classType
data.genders = {class:sub(1, 1)} -- extracts e.g. "m" from "m1"
else
local i = 1
local j = 1
local _genders = {}
while (true) do
if args == nil then
break
end
class = class .. '-' .. args
local g = args:sub(1, 1)
_genders = true
i = i + 1
end
if _genders then
data.genders = 'f'
j = j + 1
end
if _genders then
data.genders = 'm'
j = j + 1
end
if _genders then
data.genders = 'n'
j = j + 1
end
end
hasAccents = false
if accents.hasAccents(PAGENAME) then
hasAccents = true
end
if not root_pl then
if PAGENAME:find("kel$") then
root_pl = PAGENAME:gsub("k?kel$", "kl")
elseif PAGENAME:find("tel$") and not PAGENAME:find('mittel$') and not PAGENAME:find('pitel$')then
root_pl = PAGENAME:gsub("t?tel$", "tl")
else
root_pl = root
end
end
if not root_sg then
root_sg = root
end
-- Generate inflected forms
local definite_singular = {label = "definite singular"}
local indefinite_plural = {label = "indefinite plural"}
local definite_plural = {label = "definite plural"}
if class:find('m1') then
table.insert(definite_singular, root_sg .. 'en')
table.insert(indefinite_plural, root_pl .. 'ar')
table.insert(definite_plural, root_pl .. 'ane')
end
if class:find('m2') then
table.insert(definite_singular, root_sg .. 'en')
table.insert(indefinite_plural, root_pl .. 'er')
table.insert(indefinite_plural, root_pl .. 'ar')
table.insert(definite_plural, root_pl .. 'ene')
table.insert(definite_plural, root_pl .. 'ane')
end
if class:find('m3') then
table.insert(definite_singular, root_sg .. 'en')
table.insert(indefinite_plural, root_sg)
table.insert(definite_plural, root_pl .. 'a')
end
if class == 'f13' then
table.insert(indefinite_plural, root_pl .. 'ar')
table.insert(definite_plural, root_pl .. 'ane')
end
if class:find('f1') or class == 'f2' then
table.insert(definite_singular, root_sg .. 'a')
table.insert(indefinite_plural, root_pl .. 'er')
table.insert(definite_plural, root_pl .. 'ene')
end
if class == 'f2_2012' then
root = PAGENAME:gsub("$", "")
table.insert(definite_singular, root .. 'a')
table.insert(indefinite_plural, root .. 'er')
table.insert(indefinite_plural, root .. 'or')
table.insert(definite_plural, root .. 'ene')
table.insert(definite_plural, root .. 'one')
end
if class == 'f2_midlandsnormalen' then
root = PAGENAME:gsub("$", "")
table.insert(definite_singular, root .. 'o')
table.insert(indefinite_plural, root .. 'ur')
table.insert(definite_plural, root .. 'une')
end
if class:find('f3') then
table.insert(definite_singular, root_sg .. 'a')
table.insert(indefinite_plural, root_pl .. 'ar')
table.insert(definite_plural, root_pl .. 'ane')
end
if class:find('n1') then
table.insert(definite_singular, root_sg .. 'et')
table.insert(indefinite_plural, PAGENAME)
table.insert(definite_plural, root_pl .. 'a')
end
if class:find('-ium') then
data.genders = {'n'}
root = PAGENAME:gsub('um$', '')
table.insert(definite_singular, root .. 'et')
table.insert(indefinite_plural, PAGENAME)
table.insert(definite_plural, root .. 'a')
end
if class == 'mf' or class:find('c') then
data.genders = {'f', 'm'}
table.insert(definite_singular, root_sg .. 'en')
table.insert(definite_singular, root_sg .. 'a')
table.insert(indefinite_plural, root_pl .. 'er')
table.insert(indefinite_plural, root_pl .. 'ar')
table.insert(definite_plural, root_pl .. 'ene')
table.insert(definite_plural, root_pl .. 'ane')
end
-- Add inflections
data.inflections = {definite_singular}
if #indefinite_plural > 0 then
table.insert(data.inflections, indefinite_plural)
end
if #definite_plural > 0 then
table.insert(data.inflections, definite_plural)
end
if gen_dsg then
table.insert(data.inflections, {label = "genitive definite singular", gen_dsg})
end
if hasAccents then
for key, value in pairs(data.inflections) do --iterate over all generated forms
for i = 1, #data.inflections do
if data.inflections ~= PAGENAME then -- inflected forms identical to the singular indefinite retain their accents
table.insert(data.inflections, accents.removeAccents(data.inflections)) -- insert non-accented form
end
end
end
end
return require("Module:headword").full_headword(data)
end
function export.irregular(frame)
local PAGENAME = mw.title.getCurrentTitle().text
local args = frame:getParent().args
local uncountable = false
local data = {lang = lang, pos_category = "nouns", categories = {}, genders = {args}, inflections = {}}
-- Gather parameters
local gen_dsg = args; if gen_dsg == "" then gen_dsg = nil end
if args or args then
uncountable = true
end
if args then
table.insert(data.genders, args)
end
if args then
table.insert(data.genders, args)
end
-- Insert inflected forms
local definite_singular = {label = "definite singular"}
local indefinite_plural = {label = "indefinite plural"}
local definite_plural = {label = "definite plural"}
table.insert(definite_singular, args)
if args then
table.insert(definite_singular, args)
end
table.insert(data.inflections, definite_singular)
if not uncountable then
table.insert(indefinite_plural, args)
if args then
table.insert(indefinite_plural, args)
end
table.insert(data.inflections, indefinite_plural)
table.insert(definite_plural, args)
if args then
table.insert(definite_plural, args)
end
table.insert(data.inflections, definite_plural)
else
table.insert(data.inflections, {label = ']'})
table.insert(data.categories, lang:getCanonicalName() .. " uncountable nouns")
end
if gen_dsg then
table.insert(data.inflections, {label = "genitive definite singular", gen_dsg})
end
return require("Module:headword").full_headword(data)
end
return export