Skip to content

Instantly share code, notes, and snippets.

@knbknb
Last active December 20, 2020 13:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save knbknb/07544c7036861fb3e33c807cbb6bb7d4 to your computer and use it in GitHub Desktop.
Save knbknb/07544c7036861fb3e33c807cbb6bb7d4 to your computer and use it in GitHub Desktop.
Simple sparql queries for use at https:://dbpedia.org
# for more prefixes
# (wikidata, common)
# see also https://gist.github.com/knbknb/081ee7af40a01a0a365d0df5f49acd7c
#
# "Notable works" of a writer
#
PREFIX : <http://dbpedia.org/resource/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?author_name ?title
FROM <http://dbpedia.org/>
WHERE {
?author rdf:type dbo:Writer .
?author rdfs:label ?author_name .
?author dbo:notableWork ?work .
?work rdfs:label ?title .
?author foaf:name "Abi Morgan"@en .
FILTER (LANG(?author_name)="en" )
FILTER (LANG(?title)="en")
}
ORDER BY ASC (?author_name)
OFFSET 0
# dbpedia query
# https://dbpedia.org/sparql
#
# movies similar to "The Matrix"
# "Breakfast at Tiffany's (film)"
#
# note how characters are escaped!
prefix dbo: <http://dbpedia.org/ontology/>
prefix dbr: <http://dbpedia.org/resource/>
select ?similar (count(?p) as ?similarity)
where {
# values ?movie { dbr:The_Matrix }
values ?movie { dbr:Breakfast_at_Tiffany\u0027s_\(film\) }
?similar ?p ?o ;
a dbo:Film .
?movie ?p ?o .
}
group by ?similar ?movie
having (count(?p) > 30)
order by desc(?similarity)
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
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/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX : <http://dbpedia.org/resource/>
PREFIX dbpedia2: <http://dbpedia.org/property/>
PREFIX dbpedia: <http://dbpedia.org/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
#people who died on the german island of Sylt
SELECT ?name ?birth ?death ?person
WHERE {
?person dbo:deathPlace :Sylt .
?person dbo:birthDate ?birth .
?person foaf:name ?name .
?person dbo:deathDate ?death .
FILTER (?death > "1000-1-1"^^xsd:date) .
}
ORDER BY ?death
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX dbp: <http://dbpedia.org/property/>
PREFIX dbc: <http://dbpedia.org/resource/Category:>
PREFIX dbo: <http://dbpedia.org/ontology/>
# wikidata
PREFIX wd: <http://www.wikidata.org/entity/>
# who discovered something, anything?
SELECT distinct ?s ?o
# FROM seems to be optional
FROM <http://dbpedia.org/>
WHERE{
?s dbo:discovered ?o .
}
# WIKIDATA: all properties and objects about Albert Einstein
# returns 1300 rows
SELECT * WHERE {
wd:Q8772 ?p ?o .
}
# label of a certain item
SELECT DISTINCT * WHERE {
wd:Q19675 rdfs:label ?label .
FILTER (langMatches( lang(?label), "ES" ) )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment