Module:Hoo-ipac

Documentation for this module may be created at Module:Hoo-ipac/doc

--based on similar modules made by User:Sware, see below for more information and reference.

local sub = mw.ustring.sub
local find = mw.ustring.find
local gmatch = mw.ustring.gmatch
local gsub = mw.ustring.gsub
local match = mw.ustring.match
local u = mw.ustring.char
local split = mw.text.split
local gsplit = mw.text.gsplit

local lang = require("Module:languages").getByCode("hoo")
local m_table = require("Module:table")
local m_IPA = require("Module:IPA")

local export = {}

local cons = "[pbfmʋstdnlkgɡŋʁɬjhχ]"
local vow = "[ɑaiuɛeɔoʉɟə]"

local function same(foo, bar)
	foo, bar = mw.ustring.toNFD(foo), mw.ustring.toNFD(bar) -- decompose diacritics
	foo, bar = match(foo, "^."), match(bar, "^.") -- sort out the letter
	return foo == bar and true or false
end

local translit = {
	{"æ", "ææ"}, {"v", "ʋ"}, {"ng", "ŋ"}, {"nk", "ŋk"}, {"nk", "ŋk"}, {"r", "ʁ"}, {"ł", "ɬ"},
	{"aa", "ɑː"}, {"ii", "iː"}, {"uu", "uː"}, {"åå", "oː"}, {"ææ", "eː"},
	{"au", "aʊ"}, {"ai", "aj"}, {"åʁ", "ɟʁ"}, {"å", "u"}, {"æ", "i"}, {"eʁ", "ɛʁ"}, {"e", "ə"}, {"o", "ɔ"}, {"əɛ", "eː"}, {"əə", "eː"}, {"ɔɔ", "oː"}
}

local rules = {
	{"ɟʁ" ..vow, function(v1) return "uʁ"..v1 end}, {"uʁɟʁ", "uʁ"}, {"ɟʁ", "ɔʁ"}, --dealing with å
	{"g(" ..vow..")", function(v1) return "ɡ"..v1 end}, {"g", "ɣ"}, {"ɣɣ", "ɡː"},
	{"([ptk])("..vow..")", function(c,v) return c.."ʰ"..v end},
    {"(" .. cons .. ")(" .. cons .. ")", function(c1,c2) return same(c1,c2) and c1 .. "ː" or c1 .. c2 end}, --gemination, should go at end
    {"(" .. cons .. ")(" .. cons .. ")(" .. cons .. ")", function(c1,c2,c3) return same(c2,c3) and c1..c2.. "ː" or c1 .. c2 .. c3 end}, --gemination, should go at end
    {"([fʋsnlŋʁɬχ])([pbtdkg])("..cons..")", function(c1,c2,c3) return c1..c2.."⁽ᵊ⁾"..c3 end},
	{"([fʋsnlŋʁɬχ])("..cons..")$", function(c1,c2) return c1..c2.."⁽ᵊ⁾" end},
}

local postrules = {
	{"ːʰ", "ː"},
	{"("..cons..")("..cons..")ʰ", function(c1,c2) return c1..c2.."" end},
}

local makrules = {
	{"ʰ", ""}, {"eː", "ɛː"}, {"oː", "ɔː"}, {"ːʰ", "ː"}, {"ɑ", "a"},
	{"ʁ([ptkfsnɬə])", function(c1) return "χ"..c1 end},
}

local kalrules = {
	{"ɡ", "ɣ"}, {"ɣː", "ɡː"}, {"u", "ʉ"},
	{"i", "ɪ"}, {"ɪː", "iː"}, 
	{"("..cons..")ː(" ..vow..")", function(c1, v1) return c1.."q"..v1 end}, 
	{"("..vow..")ː", function(v1) return v1.."q" end}, {"ː", ""}, {"q", "ː"}
}

function export.crux(term, dialect)
	term = mw.ustring.lower(term)
	
	for _, rule in ipairs(translit) do
		term = gsub(term, rule[1], rule[2])
	end
	
	for _, rule in ipairs(rules) do
		term = gsub(term, rule[1], rule[2])
	end
	
	if dialect == "mak" then
		for _, rule in ipairs(makrules) do
			term = gsub(term, rule[1], rule[2])
		end
	elseif dialect == "kal" then
		for _, rule in ipairs(kalrules) do
			term = gsub(term, rule[1], rule[2])
		end
	else
		for _, rule in ipairs(postrules) do
			term = gsub(term, rule[1], rule[2])
		end
	end
	
	term = gsub(term, "·", ".")
	term = gsub(term, "%.%.", ".")
	
	return term
end

function separate_word(term, dialect)
	local result = {}
	
	
	for word in gsplit(term, " ") do
		table.insert(result, export.crux(word, dialect))
	end
	
	return table.concat(result, " ")
end

function export.show(frame)
	local parent_args = frame:getParent().args
	local params = {
		[1] = { default = mw.title.getCurrentTitle().nsText == 'Template' and "hoofnisk ull" or mw.title.getCurrentTitle().text },
	}
	local args = require("Module:parameters").process(parent_args, params)
	local term = args[1]

	local IPA_args = {}
	local mIPA_args = {}
	local kIPA_args = {}
	local phonetic = separate_word(term, "standard")
	local mphonetic = separate_word(term, "mak")
	local kphonetic = separate_word(term, "kal")
	table.insert(IPA_args, {pron = '[' .. phonetic .. ']'})
	table.insert(mIPA_args, {pron = '[' .. mphonetic .. ']'})
	table.insert(kIPA_args, {pron = '[' .. kphonetic .. ']'})

	return 
		"* (''Standard'') " .. m_IPA.format_IPA_full({lang = lang, items = IPA_args})..
		"\n* (''Maaknuna'') " .. m_IPA.format_IPA_full({lang = lang, items = mIPA_args})..
		"\n* (''Kalaalann'') " .. m_IPA.format_IPA_full({lang = lang, items = kIPA_args})
end

return export

-- THE FOLLOWING IS SWARE'S CODE FOR REFERENCE. THIS WILL BE INCLUDED UNTIL MODULE IS FINALIZED.


-- local function laxen(v)
-- 	local otc = {}
-- 	local switch = {["e"] = "ɛ", ["i"] = "ɪ", ["o"] = "ɔ", ["u"] = "ʊ"}
		 

-- local function same(foo, bar)
-- 	foo, bar = mw.ustring.toNFD(foo), mw.ustring.toNFD(bar) -- decompose diacritics
-- 	foo, bar = match(foo, "^."), match(bar, "^.") -- sort out the letter
-- 	return foo == bar and true or false
-- end

-- local first_rules = {
-- 	{"n(·?)([kg])", "ŋ%1%2"}, {"ŋg", "ŋ"}, {"c", "ʧ"}, {"j", "ʤ"}, {"y", "j"}, {"g", "ɡ"}, {"%-", ""},
-- 	-- Long vowels
-- 	{"ā", "aː"},  {"ē", "eː"}, {"ī", "iː"}, {"ō", "oː"}, {"ū", "uː"},
-- 	-- Diphthongs
-- 	{"au", "aʊ"}, {"[uʊ]ji", "wi"}, {"h?u([aeiouɛɪɔʊ])", "w%1"},
-- }

-- local phonetic_rules = {
-- 	{"([ˈˌ])·", "%1"}, {"·([ˈˌ])", "%1"}, {"ˈˌ", "ˌ"}, {"·ˈ´·", "ˈ"},
	
-- 	{"h([" .. front .. "])", "ç%1"}, {"h([" .. back .. "])", "x%1"},
-- 	{"([^nŋ]·)[tk]j", "%1ʧ"}, {"([^nŋ]·)[dɡ]j", "%1ʤ"}, {"r", "ɾ"}, {"k([·ˈ])w", "%1kw"}, {"s([·ˈ])j", "%1sj"},
	
-- 	-- Lax vowels in closed syllables
-- 	{"([·ˈ])(" .. consonants .. "?)(" .. vowels .. "*)(" .. consonants .. ")", function(st,c1,v,c2) return st .. c1 .. laxen(v) .. c2 end},
-- 	{"^(" .. consonants .. "?)(" .. vowels .. "*)(" .. consonants .. ")$", function(c1,v,c2) return c1 .. laxen(v) .. c2 end},
-- 	{"(" .. consonants .. ")(" .. vowels .. "*)(" .. consonants .. consonants .. ")", function(c1,v,c23) return c1 .. laxen(v) .. c23 end},
	
-- 	-- Doubled consonants are reduced to one
-- 	{"(" .. consonants .. ")(·?ˈ?)(" .. consonants .. ")", function(c1, st, c2) return same(c1,c2) and st .. c1 or c1 .. st .. c2 end},
-- 	{"jj", "j"},
	
-- 	-- Diphthongs
-- 	{"(" .. vowels .. ")j$", "%1ɪ"},
	
-- 	{"(·" .. consonants .. ")e$", "%1ə"}, {"a", "ä"},
-- 	{"ʤ", "d͡ʒ"}, {"ʧ", "t͡ʃ"},
-- }

-- local function syllabify(word)
-- 	word = gsub(word, "2", "ˌ")
-- 	word = gsub(word, "(ː)(" .. vowels .. ")", "%1·%2")
-- 	word = gsub(word, "(" .. consonants .. "*)(" .. vowels .. "*)", "%1%2·")
-- 	word = gsub(word, "··", "·"); word = gsub(word, "·$", ""); word = gsub(word, "^·", "")
-- 	word = gsub(word, "·(" .. consonants .. ")(" .. consonants .. ")(" .. vowels .. "*)", "%1·%2%3")
-- 	word = gsub(word, "·(" .. consonants .. ")$", "%1")
-- 	word = gsub(word, "·(" .. consonants .. ")·", "%1·")
-- 	word = gsub(word, "(" .. consonants .. ")·(" .. consonants .. ")([pbmvstdnrɾlkɡŋhxçʤʧçx])", "%1%2·%3")
-- 	word = gsub(word, "a·ʊ", "aʊ·")
	
-- 	local syllables = split(word, "·");
	
-- 	if #syllables ~= 1 then
-- 		for i, syll in ipairs(syllables) do
-- 			if match(word, "´") and not match(syll, "´") then
-- 				break
-- 			elseif match(syll, "´") then
-- 				syll = syll:gsub("´","ˈ")
-- 				return table.concat(syllables, "·")
-- 			elseif match(syll, "ː") then
-- 				table.insert(syllables, i, "ˈ")
-- 				return table.concat(syllables, "·")
-- 			elseif match(word, "ŋ$") or match(syllables[#syllables], "[aeiouɛɪɔʊ][aeiouɛɪɔʊj]") then
-- 				table.insert(syllables, #syllables, "ˈ")
-- 				return table.concat(syllables, "·")
-- 			--[[else
-- 				table.insert(syllables, #syllables-1, "ˈ")
-- 				return ret]]
-- 			end
-- 		end
		
-- 		local ret = table.concat(syllables, "·");
		
-- 		if not match(ret, "ˈ") then
-- 			syllables = split(ret, "·")
-- 			syllables[#syllables - 1] = "ˈ" .. syllables[#syllables - 1]
-- 			ret = table.concat(syllables, "·")
-- 		end
-- 	end
	
-- 	return table.concat(syllables, "·")
-- end

-- function export.crux(term)
-- 	term = mw.ustring.lower(term)
	
-- 	for _, rule in ipairs(first_rules) do
-- 		term = gsub(term, rule[1], rule[2])
-- 	end
	
-- 	term = syllabify(term)
	
-- 	for _, rule in ipairs(phonetic_rules) do
-- 		term = gsub(term, rule[1], rule[2])
-- 	end
	
-- 	term = gsub(term, "·", ".")
-- 	term = gsub(term, "%.%.", ".")
	
-- 	return term
-- end

-- function separate_word(term)
-- 	local result = {}
	
-- 	for word in gsplit(term, " ") do
-- 		table.insert(result, export.crux(word))
-- 	end
	
-- 	return table.concat(result, " ")
-- end

-- function export.show(frame)
-- 	local parent_args = frame:getParent().args
-- 	local params = {
-- 		[1] = { default = mw.title.getCurrentTitle().nsText == 'Template' and "ankyu" or mw.title.getCurrentTitle().text },
-- 	}
-- 	local args = require("Module:parameters").process(parent_args, params)
-- 	local term = args[1]

-- 	local IPA_args = {}
-- 	local phonetic = separate_word(term)
-- 	table.insert(IPA_args, {pron = '[' .. phonetic .. ']'})

-- 	return "* " .. m_IPA.format_IPA_full({lang = lang, items = IPA_args})
-- end

-- return export