Modul:SmwWikibase: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
(claims ergänzt) |
(claims ergänzt) |
||
Zeile 7: | Zeile 7: | ||
if (entity["claims"]["P8"] ~= nil) | if (entity["claims"]["P8"] ~= nil) | ||
then | then | ||
− | address = entity["P8"] | + | address = entity["claims"]["P8"] |
-- prioritize german over english for now | -- prioritize german over english for now | ||
rvalue = address["mainsnak"]["datavalue"]["value"] | rvalue = address["mainsnak"]["datavalue"]["value"] |
Version vom 27. August 2021, 17:48 Uhr
Ausgabe dieses Moduls (mit Aufruf: {{#invoke:SmwWikibase|smwfromwikibase}}): Lua-Fehler in Zeile 11: attempt to index field 'mainsnak' (a nil value)
local p = {}
local set = require('Module:Smw').set
local function getAddress ( entity )
rvalue = "Keine Adresse gefunden"
if (entity["claims"]["P8"] ~= nil)
then
address = entity["claims"]["P8"]
-- prioritize german over english for now
rvalue = address["mainsnak"]["datavalue"]["value"]
end
return rvalue
end
local function getLabel( entity )
rvalue = "Keine Bezeichnung gefunden"
if (entity["labels"] ~= nil)
then
labels = entity["labels"]
-- prioritize german over english for now
if (labels["de"] ~= nil) then rvalue = labels["de"]["value"]
elseif (labels["en"] ~= nil) then rvalue = labels["en"]["value"]
end
end
return rvalue
end
-- find wikibase objects with coordinates and make subobjects of them
function p.smwfromwikibase()
local i
local result
result = ''
for i = 1, 20, 1 do
pageId = "Q" .. i
id, entity, wrongQualifier = p.getEntity(pageId)
if (not wrongQualifier)
then
if (entity["claims"] ~= nil)
then
if (entity["claims"]["P2"] ~= nil)
then
latitude = entity["claims"]["P2"][1]["mainsnak"]["datavalue"]["value"]["latitude"]
longitude = entity["claims"]["P2"][1]["mainsnak"]["datavalue"]["value"]["longitude"]
value = latitude .. "," .. longitude
label = getLabel(entity)
address = getAddress(entity)
result = result .. "* [[Item:" .. id .. "]] label: " .. label .. " value: " .. value .. " Adresse: " .. address
smwData = {}
smwData["Quelle"] = "wikibase"
smwData["Koordinaten"] = value
smwData["Name"] = label
smwData["Adresse"] = address
smwData["Belongs to"] = "Anthroposophische Medizin in Berlin"
smwData["Bezeichnung"] = "Aus Wikibase erzeugtes SMW - Subobjekt (" .. id .. ")"
success = mw.smw.subobject(smwData)
if (success) then
result = result .. " - (ok)"
else
result = result .. " - (Fehler)"
end
result = result .. '\n'
end
end
end
end
return result
end
local function isSet( arg )
return arg and arg ~= ''
end
function p.getEntity( id )
local wrongQualifier = false
local entity = nil
if not isSet( id ) then
return '', entity, wrongQualifier
end
if mw.wikibase.isValidEntityId( id ) then
-- expensive function call
-- redirect ids marked false, too
entity = mw.wikibase.getEntity( id )
end
if not entity then
id = ''
wrongQualifier = true
end
return id, entity, wrongQualifier
end
return p