Module:ko-tone

From Wiktionary, the free dictionary
Jump to navigation Jump to search

Generates pitch accent for Korean forms. Currently works only with Busan dialect, and with nouns or noun-like forms.


local p = {}

-- mw.ustring.gsub: replace text

local pagename = mw.title.getCurrentTitle().text
local templatestyles = require('Module:TemplateStyles')('Template:ko-tone/style.css')

local function tag(text, accent)
	return tostring(
		mw.html.create('span')
			:wikitext(text)
			:addClass('ko-acc-' .. accent)
		:done()
	)
end

local w_H = tag(pagename, 'H')

local w_L = pagename

local w_F = tag(pagename, 'F')

local w_R = tag(pagename, 'R')

local w_HL = mw.ustring.gsub(pagename, '^(.)', function(a)
	return tag(a, 'H')
end)

local w_LHH = mw.ustring.gsub(pagename, '^(.)(..?)', function(a, b)
	return a .. tag(b, 'H')
end)

local w_LFF = mw.ustring.gsub(pagename, '^(.)(..?)', function(a, b)
	return a .. tag(b, 'F')
end)

local w_HHL = mw.ustring.gsub(pagename, '^(..)', function(a)
	return tag(a, 'H')
end)

local w_LHL = mw.ustring.gsub(pagename, '^(.)(.)', function(a, b)
	return a .. tag(b, 'H')
end)

local w_LLH = mw.ustring.gsub(pagename, '^(..)(.)', function(a, b)
	return a .. tag(b, 'H')
end)

local w_LLF = mw.ustring.gsub(pagename, '^(..)(.)', function(a, b)
	return a .. tag(b, 'F')
end)

local w_LLLH = mw.ustring.gsub(pagename, '^(...)(.)', function(a, b)
	return a .. tag(b, 'H')
end)

function p.H(frame)
	return  '<b>South [[w:Gyeongsang dialect|Gyeongsang]] ([[Busan]]) [[pitch accent]]:</b> ',
			'<span style="font-size: 13pt;">',
			w_H .. '의 / ',
			w_H .. '에 / ',
			w_L .. tag('까', 'H') .. '지',
			'</span>',
			'<p style="font-size: 9pt; color:#505050"><i>Syllables in red take high pitch. This word takes low pitch only before consonant-initial multisyllabic suffixes.</i></p>',
			templatestyles
end

function p.H_H_reg(frame)
	return  '<b>South [[w:Gyeongsang dialect|Gyeongsang]] ([[Busan]]) [[pitch accent]]:</b> ',
			'<span style="font-size: 13pt;">',
			w_H .. tag('의', 'H') .. ' / ',
			w_H .. tag('에', 'H') .. ' / ',
			w_H .. tag('까', 'H') .. '지',
			'</span>',
			'<p style="font-size: 9pt; color:#505050"><i>Syllables in red take high pitch. This word always takes high pitch and also heightens the next suffixed syllable.</i></p>',
			templatestyles
end

function p.H_H_irreg(frame)
	return  '<b>South [[w:Gyeongsang dialect|Gyeongsang]] ([[Busan]]) [[pitch accent]]:</b> ',
			'<span style="font-size: 13pt;">',
			w_H .. tag('의', 'H') .. ' / ',
			w_H .. '에 / ',
			w_H .. tag('까', 'H') .. '지',
			'</span>',
			'<p style="font-size: 9pt; color:#505050"><i>Syllables in red take high pitch. This word always takes high pitch and also heightens the next suffixed syllable, unless it is 에.</i></p>',
			templatestyles
end

function p.F(frame)
	return  '<b>South [[w:Gyeongsang dialect|Gyeongsang]] ([[Busan]]) [[pitch accent]]:</b> ',
			'<span style="font-size: 13pt;">',
			w_F .. '의 / ',
			w_F .. '에 / ',
			w_F .. '까지',
			'</span>',
			'<p style="font-size: 9pt; color:#505050"><i>Syllables in purple take falling pitch, a [[morae|bimoraic]] sequence of high to low pitch. This word always takes falling pitch, and lowers the pitch of subsequent suffixes.</i></p>',
			templatestyles
end

function p.R(frame)
	return  '<b>South [[w:Gyeongsang dialect|Gyeongsang]] ([[Busan]]) [[pitch accent]]:</b> ',
			'<span style="font-size: 13pt;">',
			w_R .. '의 / ',
			w_R .. '에 / ',
			w_R .. '까지',
			'</span>',
			'<p style="font-size: 9pt; color:#505050"><i>Syllables in blue take rising pitch, a [[morae|bimoraic]] sequence of low to high pitch. This word always takes rising pitch, and lowers the pitch of subsequent suffixes.</i></p>',
			templatestyles
end

function p.L_reg(frame)
	return  '<b>South [[w:Gyeongsang dialect|Gyeongsang]] ([[Busan]]) [[pitch accent]]:</b> ',
			'<span style="font-size: 13pt;">',
			w_L .. tag('의', 'H') .. ' / ',
			w_L .. tag('에', 'H') .. ' / ',
			w_L .. tag('까지', 'H'),
			'</span>',
			'<p style="font-size: 9pt; color:#505050"><i>Syllables in red take high pitch. This word always takes low pitch, and heightens the pitch of two subsequent suffixed syllables.</i></p>',
			templatestyles
end

function p.HH(frame)
	return  '<b>South [[w:Gyeongsang dialect|Gyeongsang]] ([[Busan]]) [[pitch accent]]:</b> ',
			'<span style="font-size: 13pt;">',
			w_H .. '의 / ',
			w_H .. '에 / ',
			w_H .. '까지',
			'</span>',
			'<p style="font-size: 9pt; color:#505050"><i>Syllables in red take high pitch. This word always takes high pitch on both syllables, and lowers the pitch of subsequent suffixes.</i></p>',
			templatestyles
end

function p.HL(frame)
	return  '<b>South [[w:Gyeongsang dialect|Gyeongsang]] ([[Busan]]) [[pitch accent]]:</b> ',
			'<span style="font-size: 13pt;">',
			w_HL .. '의 / ',
			w_HL .. '에 / ',
			w_HL .. '까지',
			'</span>',
			'<p style="font-size: 9pt; color:#505050"><i>Syllables in red take high pitch. This word always takes high pitch only on the first syllable, and lowers the pitch of subsequent suffixes.</i></p>',
			templatestyles
end

function p.LH_reg(frame)
	return  '<b>South [[w:Gyeongsang dialect|Gyeongsang]] ([[Busan]]) [[pitch accent]]:</b> ',
			'<span style="font-size: 13pt;">',
			w_LHH .. '의 / ',
			w_LHH .. '에 / ',
			w_L .. tag('까', 'H') .. '지',
			'</span>',
			'<p style="font-size: 9pt; color:#505050"><i>Syllables in red take high pitch. This word always takes high pitch only on the second syllable, except before consonant-initial multisyllabic suffixes, when it takes full low pitch.</i></p>',
			templatestyles
end

function p.LH_part_reg(frame)
	return  '<b>South [[w:Gyeongsang dialect|Gyeongsang]] ([[Busan]]) [[pitch accent]]:</b> ',
			'<span style="font-size: 13pt;">',
			w_LHH .. '의 / ',
			w_LHH .. '에 / ',
			w_LHH .. tag('까', 'H') .. '지',
			'</span>',
			'<p style="font-size: 9pt; color:#505050"><i>Syllables in red take high pitch. This word always takes high pitch only on the second syllable, and heightens the first syllable of subsequent consonant-initial multisyllabic suffixes.</i></p>',
			templatestyles
end

function p.LH_H(frame)
	return  '<b>South [[w:Gyeongsang dialect|Gyeongsang]] ([[Busan]]) [[pitch accent]]:</b> ',
			'<span style="font-size: 13pt;">',
			w_LHH .. tag('의', 'H') .. ' / ',
			w_LHH .. tag('에', 'H') .. ' / ',
			w_LHH .. tag('까', 'H') .. '지',
			'</span>',
			'<p style="font-size: 9pt; color:#505050"><i>Syllables in red take high pitch. This word always takes high pitch only on the second syllable, and also heightens the subsequent suffixed syllable.</i></p>',
			templatestyles
end

function p.LF(frame)
	return  '<b>South [[w:Gyeongsang dialect|Gyeongsang]] ([[Busan]]) [[pitch accent]]:</b> ',
			'<span style="font-size: 13pt;">',
			w_LFF .. '의 / ',
			w_LFF .. '에 / ',
			w_LFF .. '까지',
			'</span>',
			'<p style="font-size: 9pt; color:#505050"><i>Syllables in purple take falling pitch, a [[morae|bimoraic]] sequence of high to low pitch. This word always takes falling pitch on the second and third syllables, and lowers the pitch of subsequent suffixes.</i></p>',
			templatestyles
end

function p.HHL(frame)
	return  '<b>South [[w:Gyeongsang dialect|Gyeongsang]] ([[Busan]]) [[pitch accent]]:</b> ',
			'<span style="font-size: 13pt;">',
			w_HHL .. '의 / ',
			w_HHL .. '에 / ',
			w_HHL .. '까지',
			'</span>',
			'<p style="font-size: 9pt; color:#505050"><i>Syllables in red take high pitch. This word always takes high pitch on the first two syllables, and lowers the pitch of subsequent suffixes.</i></p>',
			templatestyles
end

function p.HLL(frame)
	return  '<b>South [[w:Gyeongsang dialect|Gyeongsang]] ([[Busan]]) [[pitch accent]]:</b> ',
			'<span style="font-size: 13pt;">',
			w_HL .. '의 / ',
			w_HL .. '에 / ',
			w_HL .. '까지',
			'</span>',
			'<p style="font-size: 9pt; color:#505050"><i>Syllables in red take high pitch. This word always takes high pitch on the first syllable, and lowers the pitch of subsequent suffixes.</i></p>',
			templatestyles
end

function p.LHH(frame)
	return  '<b>South [[w:Gyeongsang dialect|Gyeongsang]] ([[Busan]]) [[pitch accent]]:</b> ',
			'<span style="font-size: 13pt;">',
			w_LHH .. '의 / ',
			w_LHH .. '에 / ',
			w_LHH .. '까지',
			'</span>',
			'<p style="font-size: 9pt; color:#505050"><i>Syllables in red take high pitch. This word always takes high pitch on the second and third syllables, and lowers the pitch of subsequent suffixes.</i></p>',
			templatestyles
end

function p.LHL(frame)
	return  '<b>South [[w:Gyeongsang dialect|Gyeongsang]] ([[Busan]]) [[pitch accent]]:</b> ',
			'<span style="font-size: 13pt;">',
			w_LHL .. '의 / ',
			w_LHL .. '에 / ',
			w_LHL .. '까지',
			'</span>',
			'<p style="font-size: 9pt; color:#505050"><i>Syllables in red take high pitch. This word always takes high pitch on the second syllable, and lowers the pitch of subsequent suffixes.</i></p>',
			templatestyles
end

function p.LLH(frame)
	return  '<b>South [[w:Gyeongsang dialect|Gyeongsang]] ([[Busan]]) [[pitch accent]]:</b> ',
			'<span style="font-size: 13pt;">',
			w_LLH .. '의 / ',
			w_LLH .. '에 / ',
			w_L .. tag('까', 'H') .. '지',
			'</span>',
			'<p style="font-size: 9pt; color:#505050"><i>Syllables in red take high pitch. This word always takes high pitch on the final syllable, except before consonant-initial multisyllabic suffixes, when it takes full low pitch.</i></p>',
			templatestyles
end

function p.LLF(frame)
	return  '<b>South [[w:Gyeongsang dialect|Gyeongsang]] ([[Busan]]) [[pitch accent]]:</b> ',
			'<span style="font-size: 13pt;">',
			w_LLF .. '의 / ',
			w_LLF .. '에 / ',
			w_LLF .. '까지',
			'</span>',
			'<p style="font-size: 9pt; color:#505050"><i>Syllables in purple take falling pitch, a [[morae|bimoraic]] sequence of high to low pitch. This word takes falling pitch on the final syllable, and lowers the pitch of subsequent suffixes.</i></p>',
			templatestyles
end

function p.LHL_phrase(frame)
	return  '<b>South [[w:Gyeongsang dialect|Gyeongsang]] ([[Busan]]) [[pitch accent]]:</b> ',
			'<span style="font-size: 13pt;">',
			w_LHL ..
			'</span>',
			'<p style="font-size: 9pt; color:#505050"><i>The syllable in red takes high pitch.</i></p>',
			templatestyles
end

function p.HHL_isol(frame)
	return  '<b>South [[w:Gyeongsang dialect|Gyeongsang]] ([[Busan]]) [[pitch accent]]</b> <span style="font-size: 9pt; color:#505050">[high-pitch in red]</span>: ',
			'<span style="font-size: 13pt;">',
			w_HHL ..
			'</span>',
			templatestyles
end

function p.LLH_isol(frame)
	return  '<b>South [[w:Gyeongsang dialect|Gyeongsang]] ([[Busan]]) [[pitch accent]]</b> <span style="font-size: 9pt; color:#505050">[high-pitch in red]</span>: ',
			'<span style="font-size: 13pt;">',
			w_LLH ..
			'</span>',
			templatestyles
end

function p.LH_phrase(frame)
	return  '<b>South [[w:Gyeongsang dialect|Gyeongsang]] ([[Busan]]) [[pitch accent]]:</b> ',
			'<span style="font-size: 13pt;">',
			w_LHH ..
			'</span>',
			'<p style="font-size: 9pt; color:#505050"><i>The syllable in red takes high pitch.</i></p>',
			templatestyles
end

function p.HH_phrase(frame)
	return  '<b>South [[w:Gyeongsang dialect|Gyeongsang]] ([[Busan]]) [[pitch accent]]:</b> ',
			'<span style="font-size: 13pt;">',
			w_H ..
			'</span>',
			'<p style="font-size: 9pt; color:#505050"><i>Syllables in red take high pitch.</i></p>',
			templatestyles
end

function p.LLHL(frame)
	return  '<b>South [[w:Gyeongsang dialect|Gyeongsang]] ([[Busan]]) [[pitch accent]]:</b> ',
			'<span style="font-size: 13pt;">',
			w_LLH .. '의 / ',
			w_LLH .. '에 / ',
			w_LLH .. '까지',
			'</span>',
			'<p style="font-size: 9pt; color:#505050"><i>Syllables in red take high pitch. This word always takes high pitch on the third syllable, and lowers the pitch of subsequent suffixes.</i></p>',
			templatestyles
end

function p.LHHL(frame)
	return  '<b>South [[w:Gyeongsang dialect|Gyeongsang]] ([[Busan]]) [[pitch accent]]:</b> ',
			'<span style="font-size: 13pt;">',
			w_LHH .. '의 / ',
			w_LHH .. '에 / ',
			w_LHH .. '까지',
			'</span>',
			'<p style="font-size: 9pt; color:#505050"><i>Syllables in red take high pitch. This word always takes high pitch on the two middle syllables, and lowers the pitch of subsequent suffixes.</i></p>',
			templatestyles
end

function p.LLLHL(frame)
	return  '<b>South [[w:Gyeongsang dialect|Gyeongsang]] ([[Busan]]) [[pitch accent]]:</b> ',
			'<span style="font-size: 13pt;">',
			w_LLLH .. '의 / ',
			w_LLLH .. '에 / ',
			w_LLLH .. '까지',
			'</span>',
			'<p style="font-size: 9pt; color:#505050"><i>Syllables in red take high pitch. This word always takes high pitch on the fourth syllable, and lowers the pitch of subsequent suffixes.</i></p>',
			templatestyles
end

return p