Module:xchc-noun: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 52: | Line 52: | ||
data.g = g | data.g = g | ||
data.sg = word | data.sg = word | ||
data.pau = wordpron(word) | data.pau = me(wordpron(word), "[eiøy]") and "ч" | ||
or wordpron(word) | or me(wordpron(word), "[ɛa]") and "н" | ||
or wordpron(word) | or me(wordpron(word), "[uoɔ]") and "ӈ" | ||
or gsubh("Bӈ","о̆","э̆",nil,nil,"о̆") | or gsubh("Bӈ","о̆","э̆",nil,nil,"о̆") | ||
data.pl = { | data.pl = { | ||
["i"] = wordpron(word) | ["i"] = me(wordpron(word), voiceless) and gsubh("фBд","ө","э",nil,nil,"э") or gsubh("вBд","ө","э",nil,nil,"э"), | ||
["a"] = wordpron(word) | ["a"] = me(wordpron(word), voiceless) and gsubh("шBд","о̆","э̆",nil,nil,"о̆") or gsubh("жBд","о̆","э̆",nil,nil,"о̆"), | ||
} | } | ||
| Line 112: | Line 112: | ||
local decl = { | local decl = { | ||
["nom"] = "", | ["nom"] = "", | ||
["acc"] = w_number[n_sh] | ["acc"] = me(w_number[n_sh], vowel) and "дза" or me(w_number[n_sh], voiced) and "да" or "та", | ||
["dat"] = w_number[n_sh] | ["dat"] = me(w_number[n_sh], vowel) and "ша" or me(w_number[n_sh], voiced) and "за" or "са", | ||
["gen"] = "ля", | ["gen"] = "ля", | ||
["ins"] = w_number[n_sh] | ["ins"] = me(w_number[n_sh], vowel) and "лза" or gsubh("Bлз","ө", "э", nil, nil, "ө"), | ||
["pro"] = gsubh("сBц","ө", "э", nil, nil, "ө"), | ["pro"] = gsubh("сBц","ө", "э", nil, nil, "ө"), | ||
["ade"] = "ляц", | ["ade"] = "ляц", | ||
Revision as of 16:05, 7 December 2023
- The following documentation is located at Module:xchc-noun/doc.[edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
local sub = mw.ustring.sub
local find = mw.ustring.find
local match = mw.ustring.match
local gmatch = mw.ustring.gmatch
local gsub = mw.ustring.gsub
local u = mw.ustring.char
local split = mw.text.split
local gsplit = mw.text.gsplit
local m_tr = require('Module:xchc-translit')
local m_ipa = require('Module:xchc-pron')
local lang = require('Module:languages').getByCode("xchc")
local export = {}
local voiced = "mnɲŋbdɡvzʒɣlr"
local voiceless = "ptkfsʃxh"
local consonant = "[" .. voiced .. voiceless .. "]"
local vowel = "[aeɛioɔuyø]"
local function me(foo, pat)
return foo:match(pat .. "ː?$")
end
local function gsubh(word, o, e, r, u, def)
local ipa = m_ipa.crux(word)
local backh = ipa:match("ɛ") and "ɛ" or ipa:match("ɔ") and "ɔ" or nil
local roundh = ipa:match("[yuɔo]") and "r" or ipa:match("[ie]") and "u" or nil
local repl = {["ɛ"] = e, ["ɔ"] = o, ["r"] = r, ["u"] = u}
return not r and word:gsub("B", repl[backh] or def) or word:gsub("R", repl[roundh] or def)
end
function export.show(frame)
local parent_args = frame:getParent().args
local numbers = {}
local decl = {}
local g = NAMESPACE == "Template" and "a" or parent_args[1]
local word = NAMESPACE == "Template" and "өра̄" or parent_args["word"] or PAGENAME
local unc = parent_args["unc"] or false
local args = {}
--if g ~= "i" and g ~= "a" then error("Unknown gender: it must be either ‘i’ or ‘a’") end
local function wordpron(w)
return m_ipa.crux(w)
end
local data = {}
data.word = word
data.g = g
data.sg = word
data.pau = me(wordpron(word), "[eiøy]") and "ч"
or me(wordpron(word), "[ɛa]") and "н"
or me(wordpron(word), "[uoɔ]") and "ӈ"
or gsubh("Bӈ","о̆","э̆",nil,nil,"о̆")
data.pl = {
["i"] = me(wordpron(word), voiceless) and gsubh("фBд","ө","э",nil,nil,"э") or gsubh("вBд","ө","э",nil,nil,"э"),
["a"] = me(wordpron(word), voiceless) and gsubh("шBд","о̆","э̆",nil,nil,"о̆") or gsubh("жBд","о̆","э̆",nil,nil,"о̆"),
}
end
function make_table(data)
local function show_form(form)
local function link(term)
local links = {}
for alt in gmatch(term, "([^%s,]+)") do
alt = term == "—" and term or "[[Contionary:" .. alt .. "|" .. alt .. "]]"
table.insert(links, alt)
end
return table.concat(links, ", ")
end
if not form then
return "—"
end
local ret, tr_ret = {}, {}
for _, subform in ipairs(form) do
table.insert(ret, link(subform))
table.insert(tr_ret, m_tr(subform,lang))
end
return table.concat(ret, ", ") .. "<br/>" .. table.concat(tr_ret, ", ")
end
function make_cases(data)
local w_number = {["si"] = data.word .. data.sg, ["pa"] = data.word .. data.pa, ["pl"] = data.word .. data.pl}
local cases = {"nominative", "accusative", "dative", "genitive", "instrumental", "prosecutive", "adessive<br/>comitative", "ablative<br/>elative", "illative<br/>allative"}
local numbers = {"singular", "paucal", "plural"}
local ret = {}
if data.unc then
numbers[2], numbers[3], numbers_sh[2], numbers_sh[3] = nil, nil, nil, nil
end
table.insert(ret, "! \n")
for _, number in ipairs(numbers) do
table.insert(ret, "! " .. number .. "\n")
end
table.insert(ret, "|-\n")
for _, case in ipairs(cases) do
local c_sh = case:sub(1,3)
table.insert(ret, "! " .. case .. "\n")
for _, number in ipairs(numbers) do
local n_sh = number:sub(1,3)
local decl = {
["nom"] = "",
["acc"] = me(w_number[n_sh], vowel) and "дза" or me(w_number[n_sh], voiced) and "да" or "та",
["dat"] = me(w_number[n_sh], vowel) and "ша" or me(w_number[n_sh], voiced) and "за" or "са",
["gen"] = "ля",
["ins"] = me(w_number[n_sh], vowel) and "лза" or gsubh("Bлз","ө", "э", nil, nil, "ө"),
["pro"] = gsubh("сBц","ө", "э", nil, nil, "ө"),
["ade"] = "ляц",
["abl"] = gsubh("сB",nil,nil,"u","i","u") .. gsubh("шR","о̄̆","э̄̆",nil,nil,"э̄̆"),
["pro"] = gsubh("кFб","ү","ы",nil,nil,"ы"),
}
table.insert(ret, "| " .. show_form(w_number[n_sh] .. decl[c_sh]))
end
table.insert(ret, "|-\n")
end
return table.concat(ret)
end
local t = [=[
<div class="mw-collapsible" style="border-collapse: collapse; margin: 0px 0px -1px 0px; padding: 2px; border: 1px solid #aaaaaa; text-align: center; font-size: 95%; overflow: auto; min-width: 70em; display:inline-block;">
<div style="min-height: 1.6em; font-size: 100%; text-align: left; background-color:#DEE9FB; padding-left: 10px; background-image: -webkit-gradient(linear, left top, left bottom, from(#EFEFEF), to(#DFDFDF), color-stop(0.6, #E3E3E3)); background-image: -moz-linear-gradient(top, #EFEFEF, #E3E3E3 60%, #DFDFDF); background-image: -o-linear-gradient(top, #EFEFEF, #E3E3E3 60%, #DFDFDF);">'''''{title}'''''<span style="font-weight:normal;">{after_title}</span> </div>
<div class="mw-collapsible-content" style="font-size: 100%;">
{| class = "wikitable"
|-
]=] .. make_cases(data) .. [=[
|}</div></div>
]=]
return t
end
return export