Modul:SmwWikibase

Aus imedwiki
Zur Navigation springen Zur Suche springen

Ausgabe dieses Moduls (mit Aufruf: {{#invoke:SmwWikibase|smwfromwikibase}}):

  • Item:Q9 label: Gemeinschaftskrankenhaus Havelhöhe value: 52.461111,13.16 Adresse: Keine Adresse gefunden - (ok)
  • Item:Q10 label: Dachverband Anthroposophische Medizin in Deutschland value: 52.510193,13.401249 Adresse: Axel-Springer-Str. 54b, 10117 Berlin - (ok)
  • Item:Q11 label: Klinik Arlesheim value: 47.493888888889,7.6147219444444 Adresse: Keine Adresse gefunden - (ok)
  • Item:Q12 label: Praxis Bettina Schulz value: 52.54791,13.34934 Adresse: Antwerpener Straße 3, 13353 Berlin-Wedding - (ok)
  • Item:Q17 label: Arztpraxis Alexanderplatz value: 52.5197917,13.4107139 Adresse: Rathausstr 7, 10178 Berlin - (ok)

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"][1]
			-- 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