Module:ha-headword: difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
No edit summary |
No edit summary |
||
Line 10: | Line 10: | ||
local long_vowels = {['ā'] = 'a', ['ē'] = 'e', ['ī'] = 'i', ['ō'] = 'o', ['ū'] = 'u'} |
local long_vowels = {['ā'] = 'a', ['ē'] = 'e', ['ī'] = 'i', ['ō'] = 'o', ['ū'] = 'u'} |
||
for k,v in |
for k,v in pairs(vowels) do |
||
vowels[k+GRAVE] = true |
vowels[k+GRAVE] = true |
||
vowels[k+ACUTE] = true |
vowels[k+ACUTE] = true |
||
end |
end |
||
for k,v in |
for k,v in pairs(long_vowels) do |
||
long_vowels[k+GRAVE] = true |
long_vowels[k+GRAVE] = true |
||
long_vowels[k+ACUTE] = true |
long_vowels[k+ACUTE] = true |
Revision as of 23:14, 2 September 2017
- 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'}
for k,v in pairs(vowels) do
vowels[k+GRAVE] = true
vowels[k+ACUTE] = true
end
for k,v in pairs(long_vowels) do
long_vowels[k+GRAVE] = true
long_vowels[k+ACUTE] = true
end
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 length = mw.ustring.len(term)
local final_char = mw.ustring.sub(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 term .. 'r̃' end
-- ends in ai or au
local suffix = mw.ustring.sub(term,length-1,length-1) .. final_char
if suffix == 'ai' or suffix == 'au' then return mw.ustring.sub(term,1,length-1) .. 'n' end
-- otherwise
return term .. 'n'
end
return export