Jump to content

Module:Pinyin

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Underbar dk (talk | contribs) at 08:50, 28 February 2014. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}

function p.pinyin(frame)

	local sentence = frame.args[1]
	for i in string.gmatch(sentence, "%S+(%d)") do
--		selectVowel(i, )
	end

	
end

function attachTone(a, n)
	if a == "a" then
		if n == 1 then return "ā" end
		if n == 2 then return "á" end
		if n == 3 then return "ǎ" end
		if n == 4 then return "à" end
		return a
			
	end
	
	if a == "A" then
		if n == 1 then return "Ā" end
		if n == 2 then return "Á" end
		if n == 3 then return "Ǎ" end
		if n == 4 then return "À" end
		return a
			
	end
	
	if a == "e" then
		if n == 1 then return "ē" end
		if n == 2 then return "é" end
		if n == 3 then return "ě" end
		if n == 4 then return "è" end
		return a
			
	end
	
	if a == "E" then
		if n == 1 then return "Ē" end
		if n == 2 then return "É" end
		if n == 3 then return "Ě" end
		if n == 4 then return "È" end
		return a
			
	end
	
	if a == "i" then
		if n == 1 then return "ī" end
		if n == 2 then return "í" end
		if n == 3 then return "ǐ" end
		if n == 4 then return "ì" end
		return a
			
	end
	
	if a == "O" then
		if n == 1 then return "Ō" end
		if n == 2 then return "Ó" end
		if n == 3 then return "Ŏ" end
		if n == 4 then return "Ò" end
		return a
			
	end
	
	if a == "o" then
		if n == 1 then return "ō" end
		if n == 2 then return "ó" end
		if n == 3 then return "ǒ" end
		if n == 4 then return "ò" end
		return a
			
	end
	
	if a == "u" then
		if n == 1 then return "ū" end
		if n == 2 then return "ú" end
		if n == 3 then return "ǔ" end
		if n == 4 then return "ù" end
		return a
			
	end
	
	if (a == "v") or (a == "ü") then
		if n == 1 then return "ǖ" end
		if n == 2 then return "ǘ" end
		if n == 3 then return "ǚ" end
		if n == 4 then return "ǜ" end
		return "ü"
			
	end
	
	return a
	
end




function selectVowel(chara, n)

	local A_in = string.find(chara, "A", -1)
	if A_in > 0 then
		chara[A_in] = attachTone("A", n)
		return chara
	end
	
	local a_in = string.find(chara, "a", -1)
	if a_in > 0 then
		chara[a_in] = attachTone("a", n)
		return chara
	end


	local E_in = string.find(chara, "E", -1)
	if E_in > 0 then
		chara[E_in] = attachTone("E", n)
		return chara
	end
	
	local e_in = string.find(chara, "e", -1)
	if e_in > 0 then
		chara[e_in] = attachTone("e", n)
		return chara
	end
	
	
	local i_in = string.find(chara, "i", -1)
	if i_in > 0 then
		if chara[i_in + 1] == "u" then
			chara[i_in + 1] = attachTone("u", n)
			return chara
		end
		
		chara[i_in] = attachTone("i", n)
		return chara
	end
	
	
	local O_in = string.find(chara, "O", -1)
	if O_in > 0 then
		chara[O_in] = attachTone("O", n)
		return chara
	end
	
	local o_in = string.find(chara, "o", -1)
	if o_in > 0 then
		chara[o_in] = attachTone("o", n)
		return chara
	end
	
	
	local u_in = string.find(chara, "u", -1)
	if u_in > 0 then
		chara[u_in] = attachTone("u", n)
		return chara
	end
	
	
	local v_in = string.find(chara, "v", -1)
	if v_in > 0 then
		chara[v_in] = attachTone("v", n)
		return chara
	end
	
	local umlaut_in = string.find(chara, "ü", -1)
	if umlaut_in > 0 then
		chara[umlaut_in] = attachTone("ü", n)
		return chara
	end
	
end



-- Sample Module demonstrating how to access arguments.
-- For more about the Frame object, see http://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Frame_object
-- Unit tests at Module:BananasArgs/testcases
 
local p = {}
 
-- No arguments, used like: {{#invoke:BananasArgs|hello_world}}
function p.hello_world()
	return "Hello, world!"
end
 
-- One argument, used like: {{#invoke:BananasArgs|hello|Fred}}
function p.hello(frame)
	local name = frame.args[1]
	return "Hello, " .. name .. "!"
end
 
-- Two arguments, used like: {{#invoke:BananasArgs|add|5|3}}
function p.add(frame)
	local num1 = tonumber(frame.args[1])
	local num2 = tonumber(frame.args[2])
	return num1 + num2
end
 
-- Named arguments, used like: {{#invoke:BananasArgs|count_fruit|bananas=5|apples=3}}
function p.count_fruit(frame)
	local num_bananas = frame.args.bananas
	local num_apples = frame.args.apples
	return 'I have ' .. num_bananas .. ' bananas and ' .. num_apples .. ' apples'
end
 
-- Mixing regular args with named args and optional named args
-- Used like: {{#invoke:BananasArgs|has_fruit|Fred|bananas=5|cherries=7}}
function p.has_fruit(frame)
	local name = frame.args[1]
	local num_bananas = frame.args.bananas
	local num_apples = frame.args.apples
	local num_cherries = frame.args.cherries
 
	local result = name .. ' has:'
	if num_bananas then result = result .. ' ' .. num_bananas .. ' bananas' end
	if num_apples then result = result .. ' ' .. num_apples .. ' apples' end
	if num_cherries then result = result .. ' ' .. num_cherries .. ' cherries' end
	return result
end
 
-- Iterating over args, used like: {{#invoke:BananasArgs|custom_fruit|pineapples=10|kiwis=5}}
function p.custom_fruit(frame)
	local result = 'I have:'
	for name, value in pairs(frame.args) do
		result = result .. ' ' .. value .. ' ' .. name
	end
	return result
end
 
-- Iterating over args with separate mandatory args
-- Used like: {{#invoke:BananasArgs|custom_fruit_2|Fred|pineapples=10|kiwis=5}}
function p.custom_fruit_2(frame)
	local name = frame.args[1]
	local result = name .. ' has:'
	for name, value in pairs(frame.args) do
		if name ~= 1 then
			result = result .. ' ' .. value .. ' ' .. name
		end
	end
	return result
end
 
return p