Module:User:Theknightwho/mn-common

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


local export = {}
local lang = require("Module:languages").getByCode( "mn" )
local links = require( "Module:links" )
table = require( "Module:table" ).reverse
table = require( "Module:table" ).removeDuplicates

local char = mw.ustring.char
local find = mw.ustring.find
local len = mw.ustring.len
local match = mw.ustring.match
local gmatch = mw.ustring.gmatch
local sub = mw.ustring.sub
local gsub = mw.ustring.gsub
local lower = mw.ustring.lower
local reverse = require( "Module:string" ).reverse

export.FVS1 = char( 0x180B )
export.FVS2 = char( 0x180C )
export.FVS3 = char( 0x180D )
export.FVS4 = char( 0x180F )
export.MVS = char( 0x180E )
export.NNBSP = char( 0x202F )
export.stem_barrier = char( 0xF000 )

local function format_Mongolian_text(text) return "<span class=\"Mong\" lang=\"mn\">" .. text .. "</span>" end

function export.see(frame)
	local params = {
		 = {},
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	local title = args
	local curr_title = mw.title.getCurrentTitle().subpageText
	local content = mw.title.new(title):getContent()
	local senses = {}
	local sense_id = 0
	local j, pos, s, section
	
	if title == curr_title then
		return error("The soft-directed item is the same as the page title.")
	end
	
	if content then
		if not match(content, "==Mongolian==") then
			categories = categories .. "]"
		elseif not match(content, "mn%-IPA") and not match(content, "mn%-see") then
			require("Module:debug").track("mn-see/unidirectional reference to variant")
		elseif not match(content, curr_title) then
			require("Module:debug").track("mn-see/unidirectional reference variant→orthodox")
		end
	end
	
	while true do
		_, j, language_name, s = content:find("%f==%s*(+)%s*==(\n.-)\n==%f", pos)
		
		if j == nil then
			i, j, language_name, s = content:find("%f==%s*(+)%s*==(\n.+)", pos)
		end
		
		if j == nil then
			break
		else
			pos = j - 1
		end
		
		if language_name == "Mongolian" then
			section = s
		end
	end
		
	if not section then
		return ""
	end
	
	section = section:gsub("\n===+Etymology.-(\n==)", "%1")
	
	local text = {}
	
	for sense in section:gmatch("\n# (+)") do
		if not sense:match("rfdef") and not sense:match("defn") then
			sense_id = sense_id + 1
			table.insert(senses, sense)
		end
	end
	table.insert(text, table.concat(senses, "\n# "))
	
	table.insert(text, "</div>")
	
	return frame:preprocess( table.concat(text) )
	
end

function export.ipasee(frame)
	local params = {
		 = {},
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	local title = args
	local curr_title = mw.title.getCurrentTitle().subpageText
	local content = mw.title.new(title):getContent()
	local senses = {}
	local sense_id = 0
	local j, pos, s, section
	
	if title == curr_title then
		return error("The soft-directed item is the same as the page title.")
	end
	
	if content then
		if not match(content, "==Mongolian==") then
			categories = categories .. "]"
		elseif not match(content, "mn%-IPA") and not match(content, "mn%-see") and not match(content, "mn%-IPA-see") then
			require("Module:debug").track("mn-IPA-see/unidirectional reference to variant")
		elseif not match(content, curr_title) then
			require("Module:debug").track("mn-IPA-see/unidirectional reference variant→orthodox")
		end
	end
	
	while true do
		_, j, language_name, s = content:find("%f==%s*(+)%s*==(\n.-)\n==%f", pos)
		
		if j == nil then
			i, j, language_name, s = content:find("%f==%s*(+)%s*==(\n.+)", pos)
		end
		
		if j == nil then
			break
		else
			pos = j - 1
		end
		
		if language_name == "Mongolian" then
			section = s
		end
	end
		
	if not section then
		return ""
	end
	
	section = section:gsub("\n===+Etymology.-(\n==)", "%1")
	
	local text = {}
	
	if section:match("{{mn-IPA\|(+)}}") then
		return frame:expandTemplate{ title = "mn-IPA", args = { section:match("{{mn-IPA\|(+)}}") } }
	else
		return frame:expandTemplate{ title = "mn-IPA", args = { title } }
	end
	
	
end

--Breaks down a string into vowel harmonic segments
function export.vowelharmony( text, params )
	
	if not params then params = {} end
	
	local vh = {}
	local breaks = { 1 }
	
	local switchers = { "ау", "оу", "уу", "иу", "яу", "ёу", "еу", "юу", "уй", "эү", "өү", "үү", "иү", "еү", "юү", "үй", "%s" }
	local switchers2 = { "аа", "оо", "өө", "ээ", "яа", "ёо", "еө", "еэ", "Аа", "Оо", "Өө", "Ээ", "Яа", "Ёо", "Еө", "Еэ" }
	
	for _, v in pairs( switchers ) do
		v = gsub( v, "(.)(.)", "%1" .. char( 0x301 ) .. "?" .. char( 0x300 ) .. "?%2" )
		local c = 0
		while c ~= nil do
			c = find( lower( text ), v, c + 1 )
			if c ~= nil and c ~= 1 then
				table.insert( breaks, c )
			end
		end
	end
	
	if params.bor then
		for _,v in pairs( switchers2 ) do
			if match( text, v .. "$" ) then
				table.insert( breaks, len( text ) - 1 )
			end
		end
	end
	
	table.sort( breaks )
	
	for i, b in ipairs( breaks ) do
		table.insert( vh, { Cyrl = {}, Mong = {} } )
		if i == #breaks then
			vh.substring = sub( text, b, len( text ) )
		else
			vh.substring = sub( text, b, breaks - 1 )
		end
	end
	
	if params.bor then
		for i,s in ipairs( vh ) do
			vh = { Cyrl = {}, Mong = {} }
			local orig_text = s.substring
			s.substring = lower( s.substring )
			if params.bor == "Russian" then s.substring = gsub( s.substring, "у", "ү" ) end
			local substring_nostress = gsub( s.substring, "", "" )
			if match( s.substring, "кило" .. char( 0x301 ) .. "?$" ) then -- irregular
				vh.Cyrl.a = "э"
				vh.location = find( s.substring, "" )
				vh.position = "front"
				vh.quality = "unrounded"
			elseif match( substring_nostress, "у" ) or match( substring_nostress, "уй" ) then
				vh.Cyrl.a = "а"
				vh.location = 1
				vh.position = "back"
				vh.quality = "unrounded"
			elseif match( substring_nostress, "ү" ) or match( substring_nostress, "үй" ) then
				vh.Cyrl.a = "э"
				vh.location = 1
				vh.position = "front"
				vh.quality = "unrounded"
			elseif match( s.substring, "" .. char( 0x301 ) ) then
				vh.Cyrl.a = "а"
				vh.location = find( s.substring, char( 0x301 ) ) - 1
				vh.position = "back"
				vh.quality = "unrounded"
			elseif match( s.substring, "" .. char( 0x301 ) ) then
				vh.Cyrl.a = "о"
				vh.location = find( s.substring, char( 0x301 ) ) - 1
				vh.position = "back"
				vh.quality = "rounded"
			elseif ( match( substring_nostress, "" ) and ( find( substring_nostress, "" ) == find( substring_nostress, "" ) ) ) or match( substring_nostress, "" ) then
				vh.Cyrl.a = "а"
				vh.location = find( substring_nostress, "" )
				vh.position = "back"
				vh.quality = "unrounded"
			elseif match( substring_nostress, "" ) and find( substring_nostress, "" ) == find( substring_nostress, "" ) then
				vh.Cyrl.a = "о"
				vh.location = find( substring_nostress, "" )
				vh.position = "back"
				vh.quality = "rounded"
			elseif ( match( substring_nostress, "" ) and find( substring_nostress, "" ) == find( substring_nostress, "" ) ) or match( substring_nostress, "" ) then
				vh.Cyrl.a = "э"
				vh.location = find( substring_nostress, "" )
				vh.position = "front"
				vh.quality = "unrounded"
			elseif match( substring_nostress, "" ) and find( substring_nostress, "" ) == find( substring_nostress, "ө" ) then
				vh.Cyrl.a = "ө"
				vh.location = find( substring_nostress, "ө" )
				vh.position = "front"
				vh.quality = "rounded"
			else
				vh.Cyrl.a = "э"
				vh.location = find( substring_nostress, "и" ) or 1
				vh.position = "front"
				vh.quality = "unrounded"
			end
			if match( vh.Cyrl.a, "" ) then
				vh.Cyrl.ii = "ы"
				vh.Cyrl.u = "у"
				vh.Mong.a = "ᠠ"
				vh.Mong.u = "ᠤ"
			else
				vh.Cyrl.ii = "ий"
				vh.Cyrl.u = "ү"
				vh.Mong.a = "ᠡ"
				vh.Mong.u = "ᠦ"
			end
			if match( vh.Cyrl.a, "ө" ) then -- ө takes the diphthong эй not өй
				vh.Cyrl.ai = "эй"
			else
				vh.Cyrl.ai = vh.Cyrl.a .. "й"
			end
			vh.Cyrl.aa = vh.Cyrl.a .. vh.Cyrl.a
			vh.Cyrl.uu = vh.Cyrl.u .. vh.Cyrl.u
			vh.substring = orig_text
		end
	else
		local location
		local pattern
		for i,s in ipairs( vh ) do
			local orig = s.substring
			s.substring = reverse( lower( s.substring ) )
			local vowel = match( s.substring, "" )
			location,_ = find( s.substring, "" )
			if vh.Cyrl.a == nil then
				vh.Cyrl.a = "э"
				vh.position = "front"
				vh.quality = "unrounded"
				pattern = "и"
			end
			vh.Cyrl.a = lower( vh.Cyrl.a )
			if vowel == "а" or vowel == "у" or vowel == "я" then
				vh.Cyrl.a = "а"
				vh.position = "back"
				vh.quality = "unrounded"
				pattern = ""
				if match( s.substring, "" ) then vh.violation = true else vh.violation = false end
			elseif vowel == "о" or vowel == "ё" then
				vh.Cyrl.a = "о"
				vh.position = "back"
				vh.quality = "rounded"
				pattern = ""
				if match( s.substring, "" ) then vh.violation = true else vh.violation = false end
			elseif vowel == "э" then
				vh.position = "front"
				if location and sub( s.substring, location-1, location-1 ) == "й" and match( s.substring, "", location+1 ) == "ө" then
						vh.Cyrl.a = "ө"
						vh.quality = "rounded"
						pattern = ""
						if match( s.substring, "" ) then vh.violation = true else vh.violation = false end
				else
					vh.Cyrl.a = "э"
					vh.quality = "unrounded"
					pattern = ""
					if match( s.substring, "" ) then vh.violation = true else vh.violation = false end
				end
			elseif vowel == "ү" then
				vh.Cyrl.a = "э"
				vh.position = "front"
				vh.quality = "unrounded"
				pattern = ""
				if match( s.substring, "" ) then vh.violation = true else vh.violation = false end
			elseif vowel == "ө" then
				vh.Cyrl.a = "ө"
				vh.position = "front"
				vh.quality = "rounded"
				pattern = ""
				if match( s.substring, "" ) then vh.violation = true else vh.violation = false end
			elseif vowel == "е" then
				vh.position = "front"
				if match( s.substring, "ө", location+1 ) then
					vh.Cyrl.a = "ө"
					vh.quality = "rounded"
					pattern = ""
					if match( s.substring, "" ) then vh.violation = true else vh.violation = false end
				else
					vh.Cyrl.a = "э"
					vh.quality = "unrounded"
					pattern = ""
					if match( s.substring, "" ) then vh.violation = true else vh.violation = false end
				end
			elseif vowel == "ю" then
				vh.quality = "unrounded"
				if match( s.substring, "", location+1 ) then
					vh.Cyrl.a = "а"
					vh.position = "back"
					pattern = ""
					if match( s.substring, "" ) then vh.violation = true else vh.violation = false end
				else
					vh.Cyrl.a = "э"
					vh.position = "front"
					pattern = ""
					if match( s.substring, "" ) then vh.violation = true else vh.violation = false end
				end
			end
			location = 0
			local function prev_vowel( n ) return match( s.substring, "", n+1 ) end
			local function prev_hvowel( n ) return match( s.substring, pattern, n+1 ) end
			while prev_vowel( location ) and ( prev_vowel( location ) == prev_hvowel( location ) or prev_vowel( location ) == "и" ) do
				if prev_vowel( location ) == prev_hvowel( location ) then
					location = find( s.substring, pattern, location+1 )
				else -- if и
					local icheck = location+1
					while prev_vowel( icheck ) == "и" do
						icheck = find( s.substring, "и", icheck+1 )
					end
					if prev_vowel( icheck ) and prev_vowel( icheck ) == prev_hvowel( icheck ) then
						location = icheck
					elseif not prev_vowel( icheck ) and vowel == "э" then
						location = icheck
					elseif vowel == "э" and sub( s.substring, icheck-1, icheck-1 ) == "й" then
						location = icheck
					else
						break
					end
				end
			end
			if match( vh.Cyrl.a, "" ) then
				vh.Cyrl.ii = "ы"
				vh.Cyrl.u = "у"
				vh.Mong.a = "ᠠ"
				vh.Mong.u = "ᠤ"
			else
				vh.Cyrl.ii = "ий"
				vh.Cyrl.u = "ү"
				vh.Mong.a = "ᠡ"
				vh.Mong.u = "ᠦ"
			end
			if match( vh.Cyrl.a, "ө" ) then -- ө takes the diphthong эй not өй
				vh.Cyrl.ai = "эй"
			else
				vh.Cyrl.ai = vh.Cyrl.a .. "й"
			end
			vh.Cyrl.aa = vh.Cyrl.a .. vh.Cyrl.a
			vh.Cyrl.uu = vh.Cyrl.u .. vh.Cyrl.u
			s.substring = orig
			vh.location = len( s.substring ) + breaks - location
		end
	end
	
	return vh
end

--Breaks down a string into syllables and returns a table
function export.syllables( text )
	
	local consonant = ""
	local vowel = ""
	local sign = ""
	local iotated = ""
	local punctuation = ""
	local final_clusters = require( "Module:mn/data" ).syll_final_cons
	
	local chars = {}
	for v in gmatch( text, "" ) do -- strip diacritics
		table.insert( chars, v )
	end
	
	text = table.concat( chars ) -- reform text without diacritics
	
	local breaks = {}
	for i,v in pairs( chars ) do
		if i == 1 or match( chars, punctuation ) then -- first letter of word
			table.insert( breaks, i )
		elseif match( chars, export.stem_barrier ) then -- stem barrier (used by inflection templates)
			table.insert( breaks, i )
		elseif i ~= #chars and match( v, consonant ) and match( chars, vowel ) then -- if followed by vowel (i.e. if lone/cluster-final), count backwards until vowel, punctuation/space or start of string is found; if a vowel is found first, then letter must be medial and lone/cluster-final, so is the break; if punctuation/start of string found first, letter is part of word-initial cluster, so is not the break (occurs in loanwords, e.g. трол|лей|бус ("trolleybus"))
			local j = i
			while j > 1 and ( match( chars, consonant ) or match( chars, sign ) ) do
				j = j - 1
				if match( chars, vowel ) then
					table.insert( breaks, i )
				end
			end
		elseif ( match( v, consonant ) or match( v, sign ) ) and ( i == #chars or match( chars, punctuation ) ) then -- if word-final consonant, count backwards until vowel, checking if each cluster is allowed as a word-final cluster; if it is, increase "stable" (the number of stable consonants (and signs) at the end) by one; if a vowel is found before an unstable cluster, the loop ends with no change; if an unstable cluster is found, "stable" will not iterate which will trigger an additional unvoweled syllable break at that consonant (occurs in loanwords, e.g. буд|ди|зм ("Buddhism"), ал|ге|бр ("algebra"))
			local j = i
			local check = { chars }
			local stable = 1
			while j > 1 and j > i - #final_clusters and stable > i - j and ( match( chars, consonant ) or match( chars, sign ) ) do
				j = j - 1
				table.insert( check, chars )
				for k,cluster in ipairs( final_clusters ) do
					if match( table.concat( table.reverse( check ) ), cluster ) then
						stable = stable + 1
						break
					end
				end
				if stable == i - j then
					table.insert( breaks, j )
				end
			end
		elseif match( v, vowel ) and match( chars, sign ) then -- vowel after Ь/Ъ
			table.insert( breaks, i )
		elseif match( v, iotated ) and match( chars, vowel ) then -- iotated ("ya"-type) vowel after a vowel
			table.insert( breaks, i )
		end
	end
	
	breaks = table.removeDuplicates( breaks )		
		
	local syll = {}
	for i,v in ipairs( breaks ) do
		if i == #breaks then
			table.insert( syll, sub( text, v ) )
		else
			table.insert( syll, sub( text, v, breaks - 1 ) )
		end
	end
	
	return syll
end

function export.remove_final_short_vowel( text, params )
	
	if not params then params = {} end
	local vh = export.vowelharmony( text, params )
	local syllables = #export.syllables( text )
	local reduced = text
	local no_fv = false
	if ( syllables > 1 and match( text, "$" ) ) or match( text, "$" ) then
		
		local matches = {
			not params.bor,
			match( text, "$" ),
			match( text, "ба$" ),
			match( text, "бо$" ),
			match( text, "өбө$" ),
			match( text, "бэ$" ),
			match( text, "" .. vh.Cyrl.a .. char( 0x301 ) .. "?" .. char( 0x300 ) .. "?н" .. vh.Cyrl.a .. "$" ),
			match( text, "нга$" ),
			match( text, "нго$" ),
			match( text, "өнгө$" ),
			match( text, "нгэ$" )
		}
		
		for _,v in pairs( matches ) do
			if v then
				reduced = sub( text, 1, len( text ) - 1 )
				no_fv = true
			end
		end
	end
	return reduced, no_fv
end

function export.remove_penultimate_short_vowel( text, params )
	
	if not params then params = {} end
	local vh = export.vowelharmony( text, params )
	local syllables = table.reverse( export.syllables( text ) )
	
	if not params.proper and ( vh.location ~= len( text ) - 1 or vh.violation == false ) and not params.bor then -- exclude proper nouns, loanwords and terms where the deleted vowel determines the vowel harmony
	
		local check
		local syllable_orig
		for i,syllable in ipairs( syllables ) do
			if i ~=1 and i ~= #syllables then
				syllable_orig = syllable
				if match( syllable, export.stem_barrier ) then
					break
				end
				local prev_syllable = gsub( syllables, export.stem_barrier, "" )
				check = ( match( prev_syllable, "*$" ) or "" ) .. syllable .. ( match( syllables, "^*" ) or "" )
				local matches = {
					-- CVC
					match( check, "^ь?$" ), -- not VC
					match( check, "^гь?$" ) and vh.position == "front", -- гV if front vowel only
					-- CCVC
					match( check, "^?ь?ь?$" ),
					match( check, "^?ь?ь?ь?$" ),
				}
				local exclusions = {
					match( check, "ь?в$" ), -- not Vв
					match( check, "ь?и$" ), -- only иC
				}
				for _,v in pairs( matches ) do
					if v then
						syllables = sub( syllable, 1, len( syllable ) - 1 )
						for _,e in pairs( exclusions ) do
							if e then syllables = syllable_orig end
						end
					end
				end
				if syllables ~= syllable_orig then
					break
				end
			end
		end
	end
	return table.concat( table.reverse( syllables ) )
end

function export.concat_forms_in_slot( forms )
	if forms then
		local new_vals = {}
		for _, v in ipairs( forms ) do
			local val = gsub( v.form, "|", "<!>" )
			table.insert( new_vals, val )
		end
		return table.concat( new_vals, "," )
	else
		return nil
	end
end


function export.combine_stem_ending( stem, ending )
	if stem == "?" then
		return "?"
	else
		return stem .. ending
	end
end


function export.generate_form( form, footnotes )
	if type( footnotes ) == "string" then
		footnotes = { footnotes }
	end
	if footnotes then
		return { form = form, footnotes = footnotes }
	else
		return form
	end
end
	
return export