Module:Sandbox/Nardog/2
local p = {}
local getArgs = require('Module:Arguments').getArgs
local gsub = mw.ustring.gsub
local function isCons(s)
if s == 'b'
or s == 'd'
or s == 'dj'
or s == 'dʒ'
or s == 'ð'
or s == 'f'
or s == 'ɡ'
or s == 'h'
or s == 'hw'
or s == 'j'
or s == 'k'
or s == 'l'
or s == 'lj'
or s == 'm'
or s == 'n'
or s == 'nj'
or s == 'ŋ'
or s == 'p'
or s == 'r'
or s == 's'
or s == 'sj'
or s == 'ʃ'
or s == 't'
or s == 'tj'
or s == 'tʃ'
or s == 'θ'
or s == 'θj'
or s == 'v'
or s == 'w'
or s == 'z'
or s == 'zj'
or s == 'ʒ'
or s == 'x'
or s == 'ʔ'
then
return true
end
end
local function isVowel(s)
if s == 'ɑː'
or s == 'ɑːr'
or s == 'ɒ'
or s == 'ɒr'
or s == 'æ'
or s == 'ær'
or s == 'aɪ'
or s == 'aɪər'
or s == 'aʊ'
or s == 'aʊər'
or s == 'ɛ'
or s == 'ɛr'
or s == 'eɪ'
or s == 'ɛər'
or s == 'ɪ'
or s == 'ɪr'
or s == 'iː'
or s == 'ɪər'
or s == 'ɔː'
or s == 'ɔːr'
or s == 'ɔɪ'
or s == 'ɔɪər'
or s == 'oʊ'
or s == 'ɔər'
or s == 'ʊ'
or s == 'ʊr'
or s == 'uː'
or s == 'ʊər'
or s == 'juː'
or s == 'jʊər'
or s == 'ʌ'
or s == 'ʌr'
or s == 'ɜːr'
or s == 'ə'
or s == 'ər'
or s == 'əl'
or s == 'ən'
or s == 'əm'
or s == 'i'
or s == 'u'
or s == 'ᵻ'
or s == 'ᵿ'
or s == 'jᵿ'
then
return true
end
end
local function isChecked(s)
if s == 'ɒ'
or s == 'æ'
or s == 'ɛ'
or s == 'ɪ'
or s == 'ʊ'
or s == 'ʌ'
then
return true
end
end
local function isSeg(s)
if isCons(s) or isVowel(s) then
return true
end
end
local function isStr(s)
if s == 'ˈ' or s == 'ˌ' then
return true
end
end
local function toResp(s)
if s == 'dj' then
return 'dy'
elseif s == 'dʒ' then
return 'j'
elseif s == 'ð' then
return 'dh'
elseif s == 'ɡ' then
return 'g'
elseif s == 'hw' then
return 'wh'
elseif s == 'j' then
return 'y'
elseif s == 'lj' then
return 'ly'
elseif s == 'nj' then
return 'ny'
elseif s == 'ŋ' then
return 'ng'
elseif s == 'sj' then
return 'sy'
elseif s == 'ʃ' then
return 'sh'
elseif s == 'tj' then
return 'ty'
elseif s == 'tʃ' then
return 'ch'
elseif s == 'θ' then
return 'th'
elseif s == 'θj' then
return 'thy'
elseif s == 'zj' then
return 'zy'
elseif s == 'ʒ' then
return 'zh'
elseif s == 'ɑː' then
return 'ah'
elseif s == 'ɑːr' then
return 'ar'
elseif s == 'ɒ' then
return 'o'
elseif s == 'ɒr' then
return 'orr'
elseif s == 'æ' then
return 'a'
elseif s == 'ær' then
return 'arr'
elseif s == 'aɪ' then
return 'eye'
elseif s == 'aɪər' then
return 'ire'
elseif s == 'aʊ' then
return 'ow'
elseif s == 'aʊər' then
return 'owr'
elseif s == 'ɛ' then
return 'e'
elseif s == 'ɛr' then
return 'err'
elseif s == 'eɪ' then
return 'ay'
elseif s == 'ɛər' then
return 'air'
elseif s == 'ɪ' then
return 'i'
elseif s == 'ɪr' then
return 'irr'
elseif s == 'iː' then
return 'ee'
elseif s == 'ɪər' then
return 'eer'
elseif s == 'ɔː' then
return 'aw'
elseif s == 'ɔːr' then
return 'or'
elseif s == 'ɔɪ' then
return 'oy'
elseif s == 'ɔɪər' then
return 'oir'
elseif s == 'oʊ' then
return 'oh'
elseif s == 'ɔər' then
return 'ohr'
elseif s == 'ʊ' then
return 'uu'
elseif s == 'ʊr' then
return 'uurr'
elseif s == 'uː' then
return 'oo'
elseif s == 'ʊər' then
return 'oor'
elseif s == 'juː' then
return 'ew'
elseif s == 'jʊər' then
return 'ewr'
elseif s == 'ʌ' then
return 'u'
elseif s == 'ʌr' then
return 'urr'
elseif s == 'ɜːr' then
return 'ur'
elseif s == 'i' then
return 'ee'
elseif s == 'u' then
return 'oo'
elseif s == 'ᵻ' then
return 'i'
elseif s == 'ᵿ' then
return 'uu'
elseif s == 'jᵿ' then
return 'yuu'
elseif s == 'x' then
return 'kh'
else
return s
end
end
function p._main(args)
local ret = { '' }
local strNum = {}
local hasPrimStress = false
for i, v in ipairs(args) do
-- Swap stress and consonant after checked vowel
if isChecked(args[i - 2]) and isStr(args[i - 1]) and isCons(v) then
args[i] = args[i - 1]
args[i - 1] = v
end
-- Disable secondary stress following primary stress
if v == 'ˈ' then
hasPrimStress = true
elseif v == '_' or v == ',_' then -- But not in case of a word break
hasPrimStress = false
end
if hasPrimStress and v == 'ˌ' then
args[i] = '.'
end
end
for i, v in ipairs(args) do
if v == '.' then
table.insert(ret, '')
elseif isStr(v) then
if isSeg(args[i - 1]) then
table.insert(ret, '')
end
table.insert(strNum, #ret)
elseif isSeg(v) then
ret[#ret] = ret[#ret] .. toResp(v)
-- Break after checked vowel + segment
if isChecked(args[i - 1]) and isSeg(v) and isSeg(args[i + 1]) then
-- See if there's a vowel down the line
local j = i + 1
while args[j] do
if isVowel(args[j]) then
j = isVowel(args[j])
break
end
j = j + 1
end
if j == true then -- There IS a vowel down the line
table.insert(ret, '')
end
end
-- Break after free vowel
if isVowel(v) and not isChecked(v) and isCons(args[i + 1]) and isSeg(args[i + 2]) then
table.insert(ret, '')
end
-- Break between vowels
if isVowel(v) and not isChecked(v) and isVowel(args[i + 1]) then
table.insert(ret, '')
end
else
-- Process separators
table.insert(ret, v)
table.insert(ret, '')
end
end
for i, v in ipairs(ret) do
v = gsub(v, '([dlnstz]h?)yoo', '%1ew')
v = gsub(v, 'g([ei])', 'gh%1')
v = gsub(v, 'ch$', 'tch')
v = gsub(v, '([eio])s$', '%1ss')
v = gsub(v, '(.)eye(.+)', '%1y%2e')
v = gsub(v, '(.)eye', '%1y')
ret[i] = v
end
-- Capitalize stressed syllables
for i, v in ipairs(strNum) do
ret[v] = mw.ustring.upper(ret[v])
end
return table.concat(ret, '-')
end
function p.main(frame)
local args = getArgs(frame)
return frame:expandTemplate{
title = 'Template:IPAc-en',
args = args
} .. ' ' ..
--[[ frame:expandTemplate{
title = 'Template:Respell',
args = p._main(args)
}
table.concat(p._main(args), '-')]]
p._main(args)
end
return p
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.