Nicht angemeldeter Benutzer - Bearbeiten von Seiten ist nur als angemeldeter Benutzer möglich.

Modul:SmwWikibase

Aus imedwiki
Zur Navigation springen Zur Suche springen

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

  • LOC Baseimedwiki:Item:Q9 label: Gemeinschaftskrankenhaus Havelhöhe coordinates: 52.461111,13.16 Adresse: Name: Gemeinschaftskrankenhaus Havelhöhe Belongs to: Online: Type: Specialty: Doctors: - (ok)
  • LOC Baseimedwiki:Item:Q10 label: Dachverband Anthroposophische Medizin in Deutschland coordinates: 52.510193,13.401249 Adresse: Axel-Springer-Str. 54b, 10117 Berlin Name: Dachverband Anthroposophische Medizin in Deutschland Belongs to: Online: Type: Specialty: Doctors: - (ok)
  • LOC Baseimedwiki:Item:Q11 label: Klinik Arlesheim coordinates: 47.493888888889,7.6147219444444 Adresse: Name: Klinik Arlesheim Belongs to: Online: Type: Specialty: Doctors: - (ok)
  • LOC Baseimedwiki:Item:Q12 label: Praxis Bettina Schulz coordinates: 52.54791,13.34934 Adresse: Antwerpener Straße 3, 13353 Berlin-Wedding Name: Praxis Bettina Schulz Belongs to: Anthroposophische Medizin in Berlin Online: https://gyn-praxis-schulz.de/ Type: Praxis Specialty: Gynäkologie Doctors: Bettina Schulz - (ok)
  • DOC Baseimedwiki:Item:Q13 label: Bettina Schulz Adresse: Name: Bettina Schulz Ort: Praxis Bettina Schulz Belongs to: Anthroposophische Medizin in Berlin Online: Type: Arzt Specialty: Gynäkologie - (ok)
  • LOC Baseimedwiki:Item:Q17 label: Arztpraxis Alexanderplatz coordinates: 52.5197917,13.4107139 Adresse: Rathausstr 7, 10178 Berlin Name: Arztpraxis Alexanderplatz Belongs to: Anthroposophische Medizin in Berlin Online: Http://www.arztpraxis-alexanderplatz.de Type: Praxis Specialty: Allgemeinmedizin Doctors: - (ok)
  • DOC Baseimedwiki:Item:Q19 label: Andreas Stein Adresse: Name: Andreas Stein Ort: Arztpraxis Alexanderplatz Belongs to: Anthroposophische Medizin in Berlin Online: Type: Arzt Specialty: Allgemeinmedizin - (ok)
  • LOC Baseimedwiki:Item:Q30 label: Academic Consortium for Integrative Medicine & Health coordinates: 45.41118369281,-122.71948320392 Adresse: Name: Academic Consortium for Integrative Medicine & Health Belongs to: Online: https://www.imconsortium.org Type: Specialty: Doctors: - (ok)

local p = {}

local function getLabel( entity )
	rvalue = ""
	
	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

local function getType ( entity)
    rvalue = ""
	
	if (entity["claims"]["P10"] ~= nil)
    	then
			value = entity["claims"]["P10"][1]
			rvalue = value["mainsnak"]["datavalue"]["value"]
    	end
	return rvalue
end

local function getAddress ( entity )
    rvalue = ""
	
	if (entity["claims"]["P8"] ~= nil)
    	then
			value = entity["claims"]["P8"][1]
			rvalue = value["mainsnak"]["datavalue"]["value"]
    	end
	return rvalue
end

local function getWebsite ( entity )
    rvalue = ""
	
	if (entity["claims"]["P7"] ~= nil)
    	then
			value = entity["claims"]["P7"][1]
			rvalue = value["mainsnak"]["datavalue"]["value"]
    	end
	return rvalue
end

local function getBelongsTo ( entity )
    rvalue = ""
	
	attributeId = "P9"
	
	if (entity["claims"][attributeId] ~= nil)
    	then
			value = entity["claims"][attributeId][1]
			valueId = value["mainsnak"]["datavalue"]["value"]["id"]
			rID, rEntity, wrongQ = p.getEntity(valueId)
			rvalue = getLabel(rEntity)
    	end
	return rvalue
end

local function getDoctors ( entity )
    rvalue = ""
	
	attributeId = "P11"
	
	if (entity["claims"][attributeId] ~= nil)
    	then
			value = entity["claims"][attributeId][1]
			valueId = value["mainsnak"]["datavalue"]["value"]["id"]
			rID, rEntity, wrongQ = p.getEntity(valueId)
			rvalue = getLabel(rEntity)
    	end
	return rvalue
end

-- get doctors location of work
local function getLocation ( entity )
    rvalue = ""
	
	attributeId = "P4"
	
	if (entity["claims"][attributeId] ~= nil)
    	then
			value = entity["claims"][attributeId][1]
			valueId = value["mainsnak"]["datavalue"]["value"]["id"]
			rID, rEntity, wrongQ = p.getEntity(valueId)
			rvalue = getLabel(rEntity)
    	end
	return rvalue
end


local function getSpecialty ( entity )
    rvalue = ""
	
	attributeId = "P6"
	
	if (entity["claims"][attributeId] ~= nil)
    	then
			value = entity["claims"][attributeId][1]
			valueId = value["mainsnak"]["datavalue"]["value"]["id"]
			rID, rEntity, wrongQ = p.getEntity(valueId)
			rvalue = getLabel(rEntity)
    	end
	return rvalue
end

local function extractWBLocationSubobject ( entity )
    local resultString
    local smwData
    local latLon
    local label
    local address
    local belongsTo
    local website
    local type
    local specialty
	
    resultString = ""
	
    latitude = entity["claims"]["P2"][1]["mainsnak"]["datavalue"]["value"]["latitude"]
    longitude = entity["claims"]["P2"][1]["mainsnak"]["datavalue"]["value"]["longitude"]
    latLon = latitude .. "," .. longitude
        		    
    label = getLabel(entity)
    address = getAddress(entity)
    belongsTo = getBelongsTo(entity)
    website = getWebsite(entity)
    type = getType(entity)
    specialty = getSpecialty(entity)
    doctors = getDoctors(entity)
        		    
    resultString = resultString .. "* LOC [[Baseimedwiki:Item:" .. id .. "]] label: " .. label .. 
     			" coordinates: " .. latLon .. 
      			" Adresse: " .. address ..
       			" Name: " .. label ..
       			" Belongs to: " .. belongsTo ..
       			" Online: " .. website ..
      			" Type: " .. type ..
       			" Specialty: " .. specialty ..
       			" Doctors: " .. doctors
        		    
    smwData = {}
    smwData["Quelle"] = "wikibase"
    smwData["Coordinates"] = latLon
    smwData["Name"] = label
    smwData["Arzt"] = doctors
    smwData["Adresse"] = address
    smwData["Belongs to"] = belongsTo
    smwData["Online"] = website
    smwData["Typ"] = type
    smwData["Fachrichtung"] = specialty
    smwData["WikibaseId"] = id
    smwData["Bezeichnung"] = "Aus Wikibase (" .. id .. ") erzeugtes SMW - Subobjekt"
    
    return smwData, resultString
end

local function extractWBDoctorSubobject ( entity )
    local resultString
    local smwData
    local latLon
    local label
    local address
    local belongsTo
    local website
    local type
    local specialty
	
    resultString = ""
	
    latLon = nil

    label = getLabel(entity)
    address = getAddress(entity)
    belongsTo = getBelongsTo(entity)
    website = getWebsite(entity)
    type = getType(entity)
    specialty = getSpecialty(entity)
    location = getLocation(entity)
        		    
    resultString = resultString .. "* DOC [[Baseimedwiki:Item:" .. id .. "]] label: " .. label ..
      			" Adresse: " .. address ..
       			" Name: " .. label ..
       			" Ort: " .. location ..
       			" Belongs to: " .. belongsTo ..
       			" Online: " .. website ..
      			" Type: " .. type ..
       			" Specialty: " .. specialty
        		    
    smwData = {}
    smwData["Quelle"] = "wikibase"
    smwData["Coordinates"] = latLon
    smwData["Name"] = label
    smwData["Arzt"] = doctors
    smwData["Adresse"] = address
    smwData["Ort"] = location
    smwData["Belongs to"] = belongsTo
    smwData["Online"] = website
    smwData["Typ"] = type
    smwData["Fachrichtung"] = specialty
    smwData["WikibaseId"] = id
    smwData["Bezeichnung"] = "Aus Wikibase (" .. id .. ") erzeugtes SMW - Subobjekt"
    
    return smwData, resultString
end

-- find wikibase medical objects and make subobjects of them
function p.smwfromwikibase()
    local i
    local result
    local success
    local smwData
 
    result = ''
    for i = 1, 50, 1 do
    	smwData = nil
    	pageId = "Q" .. i
    	id, entity, wrongQualifier = p.getEntity(pageId)
    	if (not wrongQualifier)
    	then
    		if (entity["claims"] ~= nil)
    		then
    			if (entity["claims"]["P2"] ~= nil) then 
    				smwData, resultString = extractWBLocationSubobject (entity) 
    				
    				success = mw.smw.subobject(smwData, smwData["Name"])
        		    if (success) then
        		    	result = result .. resultString .. " - (ok)"
        		    else
        		    	result = result .. resultString .. " - (Fehler)"
        		    end
        		    result = result .. '\n'
    			end
        		
        		if (entity["claims"]["P5"] ~= nil) then 
        			smwData, resultString = extractWBDoctorSubobject (entity)
        			
    				success = mw.smw.subobject(smwData)
        		    if (success) then
        		    	result = result .. resultString .. " - (ok)"
        		    else
        		    	result = result .. resultString .. " - (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