יחידה:LocationAndCountry: הבדלים בין גרסאות בדף

מאין תקציר עריכה
מאין תקציר עריכה
שורה 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 bestClaim = nil
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
end
 
if timestamp then
if timestamp then
if before and HeDateUtils.le(timestamp, before) then --the claim list is sorted by before
if before and HeDateUtils.le(timestamp, before) then --the claim list is sorted by before
break
break
elseif after == nil and before and not HeDateUtils.le(timestamp, before) then
elseif after == nil and before and not HeDateUtils.le(timestamp, before) then
return eachPropClaim
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  
return eachPropClaim
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
return eachPropClaim
table.insert(bestClaims, eachPropClaim)
end
end
end
end
if not bestClaim or mw.wikibase.entity.claimRanks['RANK_' .. mw.ustring.upper(bestClaim.rank)] < mw.wikibase.entity.claimRanks['RANK_' .. mw.ustring.upper(eachPropClaim.rank)]  
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(bestClaim.rank)] < mw.wikibase.entity.claimRanks['RANK_' .. mw.ustring.upper(eachPropClaim.rank)] and not after) then
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
bestClaim = eachPropClaim
bestNoTimeClaim = eachPropClaim
end
end
end
end
שורה 134: שורה 137:
end end
end end


if bestClaim then
if #bestClaims==0 and bestNoTimeClaim then
return bestClaim
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