Module:xchc-pron: Difference between revisions

Undo revision 474002 by Sware (talk)
No edit summary
 
(6 intermediate revisions by the same user not shown)
Line 7: Line 7:
local split = mw.text.split
local split = mw.text.split
local gsplit = mw.text.gsplit
local gsplit = mw.text.gsplit
local M = u(0x0304) -- COMBINING MACRON
local B = u(0x0306) -- COMBINING BREVE
local D = u(0x0308) -- COMBINING DIAERESIS


local lang = require("Module:languages").getByCode("xchc")
local lang = require("Module:languages").getByCode("xchc")
Line 16: Line 12:
local m_IPA = require("Module:IPA")
local m_IPA = require("Module:IPA")


local M = c.macron
local B = c.breve
local D = c.diaer
local nb_cons = "mnŋɲptbdkɡfvszʃʒxɣhʧʦʤʣlrɾʎ"
local nb_cons = "mnŋɲptbdkɡfvszʃʒxɣhʧʦʤʣlrɾʎ"
local consonants = "[" .. nb_cons .. "]"
local consonants = "[" .. nb_cons .. "]"
local consonantsAsIs = "[мньӈбдгвзжғлрйпткфсшӀчц]"
local vowels = "[ыиэеаяүөуюоёӯӣɜɔ]"


local export = {}
local export = {}
local function laxen(v)
local otc = {}
local switch = {["e"] = "ɛ", ["i"] = "ɪ", ["o"] = "ɔ", ["u"] = "ʊ"}
for vc in gmatch(v, ".") do
if switch[vc] then vc = gsub(vc, vc, switch[vc]) end
table.insert(otc, vc)
end
return table.concat(otc)
end
local function same(foo, bar)
foo, bar = mw.ustring.toNFD(foo), mw.ustring.toNFD(bar) -- decompose diacritics
foo, bar = match(foo, "^."), match(bar, "^.") -- sort out the letter
return foo == bar and true or false
end


local first_rules = {
local first_rules = {
Line 78: Line 63:
{"l[ьі]", "ʎ"}, {"n[ьі]", "ɲ"}, {"[ьі]", "j"},
{"l[ьі]", "ʎ"}, {"n[ьі]", "ɲ"}, {"[ьі]", "j"},
{"(" .. consonants .. ")(" .. consonants .. ")", function(c1,c2) return same(c1, c2) and c1 .. "ː" or c1 .. c2 end},
{"(" .. consonants .. ")%1", "%1ː"},
{"r$", "ɾ"}, {"([ŋkɡxɣh])a", "%1ɑ"}, {"a(ː?[ŋkɡxɣh])", "ɑ%1"}
{"r$", "ɾ"}, {"([ŋkɡxɣh])a", "%1ɑ"}, {"a(ː?[ŋkɡxɣh])", "ɑ%1"}
}
}
Line 111: Line 96:
-- Remove diacritics for module calculations based on vowels
-- Remove diacritics for module calculations based on vowels
function export.simplify(term)
function export.simplify(term)
term = mw.usting.toNFD(term):gsub(c.macron, "") -- vowel length  
term = mw.ustring.toNFD(term):gsub(c.macron, "") -- vowel length  
term = term:gsub("э" .. c.breve, "ɛ"); term = term:gsub("о" .. c.breve, "ɔ")
term = term:gsub("э" .. c.breve, "ɛ"); term = term:gsub("о" .. c.breve, "ɔ")
term = mw.ustring.toNFC(term):gsub("ё", "о"); term = term:gsub("е" .. c.diaer, "о")
term = mw.ustring.toNFC(term):gsub("ё", "о"); term = term:gsub("е" .. c.diaer, "о")
Line 132: Line 117:
function export.harmony(term)
function export.harmony(term)
term = export.simplify(term)
term = export.simplify(term)
--[[local ret = {
local termR, termB = term, term
["roundness"] = ((not term:match("о" .. c.macron .. "?" .. c.breve) and term:match("[үуӯюөоё]")) or term:match("е" .. c.macron .. c.diaer)) and "r"
or term:match("[ыиӣэе]") and "u" or "ar",
local unrounded = "[ыиӣеэ]"; local rounded = "[үөуӯюоё]"; local neutralR = "[ɛɔая]"
["backness"] = term:match("э") and "f" or term:match("о" .. c.macron .. "?" .. c.breve) and "b" or "ab",
local front = "ɛ"; local back = "ɔ"; local neutralB = "[ыиӣеэүөуӯюоёая]"
}]]
 
-- for words that violate vowel harmony (compounds and loanwords)
local exception = (term:match(unrounded) and term:match(rounded)) or (term:match(front) and term:match(back))
if exception then
termR = term:gsub(neutralR, ""); termB = term:gsub(neutralB, "")
termR = termR:match("(".. vowels .. consonantsAsIs .. "*)$") or termR; termB = termB:match("(" .. vowels .. consonants .. "*)$") or termB
end
local ret = {
local ret = {
["roundness"] = term:match("[ыиӣеэ]") and "u" or term:match("[үөуӯюоё]") and "r" or "ar",
["roundness"] = termR:match(unrounded) and "u" or termR:match(rounded) and "r" or "ar",
["backness"] = term:match("ɜ") and "f" or term:match("ɔ") and "b" or "ab",
["backness"] = termB:match(front) and "f" or termB:match(back) and "b" or "ab",
}
}
return ret
return ret