Moduł:NKJP

Z Wikisłownika – wolnego słownika wielojęzycznego

Moduł wykorzystywany przez szablon {{NKJP}}.


local p = {}
function p.main( frame )
	local args = frame:getParent().args
	
	-- puste ciągi znaków interpretuj jako brak parametru
	local function hasNilOrEmptyArg( ... )
		local nonEmpty = args.n ~= 0
		for _, a in ipairs( arg ) do
			if args[ a ] == nil or args[ a ] == '' then
				nonEmpty = false
				break
			end
		end
		return not nonEmpty
	end
	
	-- spolszczenie
	if args[ 'autorzy' ] then
		args[ 'authors' ] = args[ 'autorzy' ]
	end
	
	if args[ 'tytuł_pub' ] then
		args[ 'pub_title' ] = args[ 'tytuł_pub' ]
	end
	
	if args[ 'tytuł_art' ] then
		args[ 'article_title' ] = args[ 'tytuł_art' ]
	end
	
	if args[ 'tytuł_mag' ] then
		args[ 'journal_title' ] = args[ 'tytuł_mag' ]
	end
	
	if args[ 'data' ] then
		args[ 'date' ] = args[ 'data' ]
	end
	
	local s = ''
	if not hasNilOrEmptyArg( 'authors' ) then
		s = args[ 'authors' ]
	end
	
	if not hasNilOrEmptyArg( 'article_title', 'journal_title' ) then
		if s ~= '' then
			s = s .. ', '
		end	
		s = s .. '\'\'' .. args[ 'article_title' ] .. '\'\''
		s = s .. ', „' .. args[ 'journal_title' ] .. '”'
	elseif not hasNilOrEmptyArg( 'pub_title' ) then
		if s ~= '' then
			s = s .. ', '
		end	
		s = s .. '\'\'' .. args[ 'pub_title' ] .. '\'\''
	end
	
	if not hasNilOrEmptyArg( 'date' ) then
		if s ~= '' then
			s = s .. ', '
		end	
		s = s .. args[ 'date' ]
	end
	
	-- link to NKJP
	if s ~= '' then
		s = s .. ', '
	end	
	if not hasNilOrEmptyArg( 'hash', 'match_start', 'match_end' ) then
		local nkjp_prefix = 'http://nkjp.uni.lodz.pl/ParagraphMetadata?pid='
		s = s .. '[' .. nkjp_prefix .. args[ 'hash' ] .. '&match_start=' ..
			args[ 'match_start' ] .. '&match_end=' .. args[ 'match_end' ] ..
			'&wynik=1'
	elseif not hasNilOrEmptyArg( 'url' ) then
		s = s .. '[' .. args[ 'url' ]
	elseif not hasNilOrEmptyArg( 'id' ) then
		s = s .. '[http://pelcra.clarin-pl.eu/NKJP/#page/open/context/NKJP/' ..
			args[ 'id' ] .. '/1' 
	else
		s = s .. '[http://nkjp.pl'
	end
	s = s .. ' Narodowy Korpus Języka Polskiego].'
	
	return s
end
return p