Module:pine-pron: Difference between revisions
Jump to navigation
Jump to search
No edit summary Tag: Reverted |
No edit summary |
||
| (38 intermediate revisions by the same user not shown) | |||
| Line 15: | Line 15: | ||
local vowels = "[aɑæɔoʊuʏyɛœøiɪe]" | local vowels = "[aɑæɔoʊuʏyɛœøiɪe]" | ||
local lazy_consonants = "[^" .. vowels_spelling .."]" | local lazy_consonants = "[^" .. vowels_spelling .."]" | ||
local consonants_spelling = "[ | local consonants_spelling = "[rṛtįpsṡdḍgġhḥkḳlḷƛvbnṇmṃʧʦ]" | ||
local laxen = { | local laxen = { | ||
["y"] = "ʏ", ["i"] = "ɪ", ["e"] = "ɛ", | ["y"] = "ʏ", ["i"] = "ɪ", ["e"] = "ɛ", | ||
["u"] = "ʊ", ["o"] = "ɔ", ["a"] = "ɑ", | ["u"] = "ʊ", ["o"] = "ɔ", ["a"] = "ɑ", | ||
["ů"] = "œ" | |||
} | } | ||
local long_vowels = { | local long_vowels = { | ||
["ả"] = "æː", ["ẻ"] = "eː", ["ỉ"] = "iː", | ["ả"] = "æː", ["ẻ"] = "eː", ["ỉ"] = "iː", | ||
["ỏ"] = "oː", ["ủ"] = "uː", ["ỷ"] = "yː", | ["ỏ"] = "oː", ["ủ"] = "uː", ["ỷ"] = "yː", | ||
| Line 46: | Line 45: | ||
end | end | ||
end | end | ||
local export = {} | local export = {} | ||
local | function export.vowel_harmony(term) | ||
local polarity = { | |||
["au"] = "back", ["[ei]?u[oa]?"] = "back", ["o[ai]?"] = "back", ["[ủỏ]"] = "back", | |||
["a[iy]"] = "front", ["ey"] = "front", ["ů[aei]?"] = "front", ["[ei]ů"] = "front", ["[ủỷả]"] = "front" | |||
} | |||
for pat, harmony in pairs(polarity) do | |||
if find(term, pat) then return harmony end | |||
end | |||
return "neutral" | |||
end | |||
function export.syllabify_from_spelling(term) | -- exportable to be used by [[Module:pine-noun]] | ||
function export.syllabify_from_spelling(term, is_ipa) | |||
local vowels = "[" .. vowels_spelling .. "]" | local vowels = "[" .. vowels_spelling .. "]" | ||
local consonants = consonants_spelling --lazy_consonants | local consonants = consonants_spelling --lazy_consonants | ||
term = gsub(term, "(t[sṡ])", {["ts"] = "ʦ", ["tṡ"] = "ʧ"}) | |||
local words = split(term, "%s") | local words = split(term, "%s") | ||
for i, word in ipairs(words) do | for i, word in ipairs(words) do | ||
word = gsub(word, "(" .. consonants .. "*)(" .. vowels .. "+)(" .. consonants .. "*)", "%1%2·%3") | |||
word = gsub(word, "·(" .. consonants .. "?)$", "%1") | |||
word = | word = gsub(word, "·(" .. consonants .. ")(" .. consonants .. "+)", "%1·%2") | ||
word = | word = gsub(word, "(" .. consonants .. ")·%1", "·%1%1") | ||
word = gsub(word, "(" .. vowels .. ")(" .. consonants .. ")·v(" .. vowels .. ")", "%1·%2v%3") | |||
word = gsub(word, "(" .. vowels .. ")t·([ʦʧ])(" .. vowels .. ")", "%1·t%2%3") | |||
words[i] = word | words[i] = word | ||
end | end | ||
term = table.concat(words, " ") | |||
if not is_ipa then | |||
term = gsub(term, "([ʦʧ])", {["ʦ"] = "ts", ["ʧ"] = "tṡ"}) | |||
end | |||
return term | |||
end | end | ||
function export.crux(term) | function export.crux(term) | ||
term = export.syllabify_from_spelling(term) | term = export.syllabify_from_spelling(term, true) | ||
-- default to short lax vowels | -- default to short lax vowels | ||
term = | term = gsub(term, "[aeiouyů]", laxen) | ||
-- long vowels | -- long vowels | ||
term = gsub(term, "([ảẻỉỏủỷ])", long_vowels) | |||
term = gsub(term, "ɔɑ", "ɑː"); term = gsub(term, "ɛœ", "øː") | |||
term = | |||
-- diphthongized vowels | -- diphthongized vowels | ||
term = | term = gsub(term, "ʊɔ", "ʊu"); term = gsub(term, "œɑ", "øy"); term = gsub(term, "œɛ", "ʏy") | ||
-- labiodiphthongized vowels | -- labiodiphthongized vowels | ||
term = | term = gsub(term, "vʏy", "ᶣy"); term = gsub(term, "vøy", "ᶣø"); term = gsub(term, "vʊu", "ʷu") -- different in eastern | ||
term = | term = gsub(term, "^ᶣ", "ɥ"); term = gsub(term, "^ʷ", "w") | ||
-- diphthongs | -- diphthongs | ||
term = | term = gsub(term, "([ɛɑ])ʏ", "%1y"); term = gsub(term, "ɑy", "æy") | ||
term = | term = gsub(term, "([ɛɑɪ]ʊ)", "%1u"); term = gsub(term, "ɪœ", "ɪy") | ||
-- simple consonant subtitutions | -- simple consonant subtitutions | ||
term = | term = gsub(term, "ṡ", "ʃ") | ||
term = | term = gsub(term, "ḷ", "ɬ"); term = gsub(term, "ḥ", "ʔ"); | ||
-- geminate consonants | -- geminate consonants | ||
term = | term = gsub(term, "(.)%1", "%1ː"); term = gsub(term, "ng", "ŋː") | ||
local final_subs = { | local final_subs = { | ||
["ʧ"] = "t͡ʃ", | ["ʧ"] = "t͡ʃ", | ||
| Line 132: | Line 120: | ||
["ṇ"] = "n" .. c.ringbelow, | ["ṇ"] = "n" .. c.ringbelow, | ||
["ṛ"] = "r" .. c.ringbelow, | ["ṛ"] = "r" .. c.ringbelow, | ||
["·"] = ".", | |||
} | } | ||
term = | term = gsub(term, "[ʧʦgƛṃṇṛ·]", final_subs) | ||
return term | return term | ||
Latest revision as of 13:22, 27 November 2025
- The following documentation is located at Module:pine-pron/doc.[edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
local sub = mw.ustring.sub
local find = mw.ustring.find
local gmatch = mw.ustring.gmatch
local gsub = mw.ustring.gsub
local match = mw.ustring.match
local u = mw.ustring.char
local split = mw.text.split
local gsplit = mw.text.gsplit
local lang = require("Module:languages").getByCode("pine")
local c = require("Module:languages/data").chars
local m_IPA = require("Module:IPA")
local vowels_spelling = "aeiouyůảẻỉỏủỷ"
local vowels = "[aɑæɔoʊuʏyɛœøiɪe]"
local lazy_consonants = "[^" .. vowels_spelling .."]"
local consonants_spelling = "[rṛtįpsṡdḍgġhḥkḳlḷƛvbnṇmṃʧʦ]"
local laxen = {
["y"] = "ʏ", ["i"] = "ɪ", ["e"] = "ɛ",
["u"] = "ʊ", ["o"] = "ɔ", ["a"] = "ɑ",
["ů"] = "œ"
}
local long_vowels = {
["ả"] = "æː", ["ẻ"] = "eː", ["ỉ"] = "iː",
["ỏ"] = "oː", ["ủ"] = "uː", ["ỷ"] = "yː",
}
-- version of gsub() that returns a 2nd argument boolean indicating whether
-- a substitution was made.
local function gsubb(term, foo, bar)
local retval, nsubs = gsub(term, foo, bar)
return retval, nsubs > 0
end
-- apply gsub() repeatedly until no change
local function gsub_repeatedly(term, foo, bar)
while true do
local new_term = gsub(term, foo, bar)
if new_term == term then
return term
end
term = new_term
end
end
local export = {}
function export.vowel_harmony(term)
local polarity = {
["au"] = "back", ["[ei]?u[oa]?"] = "back", ["o[ai]?"] = "back", ["[ủỏ]"] = "back",
["a[iy]"] = "front", ["ey"] = "front", ["ů[aei]?"] = "front", ["[ei]ů"] = "front", ["[ủỷả]"] = "front"
}
for pat, harmony in pairs(polarity) do
if find(term, pat) then return harmony end
end
return "neutral"
end
-- exportable to be used by [[Module:pine-noun]]
function export.syllabify_from_spelling(term, is_ipa)
local vowels = "[" .. vowels_spelling .. "]"
local consonants = consonants_spelling --lazy_consonants
term = gsub(term, "(t[sṡ])", {["ts"] = "ʦ", ["tṡ"] = "ʧ"})
local words = split(term, "%s")
for i, word in ipairs(words) do
word = gsub(word, "(" .. consonants .. "*)(" .. vowels .. "+)(" .. consonants .. "*)", "%1%2·%3")
word = gsub(word, "·(" .. consonants .. "?)$", "%1")
word = gsub(word, "·(" .. consonants .. ")(" .. consonants .. "+)", "%1·%2")
word = gsub(word, "(" .. consonants .. ")·%1", "·%1%1")
word = gsub(word, "(" .. vowels .. ")(" .. consonants .. ")·v(" .. vowels .. ")", "%1·%2v%3")
word = gsub(word, "(" .. vowels .. ")t·([ʦʧ])(" .. vowels .. ")", "%1·t%2%3")
words[i] = word
end
term = table.concat(words, " ")
if not is_ipa then
term = gsub(term, "([ʦʧ])", {["ʦ"] = "ts", ["ʧ"] = "tṡ"})
end
return term
end
function export.crux(term)
term = export.syllabify_from_spelling(term, true)
-- default to short lax vowels
term = gsub(term, "[aeiouyů]", laxen)
-- long vowels
term = gsub(term, "([ảẻỉỏủỷ])", long_vowels)
term = gsub(term, "ɔɑ", "ɑː"); term = gsub(term, "ɛœ", "øː")
-- diphthongized vowels
term = gsub(term, "ʊɔ", "ʊu"); term = gsub(term, "œɑ", "øy"); term = gsub(term, "œɛ", "ʏy")
-- labiodiphthongized vowels
term = gsub(term, "vʏy", "ᶣy"); term = gsub(term, "vøy", "ᶣø"); term = gsub(term, "vʊu", "ʷu") -- different in eastern
term = gsub(term, "^ᶣ", "ɥ"); term = gsub(term, "^ʷ", "w")
-- diphthongs
term = gsub(term, "([ɛɑ])ʏ", "%1y"); term = gsub(term, "ɑy", "æy")
term = gsub(term, "([ɛɑɪ]ʊ)", "%1u"); term = gsub(term, "ɪœ", "ɪy")
-- simple consonant subtitutions
term = gsub(term, "ṡ", "ʃ")
term = gsub(term, "ḷ", "ɬ"); term = gsub(term, "ḥ", "ʔ");
-- geminate consonants
term = gsub(term, "(.)%1", "%1ː"); term = gsub(term, "ng", "ŋː")
local final_subs = {
["ʧ"] = "t͡ʃ",
["ʦ"] = "t͡s",
["g"] = "ɡ",
["ƛ"] = "t͡ɬ",
["ṃ"] = "m" .. c.ringbelow,
["ṇ"] = "n" .. c.ringbelow,
["ṛ"] = "r" .. c.ringbelow,
["·"] = ".",
}
term = gsub(term, "[ʧʦgƛṃṇṛ·]", final_subs)
return term
end
function export.show(frame)
local parent_args = frame:getParent().args
local params = {
[1] = { default = mw.title.getCurrentTitle().nsText == 'Template' and "Niṡkullit" or mw.title.getCurrentTitle().text },
}
local args = require("Module:parameters").process(parent_args, params)
local term = mw.ustring.lower(args[1])
local pronunciations = {
{pron = "[" .. export.crux(term) .. "]"}
}
return "* " .. m_IPA.format_IPA_full{lang = lang, items = pronunciations}
end
return export