Module:siwa-noun
- The following documentation is located at Module:siwa-noun/doc.[edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
local export = {}
local m_u = require('Module:utilities')
local m_data = require('Module:siwa-noun/data')
local sub = mw.ustring.sub
local find = mw.ustring.find
local match = mw.ustring.match
local gsub = mw.ustring.gsub
local u = mw.ustring.char
local split = mw.text.split
local gsplit = mw.text.gsplit
local pagename = mw.title.getCurrentTitle().text
local vowels = "[aeiouyůõảẻỉỏủỷę̊]"
local consonants = "[mpbvntdsṡʦʨʥŋɲcɟħðrṁṅḥkgġhłƛɬḍ]"
local stressed_vowels = {
["ả"] = "a", ["a[ui]"] = "a", ["oa"] = "a", ["[eẻę]"] = "e", ["e[iu]"] = "e",
["ay"] = "e", ["[iỉ]"] = "i", ["i[aeou]"] = "i", ["[oỏõ]"] = "o", ["[oõ]u"] = "o",
["oi"] = "o", ["[uủ]"] = "u", ["u[oi]"] = "u", ["[yỷ]"] = "y", ["ů[ai]?"] = "y", ["ẻu"] = "y", ["ey"] = "y",
}
local digraphs_to_single = {
["ts"] = "ʦ", ["tṡ"] = "ʨ", ["dį"] = "ʥ", ["ng"] = "ŋ", ["nį"] = "ɲ",
["kį"] = "c", ["gį"] = "ɟ", ["hh"] = "ħ", ["ḍḍ"] = "ð", ["dl"] = "ɬ", ["o̊"] = "ȯ"
}
local lenition_patterns = {
["bb"] = "b", ["dd"] = "d", ["gg"] = "g", ["ɟ"] = "į", ["mm"] = "m", ["ll"] = "l", ["nn"] = "n",
["rr"] = "r", ["bġ"] = "p", ["pr"] = "p", ["dġ"] = "t", ["tr"] = "t", ["ḍb"] = "p", ["ð"] = "hh",
["ḍg"] = "k", ["bm"] = "m", ["dn"] = "n", ["kn"] = "ng", ["([lr])pp"] = "%1p", ["([lr])tt"] = "%1t", ["([lrms])kk"] = "%1k",
["k([lvs])"] = "g%1", ["ps"] = "bs", ["[vųbhḥg]"] = "", ["d[aou]"] = "l", ["ġ[aou]"] = "vv", ["[dġ][eůy]"] = "", ["[rġ]i"] = "ṡi",
["di"] = "", ["ɲi"] = "ɟi", ["ħį"] = "ṡ", ["[ou]ų"] = "ů", ["ɬ"] = "l",
}
local endings
endings["a"] = {
["m"] = "i-a-mV", ["n"] = "i-a-nV", ["p"] = "i-a-pV", ["b"] = "i-a-bV", ["t"] = "i-a-tV",
["r"] = "i-a-rV", ["vv"] = "i-a-vvV", ["lk"] = "i-a-CkV", ["rk"] = "i-a-CkV", ["sk"] = "i-a-CkV",
}
endings["e"] = {
["na"] = "i-e-na/e", ["ne"] = "i-e-na/e", ["ba"] = "i-e-ba/e", ["be"] = "i-e-ba/e",
["ka"] = "i-e-ka/e", ["ke"] = "i-e-ka/e", ["ma"] = "i-e-ma/e", ["me"] = "i-e-ma/e",
["va"] = "i-e-va/e", ["ve"] = "i-e-va/e", ["tsa"] = "i-e-tsa/e", ["tse"] = "i-e-tsa/e",
["ta"] = "i-e-ta/e", ["te"] = "i-e-ta/e", ["sa"] = "i-e-sa/e", ["se"] = "i-e-sa/e",
["la"] = "i-e-la/e", ["le"] = "i-e-la/e", ["ha"] = "i-e-ha/e", ["he"] = "i-e-ha/e",
["ġa"] = "i-e-ha/e", ["ġe"] = "i-e-ha/e", ["a"] = "i-e-a/e", ["e"] = "i-e-a/e",
["mi"] = "i-e-mi", ["pi"] = "i-e-p/bi", ["bi"] = "i-e-p/bi", ["vi"] = "i-e-vi",
["ni"] = "i-e-ni", ["ri"] = "i-e-ri", ["li"] = "i-e-li", ["ki"] = "i-e-k/gi",
["gi"] = "i-e-k/gi", ["i"] = "i-e-i", ["o"] = "i-e-o",
["mu"] = "i-e-m/nU", ["my"] = "i-e-m/nU", ["mů"] = "i-e-m/nU", -- U = front vowel
["nu"] = "i-e-m/nU", ["ny"] = "i-e-m/nU", ["nů"] = "i-e-m/nU",
["ku"] = "i-e-kU", ["ky"] = "i-e-kU", ["ků"] = "i-e-kU",
["u"] = "i-e-U", ["y"] = "i-e-U", ["ů"] = "i-e-U",
}
endings["i"] = {
["m"] = "i-i-mV", ["n"] = "i-i-nV", ["um"] = "i-i-u/om/n", ["om"] = "i-i-u/om/n", ["un"] = "i-i-u/om/n", ["on"] = "i-i-u/om/n",
["v"] = "i-i-vV", ["g"] = "i-i-gV", ["s"] = "i-i-gV", ["r"] = "i-i-rV", ["h"] = "i-i-hV", ["k"] = "i-i-kV",
["l"] = "i-i-lV", ["i"] = "i-i-i", -- else -V
}
endings["o"] = {
["ba"] = "i-o-b/ta/e", ["be"] = "i-o-b/ta/e", ["ta"] = "i-o-b/ta/e", ["te"] = "i-o-b/ta/e",
["va"] = "i-o-v/m/na/e", ["ve"] = "i-o-v/m/na/e", ["ma"] = "i-o-v/m/na/e",
["me"] = "i-o-v/m/na/e", ["na"] = "i-o-v/m/na/e", ["ne"] = "i-o-v/m/na/e",
["ra"] = "i-o-r/h/ga/e", ["re"] = "i-o-r/h/ga/e", ["ha"] = "i-o-r/h/ga/e", ["he"] = "i-o-r/h/ga/e",
["ga"] = "i-o-r/h/ga/e", ["ge"] = "i-o-r/h/ga/e", ["ka"] = "i-o-ka/e", ["ke"] = "i-o-ka/e", ["la"] = "i-o-la/e",
["le"] = "i-o-la/e", ["mi"] = "i-o-m/n/k/gi", ["ni"] = "i-o-m/n/k/gi", ["ki"] = "i-o-m/n/k/gi", ["gi"] = "i-o-m/n/k/gi",
["lki"] = "i-o-lki", ["rki"] = "i-o-rki", ["ski"] = "i-o-ski", ["sġi"] = "i-o-ski", ["li"] = "i-o-li",
["ri"] = "i-o-r/hi", ["hi"] = "i-o-r/hi", ["ṡi"] = "i-o-ṡi", ["hhįi"] = "i-o-ṡi",
["b"] = "i-o-b/p/t/dV", ["p"] = "i-o-b/p/t/dV", ["t"] = "i-o-b/p/t/dV", ["d"] = "i-o-b/p/t/dV", ["v"] = "i-o-v/m/nV",
["m"] = "i-o-v/m/nV", ["n"] = "i-o-v/m/nV", ["r"] = "i-o-r/h/g/kV", ["h"] = "i-o-r/h/g/kV", ["g"] = "i-o-r/h/g/kV",
["k"] = "i-o-r/h/g/kV", ["l"] = "i-o-lV", ["a"] = "i-o-a/e", ["e"] = "i-o-a/e", ["i"] = "i-o-i", --else -u/o/y/ů
}
local function dedigraphize(word)
for digraph, repl in pairs(digraphs_to_single) do
word = gsub(word, digraph, repl)
end
return word
end
function syll_count(word)
local pattern = "(" .. consonants .. "?" .. vowels .. "+ː?" .. consonants .. "*)"
local syllable, n = gsub(word, pattern, "%1")
syllable = match(syllable, pattern)
return syllable, n
end
local function stressed_components(word)
local pattern = consonants .. "?(" .. vowels .. "+ː?)(" .. consonants .. "*)"
local pattern2 = consonants .. "?" .. vowels .. "+ː?" .. consonants .. "*(.)"
local v, c = match(word, pattern)
if c == "d" or c == "ġ" or c == "r" or c == "ɲ" or c == "ħ" then
c = c .. match(word, pattern2)
end
return v, c
end
local function detect_quality(word)
local stressed, n = syll_count(word)
if match(stressed, vowels .. vowels .. vowels .. "?") or match(stressed, "ː") or n>=3 then
return "w" -- weak nouns
elseif (match(stressed, vowels .. vowels .. vowels .. "?") or match(stressed, "ː")) and n<3 then
return "l" -- long nouns
else return "s" -- strong nouns
end
end
local function detect_decl(word, gender, quality)
local stressed = syll_count(word)
local tonic_vowel = stressed_components(word)
for vowel, d in pairs(stressed_vowels) do
tonic_vowel = gsub(tonic_vowel, vowel, d)
end
if gender and quality then
if find(word, vowels .. "$") then
local decl = gender .. "-" .. tonic_vowel .. "-" .. quality
return decl
else
return gender .. "-" .. sub(word, -1) .. "-" .. tonic_vowel
end
end
end
local function lenition(word)
local lenited = ""
local _, c = stressed_components(word)
for regex, repl in pairs(lenition_patterns) do
lenited = gsub(c, regex, repl, 1)
end
local i, j = find(word, c)
return sub(word, 1, i-1) .. lenited .. sub(word, j+1)
end
-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
local parent_args = frame:getParent().args
local args = {}
local decl_type = "i-a-s"
local gender, word = parent_args[1], parent_args[2]~=nil and dedigraphize(parent_args[2]) or dedigraphize(pagename)
local quality = parent_args[3]~=nil and parent_args[3] or detect_quality(word)
args = require("Module:parameters").process(parent_args, m_data[decl_type].params, true)
local prefix = sub(pagename, 1, -(#word+1))
return stressed_components(word) .. " " .. lenition(word)
end
return export