Module:ábḫ-ipa: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 4: | Line 4: | ||
local word = type(frame) == "table" and frame.args[1] or frame | local word = type(frame) == "table" and frame.args[1] or frame | ||
-- go from orthography to one-to-one | |||
word = string.gsub(word, "mb", "B") | word = string.gsub(word, "mb", "B") | ||
word = string.gsub(word, "nd", "D") | word = string.gsub(word, "nd", "D") | ||
Line 12: | Line 13: | ||
word = string.gsub(word, "jh", "J") | word = string.gsub(word, "jh", "J") | ||
word = string.gsub(word, "ḫ", "H") | word = string.gsub(word, "ḫ", "H") | ||
word = string.gsub(word, "ii", "ī") | word = string.gsub(word, "ii", "ī") | ||
word = string.gsub(word, "íi", "î") | word = string.gsub(word, "íi", "î") | ||
word = string.gsub(word, "ií", "ǐ") | word = string.gsub(word, "ií", "ǐ") | ||
word = string.gsub(word, "ei", "ē") | word = string.gsub(word, "ei", "ē") | ||
word = string.gsub(word, "éi", "ê") | word = string.gsub(word, "éi", "ê") | ||
word = string.gsub(word, "eí", "ě") | word = string.gsub(word, "eí", "ě") | ||
word = string.gsub(word, "ou", "ō") | word = string.gsub(word, "ou", "ō") | ||
word = string.gsub(word, "óu", "ô") | word = string.gsub(word, "óu", "ô") | ||
Line 26: | Line 24: | ||
word = string.gsub(word, "oi", "I") | word = string.gsub(word, "oi", "I") | ||
word = string.gsub(word, "ói", "Í") | word = string.gsub(word, "ói", "Í") | ||
word = string.gsub(word, "aai", "Ā") | word = string.gsub(word, "aai", "Ā") | ||
word = string.gsub(word, "áai", "Â") | word = string.gsub(word, "áai", "Â") | ||
Line 32: | Line 29: | ||
word = string.gsub(word, "ai", "A") | word = string.gsub(word, "ai", "A") | ||
word = string.gsub(word, "ái", "Á") | word = string.gsub(word, "ái", "Á") | ||
word = string.gsub(word, "aao", "Ō") | word = string.gsub(word, "aao", "Ō") | ||
word = string.gsub(word, "áao", "Ô") | word = string.gsub(word, "áao", "Ô") | ||
Line 38: | Line 34: | ||
word = string.gsub(word, "ao", "O") | word = string.gsub(word, "ao", "O") | ||
word = string.gsub(word, "áo", "Ó") | word = string.gsub(word, "áo", "Ó") | ||
word = string.gsub(word, "aa", "ā") | word = string.gsub(word, "aa", "ā") | ||
word = string.gsub(word, "áa", "â") | word = string.gsub(word, "áa", "â") | ||
word = string.gsub(word, "aá", "ǎ") | word = string.gsub(word, "aá", "ǎ") | ||
word = mw.text.split(word, "", true) | word = mw.text.split(word, "", true) | ||
Line 49: | Line 42: | ||
result = {} | result = {} | ||
-- put in syllable boundary marks | |||
for i,val in ipairs(word) do | for i,val in ipairs(word) do | ||
if word[i-1] == nil then | if word[i-1] == nil then | ||
Line 58: | Line 52: | ||
table.insert(result, val) | table.insert(result, val) | ||
else | else | ||
table.insert(result, ".") | |||
table.insert(result, val) | table.insert(result, val) | ||
end | end | ||
Line 89: | Line 84: | ||
end | end | ||
word = table.concat( | -- isolate syllable boundary marks | ||
stresses = string.gsub(table.concat(result), "[^.ˈ]") | |||
syllables = string.len(stresses) | |||
stresses = mw.text.split(stresses, "", true) | |||
-- compute position of stress | |||
pos = 0 | |||
for i,val in word do | |||
if mw.ustring.match(word[i], "ˈ") then | |||
pos = i | |||
end | |||
end | |||
newStresses = {} | |||
-- mark secondary stress | |||
for i,val in stresses do | |||
if mw.ustring.match(word[i], ".") and i ~= syllables then | |||
if (i - pos) % 2 == 0 then | |||
table.insert(newStresses, "ˌ") | |||
else | |||
if not (i == 1 and mw.ustring.match(result[1], ".")) then | |||
table.insert(newStresses, val) | |||
end | |||
end | |||
else | |||
table.insert(newStresses, val) | |||
end | |||
end | |||
-- look through word and replace the correct .'s with ˌ's | |||
newWord = {} | |||
index = 1 | |||
for val in words do | |||
if mw.ustring.match(val, "[.ˈ]") then | |||
table.insert(newWord, newStresses[index]) | |||
index = index + 1 | |||
else | |||
table.insert(newWord, val) | |||
end | |||
end | |||
word = table.concat(newWord) | |||
-- go from one-to-one phonemic map to IPA | |||
word = string.gsub(word, "B", "ᵐb") | word = string.gsub(word, "B", "ᵐb") | ||
word = string.gsub(word, "D", "ⁿd") | word = string.gsub(word, "D", "ⁿd") |
Revision as of 00:17, 28 February 2020
- The following documentation is located at Module:ábḫ-ipa/doc.[edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
local export = {}
function export.convert(frame)
local word = type(frame) == "table" and frame.args[1] or frame
-- go from orthography to one-to-one
word = string.gsub(word, "mb", "B")
word = string.gsub(word, "nd", "D")
word = string.gsub(word, "ng", "G")
word = string.gsub(word, "mp", "P")
word = string.gsub(word, "ntt", "Tt")
word = string.gsub(word, "nkk", "Kk")
word = string.gsub(word, "jh", "J")
word = string.gsub(word, "ḫ", "H")
word = string.gsub(word, "ii", "ī")
word = string.gsub(word, "íi", "î")
word = string.gsub(word, "ií", "ǐ")
word = string.gsub(word, "ei", "ē")
word = string.gsub(word, "éi", "ê")
word = string.gsub(word, "eí", "ě")
word = string.gsub(word, "ou", "ō")
word = string.gsub(word, "óu", "ô")
word = string.gsub(word, "oú", "ǒ")
word = string.gsub(word, "oi", "I")
word = string.gsub(word, "ói", "Í")
word = string.gsub(word, "aai", "Ā")
word = string.gsub(word, "áai", "Â")
word = string.gsub(word, "aái", "Ǎ")
word = string.gsub(word, "ai", "A")
word = string.gsub(word, "ái", "Á")
word = string.gsub(word, "aao", "Ō")
word = string.gsub(word, "áao", "Ô")
word = string.gsub(word, "aáo", "Ǒ")
word = string.gsub(word, "ao", "O")
word = string.gsub(word, "áo", "Ó")
word = string.gsub(word, "aa", "ā")
word = string.gsub(word, "áa", "â")
word = string.gsub(word, "aá", "ǎ")
word = mw.text.split(word, "", true)
result = {}
-- put in syllable boundary marks
for i,val in ipairs(word) do
if word[i-1] == nil then
if mw.ustring.match(word[i], "[íîǐéêěóôǒÍáâǎÁÂǍÓÔǑ]") then
table.insert(result, "ˈ")
table.insert(result, val)
elseif mw.ustring.match(word[i], "[mnjBDGPpTtKkbzdsJHhry]") and mw.ustring.match(word[i+1], "[íîǐéêěóôǒÍáâǎÁÂǍÓÔǑ]") then
table.insert(result, "ˈ")
table.insert(result, val)
else
table.insert(result, ".")
table.insert(result, val)
end
elseif mw.ustring.match(word[i], "[iīeēoōIaāAĀOŌ]") then
if mw.ustring.match(word[i-1], "[iīeēoōIaāAĀOŌíîǐéêěóôǒÍáâǎÁÂǍÓÔǑ]") then
table.insert(result, ".")
table.insert(result, val)
else
table.insert(result, val)
end
elseif mw.ustring.match(word[i], "[íîǐéêěóôǒÍáâǎÁÂǍÓÔǑ]") then
if mw.ustring.match(word[i-1], "[iīeēoōIaāAĀOŌíîǐéêěóôǒÍáâǎÁÂǍÓÔǑ]") then
table.insert(result, "ˈ")
table.insert(result, val)
else
table.insert(result, val)
end
else
if word[i+1] == nil then
table.insert(result, val)
elseif mw.ustring.match(word[i+1], "[iīeēoōIaāAĀOŌ]") then
table.insert(result, ".")
table.insert(result, val)
elseif mw.ustring.match(word[i+1], "[íîǐéêěóôǒÍáâǎÁÂǍÓÔǑ]") then
table.insert(result, "ˈ")
table.insert(result, val)
else
table.insert(result, val)
end
end
end
-- isolate syllable boundary marks
stresses = string.gsub(table.concat(result), "[^.ˈ]")
syllables = string.len(stresses)
stresses = mw.text.split(stresses, "", true)
-- compute position of stress
pos = 0
for i,val in word do
if mw.ustring.match(word[i], "ˈ") then
pos = i
end
end
newStresses = {}
-- mark secondary stress
for i,val in stresses do
if mw.ustring.match(word[i], ".") and i ~= syllables then
if (i - pos) % 2 == 0 then
table.insert(newStresses, "ˌ")
else
if not (i == 1 and mw.ustring.match(result[1], ".")) then
table.insert(newStresses, val)
end
end
else
table.insert(newStresses, val)
end
end
-- look through word and replace the correct .'s with ˌ's
newWord = {}
index = 1
for val in words do
if mw.ustring.match(val, "[.ˈ]") then
table.insert(newWord, newStresses[index])
index = index + 1
else
table.insert(newWord, val)
end
end
word = table.concat(newWord)
-- go from one-to-one phonemic map to IPA
word = string.gsub(word, "B", "ᵐb")
word = string.gsub(word, "D", "ⁿd")
word = string.gsub(word, "j", "ɲ")
word = string.gsub(word, "G", "ᵑg")
word = string.gsub(word, "P", "mp")
word = string.gsub(word, "T", "nt")
word = string.gsub(word, "K", "nk")
word = string.gsub(word, "b", "β")
word = string.gsub(word, "z", "θ")
word = string.gsub(word, "d", "ð")
word = string.gsub(word, "s", "ɕ")
word = string.gsub(word, "J", "ʑ")
word = string.gsub(word, "H", "x")
word = string.gsub(word, "h", "ɦ")
word = string.gsub(word, "r", "ɺ")
word = string.gsub(word, "y", "j")
word = string.gsub(word, "ī", "iː")
word = string.gsub(word, "î", "îː")
word = string.gsub(word, "ǐ", "ǐː")
word = string.gsub(word, "ē", "eːɪ̯")
word = string.gsub(word, "ê", "êːɪ̯")
word = string.gsub(word, "ě", "ěːɪ̯")
word = string.gsub(word, "o", "ɔ")
word = string.gsub(word, "ó", "ɔ́")
word = string.gsub(word, "ō", "ɔːʊ̯")
word = string.gsub(word, "ô", "ɔ̂ːʊ̯")
word = string.gsub(word, "ǒ", "ɔ̌ːʊ̯")
word = string.gsub(word, "I", "ɔɪ̯")
word = string.gsub(word, "Í", "ɔ́ɪ̯")
word = string.gsub(word, "ā", "aː")
word = string.gsub(word, "â", "âː")
word = string.gsub(word, "ǎ", "ǎː")
word = string.gsub(word, "A", "aɪ̯")
word = string.gsub(word, "Á", "áɪ̯")
word = string.gsub(word, "Ā", "aːɪ̯")
word = string.gsub(word, "Â", "âːɪ̯")
word = string.gsub(word, "Ǎ", "ǎːɪ̯")
word = string.gsub(word, "O", "aɔ̯")
word = string.gsub(word, "Ó", "áɔ̯")
word = string.gsub(word, "Ō", "aːɔ̯")
word = string.gsub(word, "Ô", "âːɔ̯")
word = string.gsub(word, "Ǒ", "ǎːɔ̯")
return "/" .. word .. "/"
end
return export