Modul:IPA-cs

Aus Wiktionary, dem freien Wörterbuch

Die Dokumentation für dieses Modul kann unter Modul:IPA-cs/Doku erstellt werden

p = {}

function IsMonosyllabic (word)
	local vocals = "[aeiouy]"
	local vocals_diacritics = {
		{ "á", "a" },
		{ "é", "e" },
		{ "ě", "e" },
		{ "í", "i" },
		{ "ó", "o" },
		{ "ú", "u" },
		{ "ů", "u" },
		{ "ý", "y" }
	}

	local simplified = word
	local number_of_vocals = 0
	
	--for some reason unknown to me the gmatch function counted "á", "ě" etc. as two characters.. so first of all let's get rid of the diacritics
	for _, replacement in ipairs(vocals_diacritics) do
		simplified = mw.ustring.gsub(simplified, replacement[1], replacement[2])
	end

	--let's assume all letters 'r' and 'l' build a syllable unless preceded/followed by a vocal; so to simplify it, remove letters r&l's in those cases
	simplified = mw.ustring.gsub(simplified, "([rl])([aeiouy])", "%2")
	simplified = mw.ustring.gsub(simplified, "([aeiouy])([rl])", "%1")

	for s in mw.ustring.gmatch(simplified, vocals) do
    	number_of_vocals = number_of_vocals + 1
	end
	if number_of_vocals > 1 then
		return false
	else
		local number_of_rls = 0
		for s in mw.ustring.gmatch(simplified, "[rl]") do
    		number_of_rls = number_of_rls + 1
    	end
		if (number_of_vocals + number_of_rls) > 1 then
			return false
		else
			return true
		end	
	end

end

function p.Replace (originalWord)
	local out = mw.ustring.lower(originalWord)
	local consonants_group = "([bcdďfghjklmnpqrřsštťvwxzž])"
	local voiceless_group = "([ptťkfsščp])"
	-- Eher experimentell bestimmte Gruppe, haben Sie keine Angst zu korrigieren
	local voiced_assimilation_group = "([bdďghzž])"

	local replacements = {
		-- Assimilation 
		-- wird nicht direkt in die IPA übertragen (wegen der Eliminierung von Konflikten mit weiteren Regeln)
		-- stimmhaft, stimmlos -> stimmlos, stimmhaft
		{"b" .. voiceless_group, "p%1"},
		{"d" .. voiceless_group, "t%1"},
		{"ď" .. voiceless_group, "ť%1"},
		{"g" .. voiceless_group, "k%1"},
		{"([^c])h" .. voiceless_group, "%1ch%2"},
		{"^h" .. voiceless_group, "ch%1"},
		{"v" .. voiceless_group, "f%1"},
		{"z" .. voiceless_group, "s%1"},
		{"ž" .. voiceless_group, "š%1"},
		{"bch", "pch"},
		{"dch", "tch"},
		{"ďch", "ťch"},
		{"gch", "kch"},
		{"vch", "fch"},
		{"zch", "sch"},
		{"žch", "šch"},
		-- stimmlos, stimmhaft -> stimmhaft, stimmhaft
		{"p" .. voiced_assimilation_group, "b%1"},
		{"t" .. voiced_assimilation_group, "d%1"},
		{"ť" .. voiced_assimilation_group, "ď%1"},
		{"k" .. voiced_assimilation_group, "ɡ%1"},
		{"ch" .. voiced_assimilation_group, "h%1"},
		{"f" .. voiced_assimilation_group, "v%1"},
		{"s" .. voiced_assimilation_group, "z%1"},
		{"š" .. voiced_assimilation_group, "ž%1"},
		-- Wortende
		{"b$", "p"},
		{"b ", "p "},
		{"d$", "t"},
		{"d ", "t "},
		{"ď$", "ť"},
		{"ď ", "ť "},
		{"g$", "k"},
		{"g ", "k "},
		{"([^c])h$", "%1ch"},
		{"([^c])h ", "%1ch "},
		{"v$", "f"},
		{"v ", "f "},
		{"z$", "s"},
		{"z ", "s "},
		{"ž$", "š"},
		{"ž ", "š "},
		
		-- silbenbildendes r (Priorität wegen der Kontextabhängigkeit)
		{consonants_group .. "r" .. consonants_group, "%1r̩%2"},
		{consonants_group .. "r$", "%1r̩"},
		{consonants_group .. "r ", "%1r̩ "},
	   
		-- silbenbildendes l (Priorität wegen der Kontextabhängigkeit)
		{consonants_group .. "l" .. consonants_group, "%1l̩%2"},
		{consonants_group .. "l$", "%1l̩"},
		{consonants_group .. "l ", "%1l̩ "},
		
		-- silbenbildendes m (geringere Priorität als r, l weil es nicht so häufig vorkommt)
		{consonants_group .. "m" .. consonants_group, "%1m̩%2"},
		{consonants_group .. "m$", "%1m̩"},
		{consonants_group .. "m ", "%1m̩ "},
									  
		-- stimmhaftes und stimmloses ř (Priorität wegen der Kontextabhängigkeit)
		{voiceless_group .. "ř", "%1r̝̊"},
		{"ř" .. voiceless_group, "r̝̊%1"},
		{"chř", "chr̝̊"},
		{"řch", "r̝̊ch"},
		{"ř$", "r̝̊"},
		{"ř ", "r̝̊ "},
		{"ř", "r̝"},
	
		--  Doppellaute
		{"au", "aʊ̯"},
		{"eu", "ɛʊ̯"},
		{"ou", "ɔʊ̯"},	
	
		-- Vokalgruppen <ia, ie, ii, io, iu> in Fremdwörtern
		{"ia", "ɪja̯"},
		{"ie", "ɪjɛ"},
		{"ii", "ɪjɪ̯"},
		{"io", "ɪjo̯"},
		{"iu", "ɪju̯"},
		
		-- vorrangige Ersetzung von x, ch, c a ts (zur Einschränkung von Konflikten)
		{"ex", "eɡz"},
		{"x", "ks"},
		{"ch", "x"},
		{"c", "t͡s"},
		{"ts", "t͡s"},
	
		-- di, ti, ni (í unberücksichtigt wegen Konflikten mit den Regeln für i)
		{"di", "ɟɪ"},
		{"dí", "ɟí"},
		{"ti", "cɪ"},
		{"tí", "cí"},
		{"ni", "ɲɪ"},
		{"ní", "ɲí"},
	
		-- ě
		{"bě", "bjɛ"},
		{"dě", "ɟɛ"},	
		{"fě", "fjɛ"},
		{"mě", "mɲɛ"},
		{"ně", "ɲɛ"},	
		{"pě", "pjɛ"},
		{"tě", "cɛ"},	
		{"vě", "vjɛ"},
	
		-- Vokale
		{"a", "a"},
		{"á", "aː"},
		{"e", "ɛ"},
		{"é", "ɛː"},
		{"i", "ɪ"},	
		{"y", "ɪ"},
		{"í", "iː"},	
		{"ý", "iː"},
		{"o", "ɔ"},
		{"ó", "ɔː"},
		{"u", "ʊ"},	
		{"ú", "uː"},	
		{"ů", "uː"},
	
		--Konsonanten
		{"dž", "d͡ʒ"},
		{"čb", "d͡ʒb"},
		{"š", "ʃ"},	
		{"ž", "ʒ"},
		{"ň", "ɲ"},
		{"ť", "c"},
		{"ď", "ɟ"},
		{"g", "ɡ"},
		{"h", "ɦ"},
		{"dz", "d͡z"},
		{"č", "t͡ʃ"},
	
		--[ɱ] wird realisiert bei /m/ vor /f/ a /v/ (zB. im Wort tramvaj)
		{"mf", "ɱf"},	
		{"mv", "ɱv"},
		
		--[ŋ] wird realisiert bei /n/ vor /k/ a /g/ (zB. im Wort banka)
		{"nk", "ŋk"},	
		{"ng", "ŋɡ"},
	}
	
	for _, replacement in ipairs(replacements) do
		out = mw.ustring.gsub(out, replacement[1], replacement[2])
	end
	if not IsMonosyllabic (mw.ustring.lower(originalWord)) then
		out = "ˈ" .. out
	end
	return out
end

function p.print (frame)
	if frame.args[1] and frame.args[1] ~= "" then
		return p.Replace (frame.args[1])
	elseif not frame.args[1] then
		return "FEHLER: Keine Eingabe"
	elseif frame.args[1] == "" then
		return "FEHLER: Leere Eingabe"		
	else
		return "FEHLER: unbekannter Fehler"
	end
end



return p