יחידה:LocationAndCountry: הבדלים בין גרסאות בדף
מאין תקציר עריכה |
מ גרסה אחת של הדף wikipedia:he:יחידה:LocationAndCountry יובאה |
||
| (9 גרסאות ביניים של 3 משתמשים אינן מוצגות) | |||
| שורה 72: | שורה 72: | ||
end | end | ||
if d1 and d2 then return HeDateUtils.le(d1 | if d1 and d2 then return not HeDateUtils.le(d2, d1, true) | ||
elseif d1 then return true | elseif d1 then return true | ||
elseif d2 then return false end | elseif d2 then return false end | ||
| שורה 96: | שורה 96: | ||
local function findClaimForTimestamp(entityId, propertyId, timestamp) | local function findClaimForTimestamp(entityId, propertyId, timestamp) | ||
local propClaims = findSortedClaimsForProperty(entityId, propertyId) | local propClaims = findSortedClaimsForProperty(entityId, propertyId) | ||
local | local bestClaims = {} | ||
local bestNoTimeClaim | |||
if propClaims then for _,eachPropClaim in ipairs(propClaims) do | if propClaims then for _,eachPropClaim in ipairs(propClaims) do | ||
if hasValueSnak(eachPropClaim) | if hasValueSnak(eachPropClaim) | ||
| שורה 113: | שורה 115: | ||
--before = GregorianDate.convertToGregorianIfInInterval(DateUtils.extractDateFromWikidataSnak(eachPropClaim.qualifiers['P582'][1])) | --before = GregorianDate.convertToGregorianIfInInterval(DateUtils.extractDateFromWikidataSnak(eachPropClaim.qualifiers['P582'][1])) | ||
end | end | ||
end | |||
if timestamp then | if timestamp then | ||
if | if after == nil and before and not HeDateUtils.le(timestamp, before) then | ||
table.insert(bestClaims, eachPropClaim) | |||
elseif after and before and not HeDateUtils.le(timestamp, before) and HeDateUtils.le(timestamp, after) then | elseif after and before and not HeDateUtils.le(timestamp, before) and HeDateUtils.le(timestamp, after) then | ||
table.insert(bestClaims, eachPropClaim) | |||
elseif after and before == nil and HeDateUtils.le(timestamp, after) then | elseif after and before == nil and HeDateUtils.le(timestamp, after) then | ||
table.insert(bestClaims, eachPropClaim) | |||
end | end | ||
end | end | ||
if not | if not bestNoTimeClaim or mw.wikibase.entity.claimRanks['RANK_' .. mw.ustring.upper(bestNoTimeClaim.rank)] < mw.wikibase.entity.claimRanks['RANK_' .. mw.ustring.upper(eachPropClaim.rank)] | ||
or (mw.wikibase.entity.claimRanks['RANK_' .. mw.ustring.upper( | or (mw.wikibase.entity.claimRanks['RANK_' .. mw.ustring.upper(bestNoTimeClaim.rank)] < mw.wikibase.entity.claimRanks['RANK_' .. mw.ustring.upper(eachPropClaim.rank)] and not after) then | ||
bestNoTimeClaim = eachPropClaim | |||
end | end | ||
end | end | ||
| שורה 134: | שורה 135: | ||
end end | end end | ||
if | if #bestClaims==0 and bestNoTimeClaim then | ||
return | return bestNoTimeClaim | ||
end | |||
if #bestClaims==1 then | |||
return bestClaims[1] | |||
elseif (#bestClaims>1) and timestamp then | |||
-- disambig: return null and log it | |||
mw.log('לא ניתן לשייך מיקום ליישות '..entityId .. ' כיוון שקיימות מספר טענות מתאימות שנכונות ל'..timestamp:toString()..'. ניתן לציין מבחין להגדרה חד ערכית.') | |||
return nil | |||
else | else | ||
return nil | return nil | ||
| שורה 149: | שורה 157: | ||
local claims = nil | local claims = nil | ||
local workingEntityId = nil | local workingEntityId = nil | ||
local countryProperty = 'P17' | |||
local administrativeUnitProperty = 'P131' | |||
if type(entity) == 'table' then | if type(entity) == 'table' then | ||
workingEntityId = entity.id | workingEntityId = entity.id | ||
| שורה 173: | שורה 183: | ||
--attempt to also load administrative unit, but only if present as a qualifier | --attempt to also load administrative unit, but only if present as a qualifier | ||
local unitQualifier = actualClaim.qualifiers and actualClaim.qualifiers[ | local unitQualifier = actualClaim.qualifiers and actualClaim.qualifiers[administrativeUnitProperty] and actualClaim.qualifiers[administrativeUnitProperty][1] | ||
if unitQualifier and unitQualifier.snaktype == 'value' then | if unitQualifier and unitQualifier.snaktype == 'value' then | ||
table.insert(locationEntitiesIds, unitQualifier.datavalue.value.id) | table.insert(locationEntitiesIds, unitQualifier.datavalue.value.id) | ||
locationNames[unitQualifier.datavalue.value.id] = | locationNames[unitQualifier.datavalue.value.id] = PropertyLink.formatEntity(unitQualifier.datavalue.value.id) | ||
end | end | ||
-- attempt to identify country in the qualifier first, but if it's not, go to the entity | -- attempt to identify country in the qualifier first, but if it's not, go to the entity | ||
local countryQualifier = actualClaim.qualifiers and actualClaim.qualifiers[ | local countryQualifier = actualClaim.qualifiers and actualClaim.qualifiers[countryProperty] and actualClaim.qualifiers[countryProperty][1] | ||
local countryId = nil | local countryId = nil | ||
local ts = nil | local ts = nil | ||
if countryQualifier and countryQualifier.snaktype == 'value' then | if countryQualifier and countryQualifier.snaktype == 'value' then | ||
table.insert(locationEntitiesIds, countryQualifier.datavalue.value.id) | table.insert(locationEntitiesIds, countryQualifier.datavalue.value.id) | ||
locationNames[countryQualifier.datavalue.value.id] = | locationNames[countryQualifier.datavalue.value.id] = PropertyLink.formatEntity(countryQualifier.datavalue.value.id) | ||
else | else | ||
local countryClaim = nil | local countryClaim = nil | ||
| שורה 210: | שורה 220: | ||
end | end | ||
countryClaim = findClaimForTimestamp(locationEntityId, | countryClaim = findClaimForTimestamp(locationEntityId, countryProperty, ts) | ||
if countryClaim and countryClaim.mainsnak and countryClaim.mainsnak.snaktype == 'value' then | if countryClaim and countryClaim.mainsnak and countryClaim.mainsnak.snaktype == 'value' then | ||
countryId = countryClaim.mainsnak.datavalue.value.id | countryId = countryClaim.mainsnak.datavalue.value.id | ||
| שורה 237: | שורה 247: | ||
]] | ]] | ||
end | end | ||
-- don't show in case of missing label | |||
if not missingEntityLabel then | if not missingEntityLabel then | ||
table.insert(locationNamesList, locationNames[eachLocationId]) | table.insert(locationNamesList, locationNames[eachLocationId]) | ||