コンテンツにスキップ

モジュール:ml-IPA

出典: フリー多機能辞典『ウィクショナリー日本語版(Wiktionary)』

このモジュールについての説明文ページを モジュール:ml-IPA/doc に作成できます

local export = {}

local consonants = {
	['ക']='k', ['ഖ']='kʰ', ['ഗ'] = 'ɡ', ['ഘ'] ='ɡʱ', ['ങ']='ŋ',
	['ച']='t͡ʃ', ['ഛ']='t͡ʃʰ', ['ജ']='d͡ʒ', ['ഝ']='d͡ʒʱ', ['ഞ']='ɲ',
	['ട']='ʈ', ['ഠ']='ʈʰ', ['ഡ']='ɖ', ['ഢ']='ɖʱ', ['ണ']='ɳ',
	['ത']='t̪', ['ഥ']='t̪ʰ', ['ദ']='d̪', ['ധ']='d̪ʱ', ['ന']='n̪', 
	['പ']='p', ['ഫ']='f', ['ബ']='b', ['ഭ']='bʱ',  ['മ']='m',
	['യ']='j', ['ര']='ɾ', ['ല']='l', ['വ']='ʋ', 
	['ശ']='ʃ', ['ഷ']='ʂ', ['സ']='s', ['ഹ']='h', 
	['ള']='ɭ', ['ഴ']='ɻ', ['റ']='r', ['ഩ']='n', ['ഺ'] ='t'
	
}

local vowel_diacritics = {
	['ാ']= 'aː', ['ി']='i', ['ീ']='iː', ['ു']='u', ['ൂ']='uː', ['ൃ'] = 'ri', ['ൄ'] = 'riː', ['ൢ'] = 'li', ['ൣ'] = 'liː',
	['െ']='e', ['േ']='eː', ['ൈ']='ɐi̯', ['ൊ']='o', ['ോ']='oː', ['ൌ']='ɐu̯', ['ൗ']='ɐu̯',
	['്']='',	--virama, supresses the inherent vowel "a"
	[''] = 'ɐ'	-- no diacritic
}

local other = {
	-- independent vowels
	['അ']='ɐ', ['ആ']='aː', ['ഇ']='i', ['ഈ']='iː', ['ഉ']='u', ['ഊ']='uː', ['ഋ'] = 'ri', ['ൠ'] = 'riː', ['ഌ'] = 'li', ['ൡ'] = 'liː',
	['എ']='e', ['ഏ']='eː', ['ഐ']='ai̯', ['ഒ']='o', ['ഓ']='oː', ['ഔ']='au̯',
	-- Other symbols
	['ം']='m̃', ['ഃ']='h',
	['ർ']='r', ['ൎ']='r', ['ൽ']='l', ['ൾ']='ɭ', ['ൻ']='n', ['ൺ']='ɳ', ['ൿ']='k', ['ൔ'] = 'm', ['ൕ'] = 'j', ['ൖ']='ɻ',
	['ഽ']='',
}

local adjust1 = {
	-- Assimilate the anusvara
	['m̃([kɡŋ])']='ŋ%1',
	['m̃([td]͡[ʃʒ])']='ɲ%1', ['m̃(ɲ)']='ɲ%1',
	['m̃([ʈɖɳ])']='ɳ%1',
	['m̃([td]̪)']='n̪%1', ['m̃(n̪)']='n̪%1',
	['m̃([pbmjɾlʋʃʂshɭɻr])']='m%1',
	['m̃([%s%p])']='m%1', ['m̃$']='m',
	['ŋk']='ŋɡ', ['ɲt͡ʃ']='ɲd͡ʒ', ['ɳʈ']='ɳɖ', ['rr']= 'tt', ['n̪t̪']='n̪d̪', ['mp']='mb', ['n̪r']='nd',
	['ɾɾ']='rr', ['rɾ']='rr', ['ɾr']='rr',
	['([ɐaeioui̯u̯jɨ̆]ː?)k([ɐaeioui̯u̯jɨ̆])']='%1ɡ%2',
	['([ɐaeioui̯u̯jɨ̆]ː?)t͡ʃ([ɐaeioui̯u̯jɨ̆])']='%1d͡ʒ%2', 
	['([ɐaeioui̯u̯jɨ̆]ː?)n̪([ɐaeioui̯u̯jɨ̆])']='%1n%2', 
	['([ɐaeioui̯u̯jɨ̆]ː?)ʈ([ɐaeioui̯u̯jɨ̆])']='%1ɖ%2', 
	['([ɐaeioui̯u̯jɨ̆]ː?)t̪([ɐaeioui̯u̯jɨ̆])']='%1d̪%2',
	['([ɐaeioui̯u̯jɨ̆]ː?)p([ɐaeioui̯u̯jɨ̆])']='%1b%2',
	['([pt̪tʈʃkbɖʒmn̪nɳŋʋʂshʰʱ])ɾ']='%1r', 
	['([ptʃkbmʋsh])n̪']='%1n',
	['n̪([mpbkɡjlʋʃs])']='n%1',
}

local adjust2 = {
	['d͡ʒɲ']='ɟɲ',
	['t̪([pbskɡ])']='l%1', ['d̪([pbskɡ])']='l%1',
	['([pt̪tʈkbd̪dɖgmn̪nɳɲŋjlʋʃʒʂshʰʱ])ʋ']='%1ʋʷ',
	['([pbkɡfʋh])l']='%1ɭ',
	['hp']='pp', ['hk']='kk', ['hs']='ss', ['hʃ']='ʃʃ', ['hʂ']='ʂʂ', ['ɲd͡ʒ']='n̠ʲd͡ʒ',
}

function export.to_IPA(text)
	local VIRAMA = '്'
	-- final virama rules
	text = mw.ustring.gsub(text, VIRAMA .. "([%,%.%!%?%:%;]?)$", VIRAMA .. "ɨ̆%1")
	text = mw.ustring.gsub(text, VIRAMA .. "([%,%.%!%?%:%;]?) ", VIRAMA .. "ɨ̆%1 ")

	text = mw.ustring.gsub(
		text,
		'([ക-ഺ])(഻?)([ാ-◌്]?)',
		function(c, n, d)
			return ((consonants[c..n] or consonants[c]) or c) .. vowel_diacritics[d]
		end)

	text = mw.ustring.gsub(text, '[ം-ൡ]', other)

	for k, v in pairs(adjust1) do
		text = mw.ustring.gsub(text, k, v)
	end

	-- If an independent vowel is after another vowel, assume diphthong
	text = mw.ustring.gsub(text, "([ɐaeiou]ː?)•", "%1")
	text = mw.ustring.gsub(text, '.', other)

	-- Phonetic transcription
	text2 = text
	for k, v in pairs(adjust2) do
		text2 = mw.ustring.gsub(text2, k, v)
	end

	return (text == text2 and { text } or { text, text2 })

end

function export.show(frame)

	local args = frame:getParent().args
	local page_title = mw.title.getCurrentTitle().text
	local text = args[1] or page_title
	local qualifier = args['q'] or nil

	local transcriptions = export.to_IPA(text)
	local IPA_text
	if not transcriptions[2] then
		IPA_text = require('Module:IPA').format_IPA_full(
			require('Module:languages').getByCode('ml'),
			{ { pron = '/' .. transcriptions[1] .. '/' } })
	else
		IPA_text = require('Module:IPA').format_IPA_full(
			require('Module:languages').getByCode('ml'),
			{ { pron = '/' .. transcriptions[1] .. '/' }, { pron = '[' .. transcriptions[2] .. ']' } })
	end

	return '* ' .. (qualifier and require("Module:qualifier").format_qualifier{qualifier} .. ' ' or '')
		.. IPA_text

end

return export