Wikidata.jl

A package to easily access Wikidata entities etc.
Author KimBue
Popularity
4 Stars
Updated Last
3 Years Ago
Started In
April 2020

Wikidata

Build Status Build Status Codecov Coveralls

This is a project to implement a Wikidata Client in Julia. For the moment, I am using this project to get used to Julia.

Usage

#load a Wikidata-Entity (Douglas Adams) 
adams = Wikidata.WikidataEntity("Q42")
println(Wikidata.label(adams))

#check if place of birth exists for this entity:
if(Wikidata.hasproperty(adams, "P19"))
  placeofbirth = Wikidata.getproperty(adams, "P19")
  # print Adams' place of birth: Cambridge
  println(Wikidata.label(placeofbirth[1]))
end

Example

How to extract birthplaces and their coordinates for all presidents (head of governement) of the US (or any other country)

using Wikidata
using DataFrames

function getPresidentsBirthPlaces(x::String)
    df = DataFrame(Name = String[], birthplace= String[], birthplace_lat = BigFloat[], birthplace_lon = BigFloat[])
    country = Wikidata.WikidataEntity(x)
    #head of government is found under Property P6
    presidents_Entities = Wikidata.getproperty(country, "P6")
    for president in presidents_Entities
       try
       #P19 is the place-of-birth property 
       birthplace_Entity = Wikidata.getproperty(president, "P19")
       #P625 is the coordinate location property 
       birthplace_latlon = Wikidata.getproperty(birthplace_Entity[1], "P625")[1]
       push!(df, (Wikidata.label(president), Wikidata.label(birthplace_Entity[1]),birthplace_latlon[1], birthplace_latlon[2]))
        catch
            println("Data not found")
        end
    end
    df
 end
 df = getPresidentsBirthPlaces("Q30") #Q30 is the identifier for the US, Q183 is the identifier of Germany etc.

Used By Packages

No packages found.