Модуль:Sources: відмінності між версіями

[неперевірена версія][перевірена версія]
Вилучено вміст Додано вміст
Скасування редагування № 18840406 користувача PsichoPuzo (обговорення)
повернуто
Рядок 48:
 
local PREFIX_CITEREF = "CITEREF_";
 
function p.deepcopy(orig)
local orig_type = type(orig)
local copy
if orig_type == 'table' then
copy = {}
for orig_key, orig_value in pairs(orig) do
copy[orig_key] = p.deepcopy( orig_value );
end
else -- number, string, boolean, etc
copy = orig
end
return copy
end
 
local options_arxiv = { separator = '; ', conjunction = '; ', format = function( id ) return '[http://arxiv.org/abs/' .. id .. ' arXiv:' .. id .. ']' end, nolinks = true, preferids = false };
Рядок 788 ⟶ 774:
end
return result;
end
 
function appendMainSnaks( entity, propertyId, result, property, options )
if ( entity.claims and entity.claims[propertyId] ) then
for i, claim in pairs( entity.claims[propertyId] ) do
if ( claim.mainsnak and claim.mainsnak.datavalue ) then
appendImpl( claim.mainsnak.datavalue, result, property, options );
end
end
end
end
 
Рядок 971 ⟶ 947:
 
expandBookSeries( context, data );
end
 
function loadSafe( entityId )
if ( entityId == nil ) then
error('entityId to load is not specified');
end
local status, result = pcall( function() return mw.loadData( 'Module:Source/' .. entityId ) end );
if ( status == true ) then
return true, result;
end
return false, nil;
end
 
Рядок 1001 ⟶ 966:
appendSnaks( bookSeriesEntity.claims, 'P291', data, 'place', {} );
appendSnaks( bookSeriesEntity.claims, 'P236', data, 'issn', {} );
end
 
function populateSourceData( data, sourceId )
local loaded, sourceData = loadSafe( sourceId );
if ( loaded and sourceData ) then
populateSourceDataImpl( data, sourceData );
end
end
 
Рядок 1028 ⟶ 986:
 
return plainData;
end
 
function updateWithRef( reference, src )
-- specified
if ( reference.snaks.p662 ) then
local cid = reference.snaks.p662[0].datavalue.value;
src.code = src.code .. '-cid:' .. cid;
src.title = 'Compound Summary for: CID ' .. cid;
src.url = 'http://pubchem.ncbi.nlm.nih.gov/summary/summary.cgi?cid=' .. cid;
src.publication = { id = 'Q278487', label = 'PubChem' };
end
 
appendSnaks( reference.snaks, 'P364', src, 'lang', {} );
appendSnaks( reference.snaks, 'P958', src, 'part', {} ); -- part
appendSnaks( reference.snaks, 'P357', src, 'title', {} ); -- title
appendSnaks( reference.snaks, 'P854', src, 'url', {} );
appendSnaks( reference.snaks, 'P123', src, 'publisher', {} );
appendSnaks( reference.snaks, 'P304', src, 'page', {} );
appendSnaks( reference.snaks, 'P478', src, 'volume', {} );
return src;
end