Module:siwa-noun: Difference between revisions
No edit summary |
Tag: Undo |
||
| (48 intermediate revisions by the same user not shown) | |||
| Line 2: | Line 2: | ||
local m_u = require('Module:utilities') | local m_u = require('Module:utilities') | ||
local m_l = require('Module:links') | |||
local m_data = require('Module:siwa-noun/data') | local m_data = require('Module:siwa-noun/data') | ||
local m_com = require('Module:siwa-noun/common') | local m_com = require('Module:siwa-noun/common') | ||
local lang = require('Module:languages').getByCode("siwa") | |||
local sub = mw.ustring.sub | local sub = mw.ustring.sub | ||
| Line 41: | Line 43: | ||
stressed = dedigraphicize(stressed) | stressed = dedigraphicize(stressed) | ||
if (match(stressed, vowels .. vowels .. vowels .. "?") or match(mw.ustring.toNFD(stressed), HOOK)) and n<3 then | if (match(stressed, vowels .. vowels .. vowels .. "?") or match(mw.ustring.toNFD(stressed), HOOK) or match(stressed, "õu")) and n<3 then | ||
return "l" -- long nouns | return "l" -- long nouns | ||
elseif (match(stressed, vowels .. vowels .. vowels .. "?") or match(mw.ustring.toNFD(stressed), HOOK)) or n>=3 then | elseif (match(stressed, vowels .. vowels .. vowels .. "?") or match(mw.ustring.toNFD(stressed), HOOK) or match(stressed, "õu")) or n>=3 then | ||
return "w" -- weak nouns | return "w" -- weak nouns | ||
else return "s" -- strong nouns | else return "s" -- strong nouns | ||
| Line 52: | Line 54: | ||
word = dedigraphicize(word) | word = dedigraphicize(word) | ||
if gender == "a" then return "animate" | if gender == "a" then return "animate" | ||
elseif word:match("[ảẻỉỏủỷởử]$") or word:match(" | elseif word:match("[ảẻỉỏủỷởử]$") or word:match("i[rů]$") or word:match("[aeio]u$") or word:match("[aeiouyůử]l$") then | ||
return "l" | return "l" | ||
elseif match(vowels, sub(word, -1, -1)) then | elseif match(vowels, sub(word, -1, -1)) then | ||
| Line 72: | Line 74: | ||
local sv = NAMESPACE == "Template" and "i" or parent_args[2] | local sv = NAMESPACE == "Template" and "i" or parent_args[2] | ||
local decl_type = (parent_args["decl"] == "decl" and detect_decl(word, sv, g)) or parent_args["decl"] or detect_decl(word, sv, g) | local decl_type = (parent_args["decl"] == "decl" and detect_decl(word, sv, g)) or parent_args["decl"] or detect_decl(word, sv, g) | ||
if decl_type == "l" then parent_args["nocoal"] = true end | |||
if g ~= "i" and g ~= "a" then error("Unknown gender: it must be either ‘i’ or ‘a’") end | if g ~= "i" and g ~= "a" then error("Unknown gender: it must be either ‘i’ or ‘a’") end | ||
| Line 92: | Line 95: | ||
local data = {forms = {}, categories = {}} | local data = {forms = {}, categories = {}} | ||
data.lang = lang | |||
data.head = parent_args["head"] or word | data.head = parent_args["head"] or word | ||
data.proper = parent_args["proper"] and true or false | data.proper = parent_args["proper"] and true or false | ||
| Line 97: | Line 101: | ||
data.sv = sv or error("Parameter 2 must be the word's stressed vowel") | data.sv = sv or error("Parameter 2 must be the word's stressed vowel") | ||
data.g = g | data.g = g | ||
data.alt = parent_args["alt"] | |||
data.decl_type = decl_type | data.decl_type = decl_type | ||
data.q = parent_args["q"] or detect_quality(data.head, data.sv) | data.q = parent_args["q"] or detect_quality(data.head, data.sv) | ||
| Line 108: | Line 113: | ||
end | end | ||
if g == "i" then | local coal_cases = {"m", "ine", "ill", "ela", "ade", "all", "abl"} | ||
if g == "i" or data.pos == "adjectives" then | |||
if parent_args.m then data.forms["m"][1] = parent_args["m"] end | if parent_args.m then data.forms["m"][1] = parent_args["m"] end | ||
-- Diphthong and long vowel coalescence | |||
if (parent_args.nocoal ~= 1) and (not m_data[word]) then | |||
for _, case in ipairs(coal_cases) do | |||
local n = 1 | |||
local v = "(" .. vowels .. ")" | |||
if data.decl_type ~= "l" then | |||
while data.forms[case][n] do | |||
for regex, repl in pairs(m_com.triphthong_coalescence) do | |||
data.forms[case][n] = gsub(data.forms[case][n], v .. v .. v .. v, "%1%2%3@%4") | |||
data.forms[case][n] = gsub(data.forms[case][n], regex, repl) | |||
data.forms[case][n] = gsub(data.forms[case][n], "@", "") | |||
-- just in case some slipped through | |||
if not parent_args["notine"] then | |||
data.forms["ine"][n] = gsub(data.forms["ine"][n], "([aoueů])ia$", "%1įa") | |||
data.forms["ine"][n] = gsub(data.forms["ine"][n], "ỉia$", "igįia") | |||
end | |||
end | |||
n = n + 1 | |||
end | |||
end | |||
end | |||
end | |||
--[[]] | |||
else | else | ||
for _, form in ipairs({"m_sg", "u_pl", "m_pl"}) do | for _, form in ipairs({"m_sg", "u_pl", "m_pl"}) do | ||
| Line 136: | Line 166: | ||
end | end | ||
--[=[ | |||
local function link(term) | local function link(term) | ||
local links = {} | local links = {} | ||
| Line 143: | Line 174: | ||
end | end | ||
return table.concat(links, ", ") | return table.concat(links, ", ") | ||
end | end | ||
]=] | |||
local function link(term) | |||
local links = {} | |||
for alt in gmatch(term, "([^%s,]+)") do | |||
alt = term == "—" and term or m_l.full_link{lang=data.lang,term=term} | |||
table.insert(links, alt) | |||
end | |||
return table.concat(links, ", ") | |||
end | |||
local function repl(param) | local function repl(param) | ||
| Line 149: | Line 191: | ||
return data.decl_type == "irregular" and data.decl_type or "''" .. data.decl_type .. "''-declension" | return data.decl_type == "irregular" and data.decl_type or "''" .. data.decl_type .. "''-declension" | ||
elseif param == "title" then | elseif param == "title" then | ||
return NAMESPACE == "Template" and "sivi" or PAGENAME | return NAMESPACE == "Template" and "sivi" or data.alt or PAGENAME | ||
elseif param == "word" and NAMESPACE == "Template" then | elseif param == "word" and NAMESPACE == "Template" then | ||
return "sivi" | return "sivi" | ||
| Line 175: | Line 217: | ||
table.insert(ret, "|-\n") | table.insert(ret, "|-\n") | ||
for _, single in ipairs(all) do | for _, single in ipairs(all) do | ||
table.insert(ret, "| " .. link | table.insert(ret, "| " .. link(show_form(data.forms[single])) .. "\n") | ||
end | end | ||
else | else | ||
| Line 190: | Line 232: | ||
local navframe = [=[ | local navframe = [=[ | ||
<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; width: 70%;"> | <div class="wikitable 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; width: 70%;"> | ||
<div style="min-height: 1.6em; font-weight:bold; font-size: 100%; text-align: left; background-color:#efefef; 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}}}'' —]=] .. (data.pos == "adjectives" and " " or " {{{gender}}} ") .. sub(data.pos, 1, -2) .. (data.g == "i" and ", {{{decl_type}}}" or "") .. [=[ | <div style="min-height: 1.6em; font-weight:bold; font-size: 100%; text-align: left; background-color:#efefef; 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}}}'' —]=] .. (data.pos == "adjectives" and " " or " {{{gender}}} ") .. sub(data.pos, 1, -2) .. (data.g == "i" and ", {{{decl_type}}}" or "") .. [=[ | ||
</div> | </div> | ||