Uwaga
Serwis Wedariusz jest portalem tematycznym prowadzonym przez Grupę Wedamedia. Aby zostać wedapedystą, czyli Użytkownikiem z prawem do tworzenia i edycji artykułów, wystarczy zarejestrować się na witrynie poprzez złożenie wniosku o utworzenie konta, co można zrobić tutaj. Liczymy na Waszą pomoc oraz wsparcie merytoryczne przy rozwoju także naszych innych serwisów tematycznych.

Moduł:odmiana-rzeczownik-esperanto

Z Wedariusz, słownik
Przejdź do nawigacji Przejdź do wyszukiwania

Dokumentacja dla tego modułu może zostać utworzona pod nazwą Moduł:odmiana-rzeczownik-esperanto/opis

local w = {}
local forms = {}
local globalFrame = {}

local kat_prefix = 'Odmiana EO test - '
local kat_ok = kat_prefix .. 'jest ok'
local kat_useless = kat_prefix .. 'niepotrzebnie wpisana odmiana'
local kat_wrong = kat_prefix .. 'źle wpisana odmiana'
local kat_missing = kat_prefix .. 'brakuje odmiany'
local kat_missing_j = kat_prefix .. 'brakuje blp w haśle z liczbą mnogą'
local kat_wrong_lp = kat_prefix .. 'wpisana odmiana lp dla blp'
local kat_wrong_word = kat_prefix .. 'czy deklinacja'
local kat_bot = kat_prefix .. 'dla bota'
local exceptions = { 'kaj' }
local withoutOAending = { 'ci' , 'ĝi' , 'ili' , 'li' , 'mi' , 'ni' , 'ŝi', 'vi' }

function w.header( is_blp, is_blm )
	local tr = mw.html.create( 'tr' )
	local th1 = mw.html.create( 'th' )
	local th2 = mw.html.create( 'th' )
	local th3 = mw.html.create( 'th' )
	th1:wikitext( ' ' )
	tr:node( th1 )
	if ( not is_blp ) then
		th2:cssText('font-weight:normal'):wikitext( '[[ununombro#eo|ununombro]]' )
		tr:node( th2 )
	end
	th3:cssText('font-weight:normal'):wikitext( '[[multenombro#eo|multenombro]]' )
	if ( is_blm ) then
		th3:wikitext( ' ([[virtuala#eo|virtuala]])' )
	end
	tr:node( th3 )
	return tr
end

function w.nominativo( is_blp, is_blm )
	local tr = mw.html.create( 'tr' )
	local th = mw.html.create( 'th' )
	local td1 = mw.html.create( 'td' )
	local td2 = mw.html.create( 'td' )
	th:cssText('font-weight:normal'):wikitext( '[[nominativo#eo|nominativo]]' )
	tr:node( th )
	if ( not is_blp ) then
		td1:wikitext( "'''" .. forms[ "nominativo_un" ] .. "'''" )
		tr:node( td1 )
	end
	local mn = ''
	if ( is_blm ) then
		mn = globalFrame:expandTemplate{ title = 'potencjalnie', args = { forms[ "nominativo_mn" ] } }
	else
		mn = forms[ "nominativo_mn" ]
	end
	td2:wikitext( "'''" .. mn .. "'''" )
	tr:node( td2 )
	return tr
end

function w.akuzativo( is_blp, is_blm )
	local tr = mw.html.create( 'tr' )
	local th = mw.html.create( 'th' )
	local td1 = mw.html.create( 'td' )
	local td2 = mw.html.create( 'td' )
	th:cssText('font-weight:normal'):wikitext( '[[akuzativo#eo|akuzativo]]' )
	tr:node( th )
	if ( not is_blp ) then
		td1:wikitext( forms[ "akuzativo_un" ] )
		tr:node( td1 )
	end
	local mn = ''
	if ( is_blm ) then
		mn = globalFrame:expandTemplate{ title = 'potencjalnie', args = { forms[ "akuzativo_mn" ] } }
	else
		mn = forms[ "akuzativo_mn" ]
	end
	td2:wikitext( mn )
	tr:node( td2 )
	return tr
end

function w.tab( is_blp, is_blm, forms )
	local wikitable = mw.html.create( 'table' )
	wikitable:addClass('wikitable'):addClass('odmiana'):cssText('text-align: center')
	wikitable:node(w.header( is_blp, is_blm ))
	wikitable:node(w.nominativo( is_blp, is_blm ))
	wikitable:node(w.akuzativo( is_blp, is_blm ))
	return wikitable
end

function w.fullTable( is_blp, is_blm, forms )
	local navHeadDiv = mw.html.create( 'div' )
	local navFrameDiv = mw.html.create( 'div' )
	local navContentDiv = mw.html.create( 'div' )
	local wikitable = w.tab( is_blp, is_blm, nominativo_un, akuzativo_un, nominativo_mn, akuzativo_mn )
	navFrameDiv:addClass('NavFrame'):addClass('collapse-odmiana'):cssText('display:inline')
	navHeadDiv:addClass('NavHead'):cssText('background:transparent; text-align:left; padding-right:55px; display:inline'):wikitext(' ')
	navFrameDiv:node(navHeadDiv)
	navContentDiv:addClass('NavContent'):cssText('display: inline; text-align: left'):node(wikitable)
	navFrameDiv:node(navContentDiv)
	return tostring( navFrameDiv )
end

function w.endsWith( word, ending )
	local lWord = mw.ustring.lower( word )
	local lEnding = mw.ustring.lower( ending )
	if (lWord == lEnding) then
		return true
	end
	if mw.ustring.len(lWord) > mw.ustring.len(lEnding) then
		if ( mw.ustring.sub( lWord, mw.ustring.len(lWord) - mw.ustring.len(lEnding) + 1 ) == lEnding ) then
			return true
		end
	end
	return false
end

function w.isException( word )
	for __, exception in pairs (exceptions) do
		if mw.ustring.lower( word ) == mw.ustring.lower( exception ) then
			return true
		end
	end
	return false
end

function w.isWithoutOAending( word )
	for __, exception in pairs (withoutOAending) do
		if mw.ustring.lower( word ) == mw.ustring.lower( exception ) then
			return true
		end
	end
	return false
end

function w.withStandardEndings( words )
	for _, word in pairs( words ) do
		if ( not w.isWithoutOAending( word ) ) and ( not w.isException( word ) ) and ( not w.endsWith( word, "a" ) ) and ( not w.endsWith( word, "o" ) )  and ( not w.endsWith( word, "aj" ) )  and ( not w.endsWith( word, "oj" ) ) then
			return false
		end
	end
	return true
end

function w.prepareStandardEndings( words , ending )
	local out = ''
	for _, word in pairs( words ) do
		out = mw.text.trim( out .. ' ' .. word )
		if not w.isException( word ) then
			out = out .. ending
		end
	end
	return mw.text.trim( out )
end

function w.prepareStandardForms( words , is_blp )
	local out = {}
	if ( is_blp ) then
		out[ "nominativo_un" ] = ''
		out[ "akuzativo_un" ] = ''
		out[ "nominativo_mn" ] = w.prepareStandardEndings( words , '' )
		out[ "akuzativo_mn" ] = w.prepareStandardEndings( words , 'n' )
	else
		out[ "nominativo_un" ] = w.prepareStandardEndings( words , '' )
		out[ "akuzativo_un" ] = w.prepareStandardEndings( words , 'n' )
		out[ "nominativo_mn" ] = w.prepareStandardEndings( words , 'j' )
		out[ "akuzativo_mn" ] = w.prepareStandardEndings( words , 'jn' )
	end
	return out
end

function w.is_bl( param1 , param2 , bl )
	if param1 == bl then
		return true
	elseif param2 == bl then
		return true
	end
	return false
end

function w.odmiana( frame )
	globalFrame = frame
	local args = frame:getParent().args
	local currentTitle = mw.title.getCurrentTitle()
	local pagetitle = currentTitle.text

	local old_param_1 = mw.text.trim( args[ "1" ] or '' )
	local old_param_2 = mw.text.trim( args[ "2" ] or '' )
	local old_nominativo_un = mw.text.trim( args[ "nominativo_un" ] or '' )
	local old_akuzativo_un = mw.text.trim( args[ "akuzativo_un" ] or '' )
	local old_nominativo_mn = mw.text.trim( args[ "nominativo_mn" ] or '' )
	local old_akuzativo_mn = mw.text.trim( args[ "akuzativo_mn" ] or '' )
	local is_blp = w.is_bl( old_param_1 , old_param_2 , 'blp' )
	local is_blm = w.is_bl( old_param_1 , old_param_2 , 'blm' )
	if ( old_param_1 ~= '' ) and ( old_param_1 ~= 'blp' ) and ( old_param_1 ~= 'blm' ) then
		pagetitle = old_param_1
	end

	local words = mw.text.split( pagetitle, " ", true )	
	local standard = w.withStandardEndings( words )
	local kat = kat_ok
	if is_blp and ( ( old_nominativo_un ~= '' ) or ( old_akuzativo_un ~= '' ) ) then
		kat = kat_wrong_blp
	end
	if standard then
		forms = w.prepareStandardForms( words , is_blp )
		if ( old_nominativo_un ~= '' ) or ( old_akuzativo_un ~= '' ) or ( old_nominativo_mn ~= '' ) or ( old_akuzativo_mn ~= '' ) or ( old_param_1 ~= 'blp' and old_param_1 ~= 'blm' and old_param_1 ~= '' and old_param_1 ~= nil ) then
			kat = kat_bot
		end
		if (#words == 1) then
			if ( old_nominativo_un ~= '' ) or ( old_akuzativo_un ~= '' ) or ( old_nominativo_mn ~= '' ) or ( old_akuzativo_mn ~= '' ) then
				kat = kat_useless
			end
		else
			if ( old_nominativo_un ~= forms.nominativo_un ) or ( old_akuzativo_un ~= forms.akuzativo_un ) or ( old_nominativo_mn ~= forms.nominativo_mn ) or ( old_akuzativo_mn ~= forms.akuzativo_mn ) then
				-- kat = kat_wrong
			end
		end
		if w.endsWith( pagetitle, "j" ) and not is_blp then
			kat = kat_missing_j
		end
	else
		if ( old_nominativo_un == '' and not is_blp ) or ( old_akuzativo_un == '' and not is_blp ) or ( old_nominativo_mn == '' ) or ( old_akuzativo_mn == '' ) then
			kat = kat_missing
		end
		if (#words == 1) then
			kat = kat_wrong_word
		end
		forms[ "nominativo_un" ] = old_nominativo_un
		forms[ "akuzativo_un" ] = old_akuzativo_un
		forms[ "nominativo_mn" ] = old_nominativo_mn
		forms[ "akuzativo_mn" ] = old_akuzativo_mn
	end

	local category = ''
	if currentTitle.namespace == 0 and ( kat ~= kat_ok ) then
		category = '[[Kategoria:' .. kat .. ']]'
	end
	
	-- odblokowanie zapełnia lub opróżnia kategorię błędów
	local bl = category
	-- local bl = ''
	
	if ( is_blp ) then
		bl = frame:expandTemplate{ title = 'blp' } .. ', ' .. bl
	end
	if ( is_blm ) then
		bl = frame:expandTemplate{ title = 'blm' } .. ', ' .. bl
	end

	return bl .. w.fullTable( is_blp , is_blm )
end

return w