Modul:hak-pron

Üdvözlöm, Ön a Modul:hak-pron szó jelentését keresi. A DICTIOUS-ban nem csak a Modul:hak-pron szó összes szótári jelentését megtalálod, hanem megismerheted az etimológiáját, a jellemzőit és azt is, hogyan kell a Modul:hak-pron szót egyes és többes számban mondani. Minden, amit a Modul:hak-pron szóról tudni kell, itt található. A Modul:hak-pron szó meghatározása segít abban, hogy pontosabban és helyesebben fogalmazz, amikor beszélsz vagy írsz. AModul:hak-pron és más szavak definíciójának ismerete gazdagítja a szókincsedet, és több és jobb nyelvi forráshoz juttat.

A modult a Modul:hak-pron/doc lapon tudod dokumentálni

local export = {}
local gsub = mw.ustring.gsub
local sub = mw.ustring.sub
local match = mw.ustring.match
local find = mw.ustring.find
local len = mw.ustring.len

function export.rom_display(text,convtype)
	if type(text) == 'table' then text,convtype = text.args,(text.args or '') end
	local display = ''
	local show = {  = '',  = '', ",  = " }
	local decomp = mw.text.split(gsub(text,'/',' / '),';',true)
	local TableTools = require('Module:table')
	for i = 1,#decomp,1 do
		if match(decomp,'pfs') then
			decomp = gsub(decomp,'pfs=','')
			local pfs_readings = {  = {},  = {} }
			local hrs_readings = {  = {},  = {} }
			local hpy_readings = {  = {},  = {} }
			local ipa_readings = {  = {},  = {} }
			local function display_format(style)
				local label = {  = 'Northern ',  = 'Southern ',  = '' }
				local city = {
						= ']',
						= ']',
						= '] and ]'
					}
				local text = string.format("\n** <small>(''], incl. %s'')</small>", label, city)
				text = text .. "\n*** <small>'']''</small>: <span style=\"font-family: Consolas, monospace;\">" .. table.concat(pfs_readings, ' / ') .. '</span>'
				text = text .. "\n*** <small>'']''</small>: <span style=\"font-family: Consolas, monospace;\">" .. table.concat(hrs_readings, ' / ') .. '</span>'
				text = text .. "\n*** <small>'']''</small>: <span style=\"font-family: Consolas, monospace;\">" .. table.concat(hpy_readings, ' / ') .. '</span>'
				local ipa = '\n*** <small>Sinological ]'
				local span = '</small>: <span class="IPA">/'
				text = text .. ipa
				if style == 'ns' then
					local north = table.concat(ipa_readings, '/, /')
					local south = table.concat(ipa_readings, '/, /')
					if north == south then
						text = text .. span .. north .. '/</span>'
					else
						text = text .. " (''Northern, incl. " .. city .. "'')" .. span .. north .. "/</span>"
						text = text .. ipa .. " (''Southern, incl. " .. city .. "'')" .. span .. south .. "/</span>"
					end
				else
					text = text .. span .. table.concat(ipa_readings, '/, /') .. '/</span>'
				end
				return text
			end
			local function southern(text)
				local function convert(a, b, c)
					local e_a = {  = 'a',  = 'â',  = 'á',  = 'à' }
					return a .. e_a .. c
				end
				text = gsub(text, '()()(̍?)', convert)
				text = gsub(text, '(gi)()(̍?)', convert)
				text = gsub(text, '(h?i)()(̍?)', convert)
				text = gsub(text, '^(i)()(̍?)', convert)
				text = gsub(text, '(i)()(̍?)', convert)
				return text
			end
			local function add(style, reading)
				pfs_readings + 1] = reading
				hrs_readings + 1] = export.hrs(reading, style)
				hpy_readings + 1] = export.pfs_to_hpy(reading)
				ipa_readings + 1] = export.ipa(reading, style)
			end
			
			local ns = true
			for _, reading in ipairs(mw.text.split(decomp, ' / ')) do
				if match(reading,':') then
					local pair = mw.text.split(reading, ':')
					if pair == 'ns' then
						add('n', pair)
						add('s', pair)
					else
						ns = false
						add(pair, pair)
					end
				elseif match(reading,'') or reading ~= southern(reading) then
					ns = false
					add('n', reading)
					add('s', southern(reading))
				else
					add('n', reading)
					add('s', reading)
				end
			end
		
			if convtype == '' then
				if ns then 
					display = display .. display_format('ns')
				else
					if #pfs_readings ~= 0 then display = display .. display_format('n') end
					if #pfs_readings ~= 0 then display = display .. display_format('s') end
				end
			else
				for i, reading in ipairs(pfs_readings) do
					pfs_readings + 1] = pfs_readings
				end
				show = table.concat(TableTools.removeDuplicates(pfs_readings), ' / ')
			end
		end
		if match(decomp,'gd') then
			if convtype == '' then
				display = display .. "\n** <small>('']'')</small>"
				display = display .. "\n*** <small>'']''</small>: <span style=\"font-family: Consolas, monospace;\">" .. string.gsub(string.gsub(decomp,'gd=',''),'()','<sup>%1</sup>') .. '</span>'
				display = display .. '\n*** <small>Sinological ]</small>: <span class="IPA">/' .. export.gd_to_ipa(decomp) .. "/</span>"
			else
				show = gsub(gsub(decomp, 'gd=', ''), '()', '<sup>%1</sup>')
			end
		end
		if match(decomp,'kuching') then
			show = gsub(gsub(decomp, 'kuching=', ''), '()', '<sup>%1</sup>')
		end
	end
	if convtype ~= '' then
		local pfs = " <small>(''], ]'')</small>: <span style=\"font-family: Consolas, monospace;\">" .. show .. '</span>'
		local gd = " <small>(''], ]'')</small>: <span style=\"font-family: Consolas, monospace;\">" .. show .. '</span>'
		if show ~= '' and show ~= '' then
			display = display .. '\n*:' .. pfs .. '\n*:' .. gd
		elseif show ~= '' then
			display = display .. pfs
		elseif show ~= '' then
			display = display .. gd
		end
	end
	return display
end

local function find_tone(text)
	text = mw.ustring.toNFD(text)
	if find(text, '̂') then
		return 1
	elseif find(text, '̀') then
		return 2
	elseif find(text, '́') then
		return 3
	elseif find(text, '̍') then
		return 6
	elseif find(text, '$') then 
		return 5
	else
		return 4
	end
end

function export.ipa(text, dialect)
	local syllables, initial, final, tone, tone_conv = {}, {}, {}, {}, {}
	local ipa = {}
	if type(text) == 'table' then text = text.args end
	text = gsub(gsub(gsub(mw.ustring.lower(text), '%.', ''), '%s+$', ''), '%s+', '-')
	syllables = mw.text.split(text, "-")
	for i, syllable in ipairs(syllables) do
		syllable = gsub(syllable, ",", "")
		syllable = gsub(syllable,'o̍',{='ua̍',='ue̍'})
		syllable = gsub(syllable,'',{='ua',='uá',='uà',='uâ',='uā',='ue',='ué',='uè',='uê',='uē'})
		
		local palatal = false
		initial = match(syllable, '^??h?')
		final = sub(syllable, len(initial) + 1, -1)
		if find(final, '^') then
			palatal = true
		end
		local function add_palatal(text, add_or_not)
			local palatal_initial = {
				 = true,
				 = true,
				 = true,
				 = true
			}
			if add_or_not and palatal_initial then
				return text .. 'i'
			else
				return text
			end
		end
		local initial_ipa = {
			 = 'ɲ',
			 = 'ŋ',
			 = 'pʰ',
			 = 'tʰ',
			 = 'kʰ',
			 = 't͡s',
			 = 't͡ɕ',
			 = 't͡sʰ',
			 = 't͡ɕʰ',
			 = 'ɕ',
			 = 'i'
		}
		initial = initial_ipa, palatal)] or initial
		tone = find_tone(final)
		local final_conv = {
			 = 'a',  = 'e',  = 'i',  = 'o',  = 'u',  = '',
			 = 'a',  = 'e',  = 'i',  = 'o',  = 'u',  = '',
			 = 'a',  = 'e',  = 'i',  = 'o',  = 'u',  = '',
			 = 'n',  = 'n',
			 = '',
			 = 'ɨ',
		}
		final = gsub(final, '', final_conv)
		if initial == 'i' then
			final = (find(final, '^i?$') and '' or 'i') .. final
			initial = dialect == 's' and '(j)' or ''
		end
		final = gsub(final, '()$', '%1̚')
		final = gsub(final, 'ng$', 'ŋ')
		final = final == 'ŋ' and 'ŋ̍' or final
		final = gsub(final, 'er$', 'ə')
		final = gsub(final, '()()(?)', function(first, second, third)
				if third ~= '' then
					first = first .. '̯'
					third = third .. '̯'
				elseif first == 'i' or first == 'u' then
					first = first .. '̯'
				elseif second == 'i' or second == 'u' then
					second = second .. '̯'
				end
			return first .. second .. third end)
	end
	for i, syllable in ipairs(syllables) do
		local tone_ipa = {
			 = '²⁴',
			 = '¹¹',
			 = '³¹',
			 = '⁵⁵',
			 = '²',
			 = '⁵',
		}
		tone_conv = tone_ipa]
		if (tone == 1 and find(tostring(tone), '') and not find(syllable, ",")) or (syllable == 'é' and dialect == 'n' and find(mw.title.getCurrentTitle().text, '仔') and find(text, '-é') and find(tostring(tone), '')) then
			tone_conv = tone_conv .. '⁻¹¹'
		end
		
		ipa = initial .. final .. tone_conv
	end
	return gsub(table.concat(ipa, " "), ",", "")
end

function export.hrs(text, dialect)
	if type(text) == 'table' then text = text.args end
	local syllables = mw.text.split(gsub(mw.ustring.lower(text), ' ', '-'), "-")
	for i, syllable in ipairs(syllables) do
		-- check for commas
		local comma = ''
		if find(syllable, ',') then
			comma = ','
			syllable = sub(syllable, 1, -2)
		end
		-- change consonants
		syllable = gsub(syllable,'',{='b',='d',='g',=dialect == 's' and '(r)i' or 'i'})
		syllable = gsub(syllable,'h',{='p',='t',='k',='z'})
		syllable = gsub(syllable,'zh','c')
		local palatal = {='j',='q',='x',=''}
		syllable = gsub(syllable,'()()', function(a,b) return palatal..b end)
		
		-- find tones
		local marks = {  = '´',  = 'ˇ',  = '`',  = '`' }
		local tone = marks or ''
		
		-- remove tone marks and fix vowels
		syllable = gsub(syllable, 'ṳ', 'ii')
		syllable = gsub(mw.ustring.toNFD(syllable), '', '')
		syllable = gsub(syllable, 'o()', 'u%1')
		
		-- add new tone marks
		syllables = syllable .. tone .. comma
	end
	return table.concat(syllables, " ")
end

function export.pfs_to_hpy(text)
	if type(text) == 'table' then text = text.args end
	local syllables = mw.text.split(gsub(mw.ustring.lower(text), ' ', '-'), "-")
	for i, syllable in ipairs(syllables) do
		if syllable == '...' then
			syllables = syllable
		else
			-- check for commas
			local comma = ''
			if find(syllable, ',') then
				comma = ','
				syllable = sub(syllable, 1, -2)
			end
			-- change consonants
			syllable = gsub(syllable,'',{='b',='d',='g'})
			syllable = gsub(syllable,'h',{='p',='t',='k',='z'})
			syllable = gsub(syllable,'zh','c')
			local palatal = {='j',='q',='x'}
			syllable = gsub(syllable,'()()', function(a,b) return palatal..b end)
			
			-- find tones
			local tone = find_tone(syllable)
			
			-- remove tone marks and fix vowels
			syllable = gsub(syllable, 'ṳ', 'i')
			syllable = gsub(mw.ustring.toNFD(syllable), '', '')
			syllable = gsub(syllable, 'o()', 'u%1')
			syllable = syllable == 'yu' and 'yiu' or syllable
			syllable = gsub(syllable, '()e()', '%1a%2')
			
			-- put everything together
			syllables = syllable .. '<sup>' .. tone .. '</sup>' .. comma
		end
	end
	return table.concat(syllables, " ")
end

function export.gd_to_ipa(text)
	local initial_conv = {
		 = "p",  = "pʰ",  = "m",  = "f",  = "ʋ",
		 = "t",  = "tʰ",  = "n",  = "l", 
		 = "k",  = "kʰ",  = "ŋ",  = "h",
		 = "t͡s",  = "t͡sʰ",  = "s",
		 = "t͡ɕ",  = "t͡ɕʰ",  = "ɕ",
		 = "",
	}
	local final_conv = {
		 = "z̩",  = "i",  = "u",
		 = "a",  = "ia",  = "ua",
		 = "e",  = "ie",  = "ue",
		 = "o",  = "io",  = "uo",
		 = "m̩",  = "n̩",
		 = "aɪ",  = "iaɪ",  = "uaɪ",
		 = "oɪ",
		 = "uɪ",  = "iuɪ",
		 = "au",  = "iau",
		 = "eu",
		 = "iu",
		 = "əm",  = "im",
		 = "am",  = "iam",
		 = "ɛm",
		 = "ən",  = "in",
		 = "an",  = "ian",  = "uan",
		 = "ɛn",  = "iɛn",  = "uɛn",
		 = "ɔn",  = "iɔn",  = "uɔn",
		 = "un",  = "iun",
		 = "aŋ",  = "iaŋ",  = "uaŋ",
		 = "ɔŋ",  = "iɔŋ",  = "uɔŋ",
		 = "ʊŋ",  = "iʊŋ",
		 = "əp̚",  = "ip̚",
		 = "ap̚",  = "iap̚",
		 = "ɛp̚",
		 = "ət̚",  = "it̚",
		 = "at̚",  = "iat̚",  = "uat̚",
		 = "ɛt̚",  = "iɛt̚",  = "uɛt̚",
		 = "ɔt̚",
		 = "ut̚",  = "iut̚",
		 = "ak̚",  = "iak̚",  = "uak̚",
		 = "ɔk̚",  = "iɔk̚",  = "uɔk̚",
		 = "ʊk̚",  = "iʊk̚",
	}
	local tone_conv = {
		 = "⁴⁴",  = "¹¹",
		 = "³¹",
		 = "⁵³",
		 = "¹",  = "⁵",
		 = "⁴⁴⁻³⁵",
		 = "⁵³⁻⁵⁵",
	}
	local palatal = {
		 = 'c',
		 = 'cʰ',
		 = 'ɲ',
		 = 'ç',
	}
	
	if type(text) == 'table' then text = text.args end
	local words = mw.text.split(text, " / ")
	local result = {}
	for _, word in ipairs(words) do
		word = gsub(gsub(gsub(word, 'gd=', ''), '', ''), '%s+$', '')
		local syllables = mw.text.split(word, '%s+')
		local initial, final, tone, ipa = {}, {}, {}, {}
		for i, syllable in ipairs(syllables) do
			initial = match(syllable, "^?g?")
			final = match(sub(syllable, len(initial) + 1, -1), "^*")
			
			if initial == "" and find(final, "^i") then
				error('Syllables starting with "i" need a "y" in front.')
			end
			
			final = gsub(gsub(final, "^yi", "i"), "^y", "i")
			
			if find(initial, "") and final == "i" then
				final = "ii"
			end
			if final == "" then
				final = initial
				initial = ""
			end
			tone = match(syllable, "$")
		end
		for i, syllable in ipairs(syllables) do
			initial = (find(final, "^i") and palatal] or initial_conv]) or error(("Unrecognised initial: \"%s\""):format(initial))
			final = final_conv] or error(("Unrecognised final: \"%s\""):format(final))
			if find(initial, "s") and find(final, "^i") then
				error("Palatal initial needed.")
			end
			if find(initial, "ɕ") and find(final, "^") then
				error("Palatal initial incompatible with rime.")
			end
			if match(tone, "") and match(tone or "", "") then
				tone = tone .. "*"
			end
			if initial == "" and final == "e" and tone == "3" and find(mw.title.getCurrentTitle().text, '仔') then
				initial = match(final or '', '()̚?$') or initial
				initial = find(final or '', 'u$') and 'ʋ' or initial
				initial = find(final or '', '$') and '(ʋ)' or initial
				initial = find(final or '', 'e$') and '(i)' or initial
			end
			tone = tone_conv]
			ipa = initial .. final .. tone
		end
		table.insert(result, table.concat(ipa, " "))
	end
	return table.concat(result, "/, /")
end

return export