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

יצירת דף עם התוכן "--[[Adapted from ro:Modul:LocationAndCountry with changes: * Using PropertyLink for linking format * No use of external modules that exist in rowiki but have dif..."
 
מ גרסה אחת של הדף wikipedia:he:יחידה:LocationAndCountry יובאה
 
(12 גרסאות ביניים של 3 משתמשים אינן מוצגות)
שורה 7: שורה 7:
* offical/short name
* offical/short name
]]
]]


-- will display a wikidata property representing a location, followed by a comma and the name of the country, both with wikilinks
-- will display a wikidata property representing a location, followed by a comma and the name of the country, both with wikilinks
שורה 16: שורה 15:
-- the fifth argument specifies the separator to use when displaying multiple values
-- the fifth argument specifies the separator to use when displaying multiple values
local getArgs = require('Module:Arguments').getArgs
local getArgs = require('Module:Arguments').getArgs
local wikidata = require('Module:Wikidata')
local HeDateUtils = require('Module:תאריך')
local HeDateUtils = require('Module:תאריך')
local TableTools = require('Module:TableTools')
local TableTools = require('Module:TableTools')
שורה 73: שורה 71:
d2 = HeDateUtils.newFromWikidataValue(q2['P580'][1].datavalue.value)
d2 = HeDateUtils.newFromWikidataValue(q2['P580'][1].datavalue.value)
end
end
if d1 and d2 then return not HeDateUtils.le(d1, d2)
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
שורה 87: שורה 86:


local function findSortedClaimsForProperty(entity, propertyId)
local function findSortedClaimsForProperty(entity, propertyId)
if propertyId == nil then return nil end
if entity == nil then entity = mw.wikibase.getEntityIdForCurrentPage() end
if entity == nil then entity = mw.wikibase.getEntityObject() end
local rawClaims = mw.wikibase.getAllStatements(entity, propertyId)
if type(entity) == 'string' then entity = mw.wikibase.getEntityObject(entity) end
if entity == nil or entity.claims == nil then return nil end
local rawClaims = entity.claims[propertyId]
if rawClaims == nil then return {} end
if rawClaims == nil then return {} end
שורה 101: שורה 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)
שורה 111: שורה 108:
if eachPropClaim.qualifiers then
if eachPropClaim.qualifiers then
if eachPropClaim.qualifiers['P580'] and eachPropClaim.qualifiers['P580'][1] and isValueSnak(eachPropClaim.qualifiers['P580'][1]) then
if eachPropClaim.qualifiers['P580'] and eachPropClaim.qualifiers['P580'][1] and isValueSnak(eachPropClaim.qualifiers['P580'][1]) then
after = HeDateUtils.julianToGregorian(HeDateUtils.newFromWikidataValue(eachPropClaim.qualifiers['P580'][1].datavalue.value))
before = HeDateUtils.julianToGregorian(HeDateUtils.newFromWikidataValue(eachPropClaim.qualifiers['P580'][1].datavalue.value))
--after = GregorianDate.convertToGregorianIfInInterval(DateUtils.extractDateFromWikidataSnak(eachPropClaim.qualifiers['P580'][1]))
--after = GregorianDate.convertToGregorianIfInInterval(DateUtils.extractDateFromWikidataSnak(eachPropClaim.qualifiers['P580'][1]))
end
end
if eachPropClaim.qualifiers['P582'] and eachPropClaim.qualifiers['P582'][1] and isValueSnak(eachPropClaim.qualifiers['P582'][1]) then
if eachPropClaim.qualifiers['P582'] and eachPropClaim.qualifiers['P582'][1] and isValueSnak(eachPropClaim.qualifiers['P582'][1]) then
before = HeDateUtils.julianToGregorian(HeDateUtils.newFromWikidataValue(eachPropClaim.qualifiers['P582'][1].datavalue.value))
after = HeDateUtils.julianToGregorian(HeDateUtils.newFromWikidataValue(eachPropClaim.qualifiers['P582'][1].datavalue.value))
--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 after == nil and before and not HeDateUtils.le(timestamp, before) then
break
table.insert(bestClaims, eachPropClaim)
elseif after == nil and before and HeDateUtils.le(timestamp, before) 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 and HeDateUtils.le(timestamp, before) and not HeDateUtils.le(timestamp, after)  then  
elseif after and before == nil and HeDateUtils.le(timestamp, after) then
return eachPropClaim
table.insert(bestClaims, eachPropClaim)
elseif after and before == nil and not HeDateUtils.le(timestamp, after) then
return 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
שורה 138: שורה 135:
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
end
end
end
local function missingLabelCategory(propertyName)
return '[[קטגוריה:ויקינתונים:ערכים_חסרי_תווית_בעברית: ' .. (mw.wikibase.label( propertyName) or propertyName) .. ']][[קטגוריה:ויקינתונים:ערכים_חסרי_תווית_בעברית]]'
end
end


שורה 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
שורה 162: שורה 172:
local valueList = {}
local valueList = {}
local valueCount = 0
local valueCount = 0
local missingLabel = false
if claims and 0 < #claims then
if claims and 0 < #claims then
for claimIdx, actualClaim in pairs(claims) do
for claimIdx, actualClaim in pairs(claims) do
שורה 172: שורה 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['P131'] and actualClaim.qualifiers['P131'][1]
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] = findLinkToItem(unitQualifier.datavalue.value.id, true, false, false)
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['P17'] and actualClaim.qualifiers['P17'][1]
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] = findLinkToItem(countryQualifier.datavalue.value.id, true, false, false)
locationNames[countryQualifier.datavalue.value.id] = PropertyLink.formatEntity(countryQualifier.datavalue.value.id)
else
else
local countryClaim = nil
local countryClaim = nil
שורה 209: שורה 220:
end
end
countryClaim = findClaimForTimestamp(locationEntityId, 'P17', ts)
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
שורה 217: שורה 228:
locationEntitiesIds = TableTools.removeDuplicates(locationEntitiesIds)
locationEntitiesIds = TableTools.removeDuplicates(locationEntitiesIds)
local locationNamesList = {}
local locationNamesList = {}
for _,eachLocationId in ipairs(locationEntitiesIds) do
for _,eachLocationId in ipairs(locationEntitiesIds) do
local missingEntityLabel = false
if not locationNames[eachLocationId] then
if not locationNames[eachLocationId] then
locationNames[eachLocationId] = PropertyLink.formatEntity(eachLocationId)
locationNames[eachLocationId], missingEntityLabel = PropertyLink.formatEntity(eachLocationId)
missingLabel = missingLabel or missingEntityLabel
--[[ Disabled feature from ro wiki: show the offical name/short name in that timestamp
--[[ Disabled feature from ro wiki: show the offical name/short name in that timestamp
local correspindingShortNameClaim = findClaimForTimestamp(eachLocationId, 'P1813', ts)
local correspindingShortNameClaim = findClaimForTimestamp(eachLocationId, 'P1813', ts)
שורה 226: שורה 241:
else
else
local correspondingOfficialNameClaim = findClaimForTimestamp(eachLocationId, 'P1448', ts)
local correspondingOfficialNameClaim = findClaimForTimestamp(eachLocationId, 'P1448', ts)
mw.log('correspondingOfficialNameClaim')
mw.logObject(correspondingOfficialNameClaim)
if correspondingOfficialNameClaim then  
if correspondingOfficialNameClaim then  
locationNames[eachLocationId] = correspondingOfficialNameClaim.mainsnak.datavalue.value.text
locationNames[eachLocationId] = correspondingOfficialNameClaim.mainsnak.datavalue.value.text
שורה 234: שורה 247:
]]
]]
end
end
table.insert(locationNamesList, locationNames[eachLocationId])
 
-- don't show in case of missing label
if not missingEntityLabel then
table.insert(locationNamesList, locationNames[eachLocationId])
end
end
end
if 0 < #locationNamesList then
if 0 < #locationNamesList then
שורה 251: שורה 268:
if separator == nil then separator = '; ' end
if separator == nil then separator = '; ' end
if maxvalues > #valueList then maxvalues = #valueList end
if maxvalues > #valueList then maxvalues = #valueList end
return table.concat(valueList, separator, 1, maxvalues)
if missingLabel then
return table.concat(valueList, separator, 1, maxvalues) .. missingLabelCategory(param)
else
return table.concat(valueList, separator, 1, maxvalues)
end
end
end