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/common')
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 function dedigraphize(word)
for digraph, repl in pairs(m_data.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(m_data.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