Module:ja-acc-multi

Hello, you have come here looking for the meaning of the word Module:ja-acc-multi. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:ja-acc-multi, but we will also tell you about its etymology, its characteristics and you will know how to say Module:ja-acc-multi in singular and plural. Everything you need to know about the word Module:ja-acc-multi you have here. The definition of the word Module:ja-acc-multi will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:ja-acc-multi, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.


local export = {}

local m_str_utils = require("Module:string utilities")
local find = m_str_utils.find
local gmatch = m_str_utils.gmatch
local gsub = m_str_utils.gsub

local range = mw.loadData("Module:ja/data/range")
local e_kana = range.vowels.e
local o_kana = range.vowels.o
local submoraic_kana = range.submoraic_kana
local submoraic_kana_pattern = ""

local function split_kana_to_morae(kana_str)
	local list = {}
	for i in gmatch(kana_str, ".") do
		if #list > 0 and find(i, submoraic_kana_pattern) then
			list = list .. i
		else
			list = i
		end
	end
	return list
end

local function string_to_positive_integer(str)
	if not string.match(str, "^%d+$") then
		error("String " .. str .. " is not a positive integer")
	end
	return tonumber(str)
end

function export.show(frame)
	local params = {
		 = {list = true, require_index = true, disallow_holes = true},
		 = {list = true, require_index = true, disallow_holes = true},
		 = {alias_of = "kana\1_accent", list = true, require_index = true, disallow_holes = true},
		 = {list = true, require_index = true, allow_holes = true}
	}
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	local kanas = args.kana
	local kana_accs = args.kana_accent
	local kana_devs = args.kana_dev
	
	if kanas == nil or #kanas == 0 then
		error("Parameters kana is required")
	end
	if kana_accs == nil or #kana_accs == 0 then
		error("Parameters kana_accent is required")
	end
	
	for i, _ in ipairs(kanas) do
		if not kana_accs then
			error("Parameter kana_accent " .. i .. " is required")
		end
		if kana_accs == "part" or kana_accs == "particle" then
			kana_accs = nil
		else
			kana_accs = string_to_positive_integer(kana_accs)
		end
	end
	
	local kana_stringbuffer = {}
	local highspan = '<span style="border-top:1px solid;position:relative;padding:1px;">'
	local downstepspan = '<span style="position:absolute;top:0;bottom:67%;right:0%;border-right:1px solid;"></span>'
	local spanend = '</span>'
	local high_mora_state = false
	
	table.insert(kana_stringbuffer, '<span lang="ja" class="Jpan">')
	for i, kana in ipairs(kanas) do
		if kana == nil then
			error("Parameters kana is required")
		end
		
		kana = gsub(kana, "(?)", "%1ー")
		kana = gsub(kana, "(?)", "%1ー")
		kana = gsub(kana, "%.", "")
		kana = gsub(kana, "% ", "")
		
		local kana_acc = kana_accs
		
		local morae = split_kana_to_morae(kana)
		if kana_acc ~= nil and kana_acc > #morae then
			error("Accent " .. kana_acc .. " is larger than morae " .. kana)
		end
		
		if kana_acc == nil then
			for _, mora in ipairs(morae) do
				table.insert(kana_stringbuffer, mora)
			end
		elseif kana_acc == 0 then
			if high_mora_state then
				table.insert(kana_stringbuffer, spanend)
			end
			table.insert(kana_stringbuffer, morae)
			table.insert(kana_stringbuffer, highspan)
			for j = 2, #morae do
				table.insert(kana_stringbuffer, morae)
			end
			high_mora_state = true
		else
			if kana_acc == 1 then
				if not high_mora_state then
					table.insert(kana_stringbuffer, highspan)
				end
				table.insert(kana_stringbuffer, morae)
				high_mora_state = false
			else
				if high_mora_state then
					table.insert(kana_stringbuffer, spanend)
				end
				table.insert(kana_stringbuffer, morae)
				table.insert(kana_stringbuffer, highspan)
				high_mora_state = true
			end
			for j = 2, kana_acc do
				table.insert(kana_stringbuffer, morae)
			end
			table.insert(kana_stringbuffer, downstepspan)
			table.insert(kana_stringbuffer, spanend)
			high_mora_state = false
			for j = kana_acc + 1, #morae do
				table.insert(kana_stringbuffer, morae)
			end
		end
	end
	if high_mora_state then
		table.insert(kana_stringbuffer, spanend)
		high_mora_state = false
	end
	table.insert(kana_stringbuffer, spanend)
	
	return table.concat(kana_stringbuffer)
end

return export