אונטערשייד צווישן ווערסיעס פון "יחידה:Wikidata"

1,691 בייטן צוגעלייגט ,  פֿאַר 2 יאָר
אפדעיט
ק (1 רעוויזיע אימפארטירט: אימפארטירט פון די יידישע וויקיפעדיע, זע ביישטייערער ליסטע)
(אפדעיט)
שורה 49: שורה 49:


local function printError(code)
local function printError(code)
return '<span class="error">' .. i18n.errors[code] .. '</span>[[קאטעגאריע:שגיאת קריאת ויקינתונים]]'
return '<span class="error">' .. i18n.errors[code] .. '</span>[[קטגוריה:שגיאת קריאת ויקינתונים]]'
end
end


שורה 193: שורה 193:
end
end
else
else
if data["entity-type"] == "item" then return mw.wikibase.label("Q" .. data["numeric-id"]) or mw.ustring.format('%s%s', id, '[[קאטעגאריע:ויקינתונים:ערכים_חסרי_תווית_בעברית]]') else printError("unknown-entity-type") end
if data["entity-type"] == "item" then return mw.wikibase.label("Q" .. data["numeric-id"]) or mw.ustring.format('%s%s', id, '[[קטגוריה:ויקינתונים:ערכים_חסרי_תווית_בעברית]]') else printError("unknown-entity-type") end
end
end
end
end
שורה 229: שורה 229:
end
end


function getQualifierSnak(claim, qualifierId)
function getQualifierSnak(claim, qualifierId, onlyHebrew)
-- a "snak" is Wikidata terminology for a typed key/value pair
-- a "snak" is Wikidata terminology for a typed key/value pair
-- a claim consists of a main snak holding the main information of this claim,
-- a claim consists of a main snak holding the main information of this claim,
שורה 237: שורה 237:
if claim.qualifiers then
if claim.qualifiers then
local qualifier = claim.qualifiers[qualifierId]
local qualifier = claim.qualifiers[qualifierId]
if qualifier then return qualifier[1] end
if qualifier then
-- only hebrew qualifiers for monolingualtext type
if onlyHebrew and qualifier[1].datatype == 'monolingualtext' then
for idx,eachForm in pairs(qualifier) do
if eachForm.datavalue.value.language == 'he' then
return qualifier[idx]
end
end
else
return qualifier[1]
end
end
end
end
return nil, printError("qualifier-not-found")
return nil, printError("qualifier-not-found")
שורה 249: שורה 260:
local error
local error
local snak
local snak
snak, error = getQualifierSnak(claim, qualifierId)
local onlyHebrew
if qualifierId == 'P2096' then onlyHebrew = true end
snak, error = getQualifierSnak(claim, qualifierId, onlyHebrew)
if snak then
if snak then


שורה 277: שורה 292:
end
end
return result
return result
end
-- Check if the 'qualifierId' exists on the 'property' of given 'id'
function p.isClaimExist(property, qualifierId, id)
-- get wikidata entity
local entity = mw.wikibase.getEntityObject(id or nil)
if not entity then
return false
end
-- fetch the first claim of satisfying the given property
local claims = findClaims(entity, property)
if not claims or not claims[1] then
return false
end
-- get initial sort indices
local sortindices = {}
for idx in pairs(claims) do
sortindices[#sortindices + 1] = idx
end
-- check if there is an element
local claim = claims[sortindices[1]]
result, error = getValueOfClaim(claim, qualifierId, parameter)
return result ~= nil
end
end


שורה 526: שורה 568:
return computeLinkToItem(entityId, capitalize, callFunction)
return computeLinkToItem(entityId, capitalize, callFunction)
end
end
-- check whether entityId has a claim with propertyId referencing to claimedEntity
p.hasClaim = function(entityId, propertyId, claimedEntity)
if entityId==nil or propertyId==nil then return false end
local propertyVals = mw.wikibase.getBestStatements(entityId, propertyId)
if (not propertyVals) or (#propertyVals==0) then return false end
for i, property in ipairs(propertyVals) do
    local propValue = property.mainsnak and property.mainsnak.datavalue
    if not propValue then return false end
    if propValue.value['id'] == claimedEntity then
    return true
end
end
return false
end
p.getValueOfClaim = getValueOfClaim
p.getValueOfClaim = getValueOfClaim
return p
return p