Modulo:Fan-accento
Versione del 3 ott 2018 alle 05:15 di Luigimagi (discussione | contributi) (Creata pagina con "local export = { } local stress = "ˈ" local long = "ː" local acute_or_grave = "[" .. mw.ustring.char(0x300, 0x301) .. "]" local vowels = "æaeɛioɔu" local vowel = "[" .....")
La documentazione per questo modulo può essere creata in Modulo:Fan-accento/man
local export = { }
local stress = "ˈ"
local long = "ː"
local acute_or_grave = "[" .. mw.ustring.char(0x300, 0x301) .. "]"
local vowels = "æaeɛioɔu"
local vowel = "[" .. vowels .. "]"
local not_vowel = "[^" .. vowels .. "]"
local front = "[eɛij]"
local fronted = mw.ustring.char(0x031F)
function export.to_accento(word)
word = mw.ustring.lower(word)
if mw.ustring.find(word,"sč") then
word = mw.ustring.toNFC(word)
--sč at the end of a word is /ʃ/
word = word:gsub("sč","ʃ")
end
if mw.ustring.find(word,"â") then
word = mw.ustring.toNFC(word)
-- â at the end of a word is /æ/
word = word:gsub("â","æ")
end
if mw.ustring.find(word,"ğ") then
word = mw.ustring.toNFC(word)
--ğ at the end of a word is /ʤ/
word = word:gsub("ğ","ʤ")
end
local decomposed = mw.ustring.toNFD(word)
-- Transcriptions must contain an acute or grave, to indicate stress position.
-- This does not handle phrases containing more than one stressed word.
-- Default to penultimate stress rather than throw error?
if not mw.ustring.find(word, acute_or_grave) then
-- Allow monosyllabic unstressed words.
local vowel_count = select(2, word:gsub("[æaeiou]", "%1"))
if vowel_count ~= 1 then
-- Add acute accent on second-to-last vowel.
word = mw.ustring.gsub(word,
"(" .. vowel .. ")(" .. not_vowel .. "*" .. vowel .. not_vowel .. "*)$",
"%1" .. mw.ustring.char(0x301) .. "%2")
else
word=mw.ustring.gsub(word,"(".. vowel ..")(" .. not_vowel .. "*)$",'%1' ..mw.ustring.char(0x301).. '%2')
end
end
local transcription=word
return transcription
end
-- Transcriptions must contain an acute or grave, to indicate stress
-- This does not handle phrases containing more than one stressed word.
-- Default to penultimate stress rather than throw error?
if not mw.ustring.find(decomposed, acute_or_grave) then
-- Allow monosyllabic unstressed words.
--local vowel_count = select(2, decomposed:gsub("[æaeiou]", "%1"))
--if vowel_count ~= 1 then
transcriptio=mw.ustring.sub(decomposed,-1)
if transcriptio == 'a' then
decomposed = mw.ustring.gsub(decomposed,"(" .. vowel .. ")(" .. not_vowel .. "*" .. vowel .. not_vowel .."*)$","%1" .. mw.ustring.char(0x301) .. "%2")
--end
elseif transcriptio =='e' then
decomposed = mw.ustring.gsub(decomposed,"(" .. vowel .. ")(" .. not_vowel .. "*" .. vowel .. not_vowel .."*)$","%1" .. mw.ustring.char(0x301) .. "%2")
elseif transcriptio =='o' then
decomposed = mw.ustring.gsub(decomposed,"(" .. vowel .. ")(" .. not_vowel .. "*" .. vowel .. not_vowel .."*)$","%1" .. mw.ustring.char(0x301) .. "%2")
elseif transcriptio =='i' then
decomposed = mw.ustring.gsub(decomposed,"(" .. vowel .. ")(" .. not_vowel .. "*" .. vowel .. not_vowel .."*)$","%1" .. mw.ustring.char(0x301) .. "%2")
else
decomposed=mw.ustring.gsub(decomposed,"(".. vowel ..")(" .. not_vowel .. "*)$",'%1' ..mw.ustring.char(0x301).. '%2')
end
end
local transcription = decomposed
function export.show(frame)
word=frame:getParent().args[1]
if not word then
word = mw.title.getCurrentTitle().text
end
transcription = "[" .. export.to_accento(word) .. "]"
return transcription
end
return export