Moduł:NKJP: Różnice pomiędzy wersjami

Z Wikisłownika – wolnego słownika wielojęzycznego
[wersja przejrzana][wersja przejrzana]
Usunięta treść Dodana treść
Nie podano opisu zmian
jezeli parametr jest pustym ciagiem znakow, ignoruj go (tak jakby nie podano go wcale, zob. Specjalna:Diff/6192901); BTW args['cokolwiek'] = nil nie dziala
 
Linia 3: Linia 3:
local args = frame:getParent().args
local args = frame:getParent().args
-- puste ciągi znaków interpretuj jako brak parametru
--spolszczenie
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
if args[ 'autorzy' ] then
args[ 'authors' ] = args[ 'autorzy' ]
args[ 'authors' ] = args[ 'autorzy' ]
end
end
if args[ 'tytuł_pub' ] then
if args[ 'tytuł_pub' ] then
args[ 'pub_title' ] = args[ 'tytuł_pub' ]
args[ 'pub_title' ] = args[ 'tytuł_pub' ]
end
end
if args[ 'tytuł_art' ] then
if args[ 'tytuł_art' ] then
args[ 'article_title' ] = args[ 'tytuł_art' ]
args[ 'article_title' ] = args[ 'tytuł_art' ]
Linia 21: Linia 35:
args[ 'date' ] = args[ 'data' ]
args[ 'date' ] = args[ 'data' ]
end
end

local s = ''
local s = ''
if args[ 'authors' ] then
if not hasNilOrEmptyArg( 'authors' ) then
s = args[ 'authors' ]
s = args[ 'authors' ]
end
end
if (args[ 'article_title' ] ~= nil and args[ 'journal_title' ] ~= nil) then
if not hasNilOrEmptyArg( 'article_title', 'journal_title' ) then
if s ~= '' then
if s ~= '' then
s = s .. ', '
s = s .. ', '
Linia 33: Linia 47:
s = s .. '\'\'' .. args[ 'article_title' ] .. '\'\''
s = s .. '\'\'' .. args[ 'article_title' ] .. '\'\''
s = s .. ', „' .. args[ 'journal_title' ] .. '”'
s = s .. ', „' .. args[ 'journal_title' ] .. '”'
elseif (args[ 'pub_title' ] ~= nil) then
elseif not hasNilOrEmptyArg( 'pub_title' ) then
if s ~= '' then
if s ~= '' then
s = s .. ', '
s = s .. ', '
Linia 40: Linia 54:
end
end
if args [ 'date' ] ~= nil and args[ 'date' ] ~= '' then
if not hasNilOrEmptyArg( 'date' ) then
if s ~= '' then
if s ~= '' then
s = s .. ', '
s = s .. ', '
Linia 51: Linia 65:
s = s .. ', '
s = s .. ', '
end
end
if ( args[ 'hash' ] and args[ 'match_start' ] and args[ 'match_end' ] ) then
if not hasNilOrEmptyArg( 'hash', 'match_start', 'match_end' ) then
local nkjp_prefix = 'http://nkjp.uni.lodz.pl/ParagraphMetadata?pid='
local nkjp_prefix = 'http://nkjp.uni.lodz.pl/ParagraphMetadata?pid='
s = s .. '[' .. nkjp_prefix .. args[ 'hash' ] .. '&match_start=' ..
s = s .. '[' .. nkjp_prefix .. args[ 'hash' ] .. '&match_start=' ..
args[ 'match_start' ] .. '&match_end=' .. args[ 'match_end' ] ..
args[ 'match_start' ] .. '&match_end=' .. args[ 'match_end' ] ..
'&wynik=1'
'&wynik=1'
elseif ( args[ 'url' ] ) then
elseif not hasNilOrEmptyArg( 'url' ) then
s = s .. '[' .. args[ 'url' ]
s = s .. '[' .. args[ 'url' ]
elseif ( args[ 'id' ] ) then
elseif not hasNilOrEmptyArg( 'id' ) then
s = s .. '[http://pelcra.clarin-pl.eu/NKJP/#page/open/context/NKJP/' ..
s = s .. '[http://pelcra.clarin-pl.eu/NKJP/#page/open/context/NKJP/' ..
args[ 'id' ] .. '/1'
args[ 'id' ] .. '/1'

Aktualna wersja na dzień 14:52, 26 maj 2018

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