Module:ha-headword
- The following documentation is located at Module:ha-headword/documentation. [edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
Backend for {{ha-noun}}
.
local export = {}
local GRAVE = mw.ustring.char(0x0300)
local ACUTE = mw.ustring.char(0x0301)
local vowels = {['a'] = true, ['e'] = true, ['i'] = true, ['o'] = true, ['u'] = true,
['â'] = true, ['ê'] = true, ['î'] = true, ['ô'] = true, ['û'] = true,
}
local long_vowels = {['ā'] = 'a', ['ē'] = 'e', ['ī'] = 'i', ['ō'] = 'o', ['ū'] = 'u'}
function replace_last_vowel(term)
local vowel_index = nil
local vowel = nil
for i = 1, mw.ustring.len(term) do
local char = mw.ustring.sub(term,i,i)
if long_vowels[char] then
vowel_index = i
vowel = long_vowels[char]
end
end
if vowel_index then
return mw.ustring.sub(term, 1, vowel_index-1) .. vowel .. mw.ustring.sub(term, vowel_index+1, mw.ustring.len(term))
else
return term
end
end
function export.generate_possessed_form(term, gender)
-- replace last vowel with short vowel
term = replace_last_vowel(term)
local stripped_term = mw.ustring.gsub(term, ACUTE, '')
stripped_term = mw.ustring.gsub(stripped_term, GRAVE, '')
local length = mw.ustring.len(stripped_term)
local final_char = mw.ustring.sub(stripped_term,length,length)
-- ends with consonant
if not vowels[final_char] then return nil end
-- contains space
if mw.ustring.match(term, '%s') then return nil end
-- feminine and ends with a
if gender == 'f' and final_char == 'a' then return mw.ustring.toNFC(term .. 'r̃') end
-- ends in ai or au
local suffix = mw.ustring.sub(stripped_term,length-1,length-1) .. final_char
if suffix == 'ai' or suffix == 'au' then return mw.ustring.toNFC(mw.ustring.sub(term,1,length-1) .. 'n') end
-- otherwise
return mw.ustring.toNFC(term .. 'n')
end
function export.noun(frame)
local params = {
[1] = {},
["g2"] = {},
["head"] = {},
["sort"] = {},
["f"] = {},
[2] = {},
["pl2"] = {},
["pl3"] = {}
}
local args = require("Module:parameters").process(frame:getParent().args, params)
local data = {lang = lang,
pos_category = "nouns",
categories = {},
heads = {args["head"]},
genders = {args[1], args["g2"]},
inflections = {}}
if args["f"] then
table.insert(data.inflections, {label = "feminine", term = args["f"]})
end
if args[2] then
table.insert(data.inflections, {label = "plural", term = args[2]})
if args["pl2"] then
table.insert(data.inflections, {label = "or", term = args["pl2"]})
if args["pl3"] then
table.insert(data.inflections, {label = "or", term = args["pl3"]})
end
end
end
return require("Module:headword").full_headword(data)
end
return export