Module:mg-pron: Difference between revisions
Jump to navigation
Jump to search
Created page with "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..." |
No edit summary |
||
| Line 9: | Line 9: | ||
local NASAL = u(0x0303) -- COMBINING TILDE, ̃ | local NASAL = u(0x0303) -- COMBINING TILDE, ̃ | ||
local velar = "[kɡɫ]" | |||
local consonants = "[bkdhjlmnɲprɾstʃθβðɡɣzʧɫʎ]" | |||
local vowels = "[aeiou]" | |||
local function same(foo, bar) | local function same(foo, bar) | ||
| Line 17: | Line 21: | ||
local export = {} | local export = {} | ||
local prelims = { | |||
{"r", "ɾ"}, {"ch", "ʧ"}, {"qu", "k"}, {"il", "ʎ"}, {"ñ", "ɲ"}, | |||
} | |||
local rules = { | local rules = { | ||
{"([ɾs])([ɾs])", function(s1, s2) return same(s1, s2) and "ʰ%1" or s1 .. s2 end}, | |||
{".$", {["a"] = "ɐ", ["e"] = "ɪ", ["o"] = "ʊ", --[[["n"] = NASAL]]}} | {".$", {["a"] = "ɐ", ["e"] = "ɪ", ["o"] = "ʊ", --[[["n"] = NASAL]]}} | ||
} | } | ||
local function syllabify(term) | |||
end | |||
function export.crux(term) | function export.crux(term) | ||
term = mw.ustring.lower(term) | term = mw.ustring.lower(term) | ||
for _, repl in ipairs(prelims) do | |||
term = gsub(term, repl[1], repl[2]) | |||
end | |||
term = syllabify(term) | |||
for _, rule in ipairs(rules) do | for _, rule in ipairs(rules) do | ||
Revision as of 15:35, 25 August 2021
- The following documentation is located at Module:mg-pron/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 NASAL = u(0x0303) -- COMBINING TILDE, ̃
local velar = "[kɡɫ]"
local consonants = "[bkdhjlmnɲprɾstʃθβðɡɣzʧɫʎ]"
local vowels = "[aeiou]"
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 export = {}
local prelims = {
{"r", "ɾ"}, {"ch", "ʧ"}, {"qu", "k"}, {"il", "ʎ"}, {"ñ", "ɲ"},
}
local rules = {
{"([ɾs])([ɾs])", function(s1, s2) return same(s1, s2) and "ʰ%1" or s1 .. s2 end},
{".$", {["a"] = "ɐ", ["e"] = "ɪ", ["o"] = "ʊ", --[[["n"] = NASAL]]}}
}
local function syllabify(term)
end
function export.crux(term)
term = mw.ustring.lower(term)
for _, repl in ipairs(prelims) do
term = gsub(term, repl[1], repl[2])
end
term = syllabify(term)
for _, rule in ipairs(rules) do
term = gsub(term, rule[1], rule[2])
end
return term
end
function IPA_span(items)
local bits = {}
for _, item in ipairs(items) do
local bit = "<span style=\"font-size:110%;font-family:'Gentium','DejaVu Sans','Segoe UI',sans-serif>" .. item.pron .. "</span>"
table.insert(bits, bit)
end
return table.concat(bits)
end
function format_IPA(items)
return "[[w:IPA chart|IPA]]<sup>([[IPA for Modern Gallaecian|key]])</sup>: " .. IPA_span(items)
end
function line_format(pronunciation)
local full_pronunciations = {}
local IPA_args = {{pron = '[' .. pronunciation .. ']'}}
table.insert(full_pronunciations, format_IPA(IPA_args))
return table.concat(full_pronunciations)
end
function separate_word(term)
local result = {}
for word in gsplit(term, " ") do
table.insert(result, export.crux(word))
end
return table.concat(result, " ")
end
function export.show(frame)
local params = {
[1] = { default = mw.title.getCurrentTitle().nsText == 'Template' and "gueizuñe" or mw.title.getCurrentTitle().text },
}
local args = require("Module:parameters").process(frame:getParent().args, params)
local term = args[1]
local ipa = "* "
ipa = ipa .. line_format(separate_word(term))
return ipa
end
return export