Module:siwa-noun: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 99: | Line 99: | ||
function export.show(frame) | function export.show(frame) | ||
local parent_args = frame:getParent().args | local parent_args = frame:getParent().args | ||
local args = {} | |||
local args = require("Module:parameters").process(parent_args, m_data.params, true) | local args = require("Module:parameters").process(parent_args, m_data.params, true) | ||
local decl_type = {} | local decl_type = {} | ||
local gender, word = | local gender, word = parent_args[1], parent_args[2]~=nil and dedigraphize(parent_args[2]) or dedigraphize(pagename) | ||
local quality = | local quality = parent_args[3]~=nil and args[3] or detect_quality(word) | ||
local prefix = sub(pagename, 1, -(#word+1)) | local prefix = sub(pagename, 1, -(#word+1)) | ||
Revision as of 21:56, 5 February 2021
syll_count
function syll_count(word)
This function lacks documentation. Please add a description of its usages, inputs and outputs, or its difference from similar functions, or make it local to remove it from the function list.
export.show
function export.show(frame)
This function lacks documentation. Please add a description of its usages, inputs and outputs, or its difference from similar functions, or make it local to remove it from the function list.
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"] = "ɬ",
}
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 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 args = require("Module:parameters").process(parent_args, m_data.params, true)
local decl_type = {}
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 args[3] or detect_quality(word)
local prefix = sub(pagename, 1, -(#word+1))
return stressed_components(word) .. " " .. lenition(word)
end
return export