Skip to content

Instantly share code, notes, and snippets.

@briantjacobs
Last active May 14, 2022 15:36
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save briantjacobs/fe0753b8e4799e3cafe7 to your computer and use it in GitHub Desktop.
Save briantjacobs/fe0753b8e4799e3cafe7 to your computer and use it in GitHub Desktop.
Structured Wikipedia data resources

Start querying (also scroll down for more query examples!)

Wikipedia stats

Wikipedia info

Wikipedia API

Freebase resources (also see MQL queries below)

Freebase datasources

[{
  "id": null,
  "name": null,
  "type": "/dataworld/mass_data_operation",
  "timestamp": null,
  "sort": "-timestamp",
  "a:operator": [{
    "id": "/m/0qs4g2b",
    "optional": "forbidden"
  }],
  "b:operator": [{
    "id": "/m/0j3vmzv",
    "optional": "forbidden"
  }],
  "c:operator": [{
    "id": "/m/0j_5_4x",
    "optional": "forbidden"
  }],
  "d:operator": [{
    "id": "/m/021y7rx",
    "optional": "forbidden"
  }]
}]

DBPedia resources

SPARQL Endpoints:

SPARQL Resources (also see SPARQL queries below)

Wikidata resources

Linked data in the wild

Misc

Queries

MQL queries - Paste into https://www.freebase.com/query

  • CAST OF ALL 1990s ROBERT DENIRO AND JOE PESCI MOVIES DIRECTED BY MARTIN SCORSESE, WITH THE NAME IN SPANISH IF POSSIBLE
  [{
    "a:starring": [{
      "actor": "Robert de Niro"
    }],
    "b:starring": [{
      "actor": "Joe Pesci"
    }],
    "c:starring": [{
      "actor": null
    }],
    "directed_by": [{
      "name": "Martin Scorsese"
    }],
    "initial_release_date": null,
    "initial_release_date>=": "1990",
    "initial_release_date<=": "1999",
    "a:name": {
      "value": null,
      "lang": "/lang/es",
      "optional": true
    },
    "b:name": null,
    "mid": null,
    "type": "/film/film"
  }]
  • Male american actors born 1943
[{
  "id": null,
  "name": "actor",
  "type": "/people/profession",
  "people_with_this_profession": [{
    "name": null,
    "/people/person/nationality": [{
      "id": "/en/united_states"
    }],
    "/people/person/gender": [{
      "id": "/en/male"
    }],
    "/people/person/date_of_birth>=": "1943",
    "/people/person/date_of_birth<": "1944",
    "/people/person/date_of_birth": null
  }]
}]

  • DeNiro's awards
[{
  "id": null,
  "name": "actor",
  "type": "/people/profession",
  "people_with_this_profession": [{
    "name": "Robert De Niro",
    "/award/award_winner/awards_won": [{
      "*": null
    }]
  }]
}]
  • Disasters
[{
  "id": null,
  "name": null,
  "type": "/event/disaster",
  "fatalities": {
    "value>": 10000,
    "value": null
  },
  "sort": "-fatalities.value"
}]

SPARQL queries - Can be pasted into SPARQL or SNORQL endpoints

  • 100 De Niro movies
PREFIX : <http://dbpedia.org/resource/>
PREFIX dbprop: <http://dbpedia.org/property/>

SELECT ?movie
WHERE {
	 ?movie dbprop:starring :Robert_De_Niro}
ORDER BY ?resource
LIMIT 100
  • Geo query
SELECT ?subject ?label ?lat ?long WHERE {  
?subject owl:sameAs <http://dbpedia.org/resource/Eiffel_Tower> .
<http://dbpedia.org/resource/Eiffel_Tower> geo:lat ?lat.
<http://dbpedia.org/resource/Eiffel_Tower> geo:long ?long.
<http://dbpedia.org/resource/Eiffel_Tower> rdfs:label ?label . }
  • Counting geo query results
SELECT (COUNT(*) AS ?count)
  WHERE{
    ?place rdf:type dbpedia-owl:Place .
    ?place foaf:name ?title .
    ?place geo:lat ?geolat .
    ?place geo:long ?geolong .
  }
  • Landlocked european countries with population filter
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>        
PREFIX type: <http://dbpedia.org/class/yago/>
PREFIX prop: <http://dbpedia.org/property/>
SELECT ?country_name ?population
WHERE {
    ?country a type:LandlockedCountries ;
             rdfs:label ?country_name ;
             prop:populationEstimate ?population .
    FILTER (?population > 15000000 && LANG(?country_name)='en') .
}
  • NASA ships
SELECT ?p ?o WHERE
{ 
  <http://nasa.dataincubator.org/spacecraft/1968-089A> ?p ?o
}
  • Movies, english descriptions
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?film ?description ?film_name WHERE {
    ?film rdf:type <http://dbpedia.org/ontology/Film>.
    ?film foaf:name ?film_name.
    ?film rdfs:comment ?description .
    FILTER (LANG(?description)='en')
}
LIMIT 100
  • Alan Alda properties
SELECT ?property ?hasValue ?isValueOf
WHERE {
  { <http://dbpedia.org/resource/Alan_Alda> ?property ?hasValue }
  UNION
  { ?isValueOf ?property <http://dbpedia.org/resource/Alan_Alda> }
}
  • Counting in SPARQL
(COUNT(DISTINCT ?instance) AS ?count)

  • Space missions
PREFIX dbowl: <http://dbpedia.org/ontology/>
PREFIX dbpprop: <http://dbpedia.org/property/>
PREFIX dbres: <http://dbpedia.org/resource/>

SELECT ?y ?z WHERE {
 ?z a dbowl:SpaceMission 
 }

limit 10
  • European countries

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX yago: <http://dbpedia.org/class/yago/>
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
 
SELECT ?place WHERE {
    ?place rdf:type yago:EuropeanCountries .
    ?place rdf:type dbpedia-owl:Country
}

  • Pablo Picasso painting locations (factforge)
# Cities where paintings of Picasso are located (PROTON)
PREFIX dbpedia: <http://dbpedia.org/resource/>
PREFIX ff: <http://factforge.net/>
PREFIX ptop: <http://www.ontotext.com/proton/protontop#>
PREFIX pext: <http://www.ontotext.com/proton/protonext#>

SELECT DISTINCT  ?painting_l ?owner_l ?city_l
WHERE {
     ?painting pext:authorOf dbpedia:Pablo_Picasso.
     ?painting ptop:isOwnedBy ?owner ; ff:preferredLabel ?painting_l.
     ?owner ff:preferredLabel ?owner_l .
     ?owner ptop:locatedIn ?city.
     ?city a pext:City ; ff:preferredLabel ?city_l .
     OPTIONAL { ?city ptop:subRegionOf ?otherLoc. ?owner ptop:locatedIn
?otherLoc. ?otherLoc a pext:City }
     FILTER (!bound(?otherLoc))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment