सामग्री पर जाएँ

मॉड्यूल:eu-pron/rhymes

विक्षनरी से

इस मॉड्यूल हेतु प्रलेख मॉड्यूल:eu-pron/rhymes/doc पर बनाया जा सकता है

local export = {}
local lang = "eu"
local sc = "Latn"

function export.find_rhyme(word)
	local text    = "#" .. word
	local length  = string.len(text)
	local rhyme   = ""
	local count   = -1
	local syl     = 0
	while count > -length do
		if string.find("̯", string.sub(text,count,count)) then
			count = count - 2
		elseif string.find("aeiou", string.sub(text,count,count)) then
			rhyme = string.sub(text,count,-1)
			syl = syl + 1
			if syl == 2 then
				return rhyme
			end
		end
		count = count - 1
	end
	return rhyme
end

function export.show_rhyme(frame)
	local args = frame:getParent().args
	local title = mw.title.getCurrentTitle().text
	if args.t then
		title = args.t
	end
	local southern = require("Module:eu-pron").IPA(title, "southern_style", false).text
	local northern = require("Module:eu-pron").IPA(title, "northern_style", false).text
	--preparing output
	local r_southern = export.find_rhyme(southern)
	local r_northern = export.find_rhyme(northern)
	
	--counting syllables
	local syl_s = 0
	local syl_n = 0
	southern = string.gsub(southern,"u̯", "w")
	northern = string.gsub(northern,"u̯", "w")
	southern = string.gsub(southern,"i̯", "j")
	northern = string.gsub(northern,"i̯", "j")
	
	for i=1,string.len(southern) do
		if string.find("aeiou", string.sub(southern,i,i)) then
			syl_s = syl_s + 1
		end
	end
	for i=1,string.len(northern) do
		if string.find("aeiou", string.sub(northern,i,i)) then
			syl_n = syl_n + 1
		end
	end
	
	--output
	if r_southern == r_northern then
		if syl_s == syl_n then
			return require("Module:rhymes").show({r_southern, lang="eu", s = syl_s})
		else
			return require("Module:rhymes").show({r_southern, lang="eu", s= tostring(syl_s) .. "," .. tostring(syl_n)})
		end
	else
		return require("Module:rhymes").show({r_southern, r_northern, lang="eu", s1=syl_s, s2=syl_n, q1="Southern", q2="Northern"})
	end
end
return export