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

[перевірена версія][неперевірена версія]
Вилучено вміст Додано вміст
м Відкинуто редагування Andriy.v (обговорення) до зробленого Shmurak
Мітка: Відкіт
Rausch (обговорення | внесок)
Немає опису редагування
Рядок 238:
end
 
--country
if statement.qualifiers.P17 then
for i, qualifier in ipairs( statement.qualifiers.P17 ) do
local parentOptions = context.cloneOptions( options );
local qualifierEntityId = qualifier.datavalue.value.id;
parentOptions[ 'text' ] = getLabel( context, qualifierEntityId, boundaries );
local link = context.formatSnak( parentOptions, qualifier );
 
if p.config.reverseOrder then
result = link .. ', ' .. result;
else
result = result .. ', ' .. link;
end
insertFromSnak( qualifier, entriesToLookupCategory )
hasAdditionalQualifiers = true;
end
end
end
 
if statement.mainsnak and
statement.mainsnak.datavalue and
statement.mainsnak.datavalue.value and
statement.mainsnak.datavalue.value.id
then
local entityId = statement.mainsnak.datavalue.value.id;
local parentSnaks = { statement.mainsnak };
local parentEntityIds = { entityId };
 
if actualDateBoundariesProperties ~= nil then
local filterCapitalOf = {
[ entityId ] = getParentsInBoundariesSnakImpl( context, entityId, boundaries, {'P1376'} )
};
if boundaries then
local entityOptions = context.cloneOptions( options );
entityOptions['text'] = getLabel( context, entityId, boundaries );
baseResult = context.formatSnak( entityOptions, statement.mainsnak, circumstances );
 
local parentId = entityId;
while parentId ~= nil do
-- get parent
local newParentSnaks = getParentsInBoundariesSnak( context, parentId, boundaries );
if not newParentSnaks or #newParentSnaks == 0 then
parentId = nil;
elseif #newParentSnaks == 1 then
local parentSnak = newParentSnaks[ 1 ];
parentId = parentSnak.datavalue.value.id;
 
table.insert( parentSnaks, parentSnak );
table.insert( parentEntityIds, parentId );
filterCapitalOf[ parentId ] = getParentsInBoundariesSnakImpl( context, parentId, boundaries, { 'P1376' } );
else
parentId = nil;
end
end
 
if not hasAdditionalQualifiers then
for i = 2, #parentSnaks, 1 do
local parentSnak = parentSnaks[ i ];
insertFromSnak( parentSnak, entriesToLookupCategory )
end
end
 
do
local i = #parentSnaks;
while i > 1 do
local prevEntityId = parentEntityIds[ i - 1 ];
-- TODO: use English labels, if there is no current language labels
local prevLabel = getLabel( context, prevEntityId, boundaries ) or '';
local nextEntityId = parentEntityIds[ i ];
local nextLabel = getLabel( context, nextEntityId, boundaries ) or '';
if p.config and p.config.hideSameLabels == true and prevLabel == nextLabel then
-- do not output same label twice (NY, NY, USA)
table.remove( parentSnaks, i );
table.remove( parentEntityIds, i );
elseif p.config and p.config.hidePartOfLabels == true and isPartOfNext( prevLabel, ' ' .. nextLabel ) then
-- do not output same label if it's part of previos
table.remove( parentSnaks, i - 1 );
table.remove( parentEntityIds, i - 1 );
elseif p.config and p.config.hideUnitsForCapitals == true then
-- do not ouput items whose capital is the first item
local capitalId = nil;
for _capitalId, capitalSnaks in pairs( filterCapitalOf ) do
if #capitalSnaks > 0 then
for __, capitalSnak in pairs( capitalSnaks ) do
if parentSnaks[ i ].datavalue.value.id == capitalSnak.datavalue.value.id then
capitalId = _capitalId;
break;
end
end
end
end
if capitalId ~= nil then
if i == #parentSnaks then
i = i - 1;
end
while i > 1 and parentEntityIds[ i ] ~= capitalId do
table.remove( parentSnaks, i );
table.remove( parentEntityIds, i );
i = i - 1;
end
end
end
i = i - 1;
end
end
 
if isSkipTopLevel( parentEntityIds[ #parentEntityIds ] ) then
table.remove( parentSnaks, #parentEntityIds );
table.remove( parentEntityIds, #parentEntityIds );
end
 
if not hasAdditionalQualifiers then
for i = 2, #parentSnaks, 1 do
local parentSnak = parentSnaks[ i ];
 
local parentOptions = context.cloneOptions( options );
parentOptions['text'] = getLabel( context, parentEntityIds[ i ], boundaries );
 
if p.config.reverseOrder then
result = context.formatSnak( parentOptions, parentSnak ) .. ', ' .. result;
else
result = result .. ', ' .. context.formatSnak( parentOptions, parentSnak );
end
end
end
end
end
end
 
if options[ 'thisLocationOnly' ] then
result = baseResult .. context.formatRefs( options, statement );
elseif p.config.reverseOrder then
result = result .. baseResult .. context.formatRefs( options, statement );
else
result = baseResult .. result .. context.formatRefs( options, statement );
end
 
if categorizeByPlace then
if property == 'P19' then result = result .. getCategory( 'P1464', entriesToLookupCategory ); end
if property == 'P20' then result = result .. getCategory( 'P1465', entriesToLookupCategory ); end
if property == 'P119' then result = result .. getCategory( 'P1791', entriesToLookupCategory ); end
end
 
return result;
end
 
function p.formatPlaceWithOnlyCountry( context, options, statement )
local property = mw.ustring.upper( options.property );
 
local actualDateBoundariesProperties = nil;
if property == 'P19' then actualDateBoundariesProperties = {'P569','P570'}; end
if property == 'P20' then actualDateBoundariesProperties = {'P570','P569'}; end
if property == 'P119' then actualDateBoundariesProperties = {'P570','P569'}; end
 
local boundaries = nil;
if actualDateBoundariesProperties ~= nil then
boundaries = getTimeBoundariesFromProperties( context, actualDateBoundariesProperties );
end
 
local entriesToLookupCategory = {};
 
local circumstances = context.getSourcingCircumstances( statement );
local result = '';
local baseResult = context.formatSnak( options, statement.mainsnak, circumstances );
if not baseResult then
return nil;
end
insertFromSnak( statement.mainsnak, entriesToLookupCategory )
 
local hasAdditionalQualifiers = false;
if statement.qualifiers then
--country
if statement.qualifiers.P17 then