Module:MFA

Vikilug‘at dan olingan
Jump to navigation Jump to search

Ushbu moduli ajtilish qajtaradi qofiya qachon berilga MFA yoki ajtilish MFA qachon berilgan qofiya.

Maʼlumotlarlar: MFA/berlar.

MFA dan qofiya dan toza[tahrirlash]

Toza MFA X-SAMPA rejenere MFA Mos?
dictionary /ˈdɪkʃən(ə)ɹi/ /"dIkS@n(@)r\i/ /ˈdɪkʃən(ə)ɹi/ ha
/ˈdɪkʃənɛɹi/ /"dIkS@nEr\i/ /ˈdɪkʃənɛɹi/ ha
Україна /ukrɑˈjɪnɑ/ /ukrA"jInA/ /ukrɑˈjɪnɑ/ ha
نوروز [næu̯ˈɾoːz] [n{u_^"4o:z] [næu̯ˈɾoːz] ha
[nou̯ˈɾuːz] [nou_^"4u:z] [nou̯ˈɾuːz] ha
[noːˈɾuːz] [no:"4u:z] [noːˈɾuːz] ha
[næu̯ˈɾɵːz] [n{u_^"48:z] [næu̯ˈɾɵːz] ha
新年 [ɕɪn˥˥niɛn˧˥] [s\In_T_TniEn_M_T] [ɕɪn˥˥niɛn˧˥] ha
battleship [ˈbætl̩ʃɪp] ["b{tl=SIp] [ˈbætl̩ʃɪp] ha
báid [bˠɑːdʲ] [b_GA:d_j] [bˠɑːdʲ] ha
Deutsch [dɔʏ̯t͡ʃ] [dOY_^t__S] [dɔʏ̯t͡ʃ] ha
dóigh [d̪ˠoːɟ] [d_d_Go:J\] [d̪ˠoːɟ] ha
murder [ˈmɝdɚ] ["m3`d@`] [ˈmɝdɚ] ha

local export = {}
local m_data = mw.loadData('Module:MFA/data')

local i2x_lookup, x2i_lookup = {}, {}

for ipa_sym, data in pairs(m_data.symbols[1]) do
	if type(data.XSAMPA) == "table" then
		i2x_lookup[ipa_sym] = data.XSAMPA[1]
		for _, xsampa_sym in ipairs(data.XSAMPA) do
			x2i_lookup[xsampa_sym] = ipa_sym
		end
	else
		i2x_lookup[ipa_sym] = data.XSAMPA
		x2i_lookup[data.XSAMPA] = ipa_sym
	end
end

--exception cases where two IPA characters map to one XSAMPA character
x2i_lookup["_T"]="˥"
x2i_lookup["_H"]="˦"
x2i_lookup["_M"]="˧"
x2i_lookup["_L"]="˨"
x2i_lookup["_B"]="˩"

function export.IPA_to_XSAMPA(text)
	local escape = false
    if type(text) == 'table' then -- a frame, extract args
    	text = text.args[1]
    	text = text:gsub('{{=}}','='):gsub('{{!}}','|')
    	text = mw.text.decode(text) -- XXX
    	escape = true
    end

    text = mw.ustring.gsub(text, 'ːː', ':') -- this basically sums up m_data.symbols[2].XSAMPA
    text = mw.ustring.gsub(text, '.', i2x_lookup)

	if escape then
		text = mw.text.nowiki(text)
	end
    return text
end

function export.XSAMPA_to_IPA(text)
	local escape = false
    if type(text) == 'table' then -- a frame, extract args
    	text = text.args[1]
    	text = mw.text.decode(text) -- XXX
    	escape = true
    end
    
    -- XXX: may not be the most efficient, but at least correct.
    local output = {}
    while #text > 0 do
    	local a1, a2, a3, a4 = mw.ustring.sub(text, 1, 1), mw.ustring.sub(text, 1, 2), mw.ustring.sub(text, 1, 3), mw.ustring.sub(text, 1, 4)
    	if x2i_lookup[a4] then
    		table.insert(output, x2i_lookup[a4])
    		text = mw.ustring.sub(text, 5)
    	elseif x2i_lookup[a3] then
    		table.insert(output, x2i_lookup[a3])
    		text = mw.ustring.sub(text, 4)
    	elseif x2i_lookup[a2] then
    		table.insert(output, x2i_lookup[a2])
    		text = mw.ustring.sub(text, 3)
    	elseif x2i_lookup[a1] then
    		table.insert(output, x2i_lookup[a1])
    		text = mw.ustring.sub(text, 2)
    	else -- no match
    		table.insert(output, a1)
    		text = mw.ustring.sub(text, 2)
    	end
    end

	output = table.concat(output)
	if escape then
--		output = mw.text.nowiki(output)
	end

	return output
end

return export