I am currently learning about SPARQL, and I'd like to use DBpedia SPARQL endpoint.
Here is the endpoint : https://dbpedia.org/sparql
And here is a link toward DBpedia ontology : https://wiki.dbpedia.org/services-resources/ontology
My goal is to find all the Nobel Prize scientist in the field of Physics only, and order them by their age.
However, I am not yet used to finding the information I want... For example, I found here http://mappings.dbpedia.org/server/ontology/classes/ some interesting classes such as Scientist or NobelPrize and also interesting properties like award, but they don't give me any result on this simple query :
PREFIX dbpedia: <http://dbpedia.org/resource/>
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
PREFIX dbpprop: <http://dbpedia.org/property/>
SELECT ?scientist
WHERE {
?scientist a dbpedia-owl:Scientist .
?scientist dbpprop:award dbpedia-owl:NobelPrize .
?scientist dbpprop:age ?age
}
ORDER BY ?age
I am also unable to find a proper way to specifically look for Physic Nobel Prize...
Can someone help me through this query ?
Thank you very much
Related
I would like to query datasets such as FOAF and DBPedia. The aim is to run quite simple requests such as “Which paintings did Magritte painted ?”,”Which are the American actor who played in American movies ?” …
So I wrote my queries, and used DBpedia snorql to run them. Then, for some other reasons, I tried Live DBpedia and OpenLinks demo.openlinksw.com to discover that the results were different according to the endpoint.
Here are 2 examples :
1) Answer with DBpedia SnorQL but neither Live DBpedia nor OpenLinks demo.openlinksw.com
#works of Magritte
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dbp: <http://dbpedia.org/property/>
SELECT * WHERE {
?person a dbo:Artist .
?person foaf:surname "Magritte"#en .
?work dbo:author ?person .
OPTIONAL {?work dbp:year ?year ; dbo:museum ?museum .}
}
ORDER BY ?year
2) Answer with Live DBpedia but neither DBpedia SnorQL nor OpenLinks demo.openlinksw.com
#american actors from Willem Robert van Hage R tutorial
SELECT ?actor ?movie ?director ?movie_date
WHERE {
?m dc:subject <http://dbpedia.org/resource/Category:American_films> .
?m rdfs:label ?movie .
FILTER(LANG(?movie) = "en")
?m dbp:released ?movie_date .
FILTER(DATATYPE(?movie_date) = xsd:date)
?m dbp:starring ?a .
?a rdfs:label ?actor .
FILTER(LANG(?actor) = "en")
?m dbp:director ?d .
?d rdfs:label ?director .
FILTER(LANG(?director) = "en")
}
LIMIT 1000
I thought an endpoint was simply a tool to query dataset whatever it is. So I thought that you can query DBPedia and FOAF from dbpedia, live dbpedia or openlinks demo.openlinksw.com ..
I read that actually different endpoints use different datasets but I can’t get why, as you give specific URI to reach.
Why do same query returns different results according to the SPARQL endpoint ?
Much like different instances of SQL DBMS (such as [in no particular order and without implication of endorsement] OpenLink Virtuoso, Oracle, MySQL, Informix, SQL Server, Sybase, DB2, PostgreSQL, Ingres, Progress OpenEdge, and many others) hold different data, different instances (read: SPARQL endpoints) of RDF RDBMS, also known as Quadstores or Triplestores (such as [in no particular order and without implication of endorsement] OpenLink Virtuoso, AllegroGraph, Stardog, Neo4J, MarkLogic, and many others) hold different data.
You cannot query Joe's database in DBMS A through Fred's database in DBMS B -- unless someone has already told Fred's database and/or DBMS about Joe's database and/or DBMS (e.g., VDBMS functionality), or you include some information about Joe's database and/or DBMS in your query (e.g., SPARQL Federation), etc.
(A "DBMS" is a Database Management System, such as listed above. A "database" is a collection of data, typically stored in a [large] document, which is managed by a DBMS.)
Of particular note relative to your question --
FOAF is an ontology, a vocabulary, which is used to describe entities.
DBpedia is a dataset (which has had various versions over time), and a project, and an organization, and various other things (the ambiguity of literal identifiers!).
OpenLink Software (not "openlinks") is a company which produces OpenLink Virtuoso, among other data-related software and services, and which provides a number of live endpoints on the web -- including the main DBpedia endpoint. (ObDisclaimer: OpenLink Software is also my employer.)
I want to get some information from the FOAF ontology. I tried the following SPARQL query, but it returns no results. I tried this query to get familiar with FOAF, but what I really want to do is to find all the people that a particular person ?x knows (using the property foaf:knows). How do I do this?
PREFIX foaf:<http://xmlns.com/foaf/0.1/>
SELECT ?name ?mbox
WHERE { ?x foaf:name ?name .
?x foaf:mbox ?mbox .
}
Semantic web is made of different components.
Knowledge is represented as RDF triples. These triples describes Resources based on a Subject - Predicate - Object syntax. For example, "John is a Male" may be represented as a RDF triple.
On top of RDF, we may use RDFS and OWL to specify restrictions and other information on these data. Thanks to RDFS, I can specify that "Male is a subclass of Person" and it is therefore possible to infer that "John is a Person". RDFS and OWL helps to define ontologies. An ontology is a vocabulary (that can be general or specific to a domain) to represents data. For example, I may want to create an ontology CAT to represent data on cats.
In that case, I would create my CAT vocabulary defining that "Cat is a subclass of Animal" and "hasOwner is a property that links a cat to a Person" and some other properties. Then, I am able to instantiate some individuals to create data on cats. For example by saying that "Baccara is a Cat" and "Baccara hasOwner John".
FOAF is basically a vocabulary to represent data on people and especially links between these people. FOAF vocabulary gives some properties and classes to handle easily information on people. But it doesn't provide any piece of information, only the "structure"/"model"/"schema" to organize information.
There are no individuals in the FOAF dataset. That is why your query returns no result. Since there's no people in the FOAF dataset, it is normal that the query returns nothing.
You may want to build your own RDF dataset based on FOAF vocabulary. To do so, you can try a tool like Protégé, or more easily with a text editor if you're familiar with RDF/XML or Turtle.
Otherwise, if you only need to get familiar with FOAF, you can query the model. For example, you may want to get all the subclasses of Agent :
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT distinct ?c
WHERE { ?c rdfs:subClassOf foaf:Agent }
I recommend you to read a bit on the semantic web components (especially RDF and RDFS, and differences between them) before going any further in FOAF. Plus, a nice exercise to learn SPARQL consists in querying DBpedia: http://dbpedia.org/sparql.
I have a burning question concerning DBpedia. Namely, I was wondering how I could search for all the properties in DBpedia per page. The URI http://nl.dbpedia.org/property/einde concerns the property "einde". I would like to get all existing property/ pages. This does not seem too hard, but I don't know anything about SPARQL, so that's why I want to ask for some help. Perhaps there is some kind of dump of it, but I honestly don't know.
Rather than asking for pages whose URLs begin with, e.g., http://nl.dbpedia.org/property/, we can express the query by asking “for which values of ?x is there a triple ?x rdf:type rdf:Property in DBpedia?” This is a pretty simple SPARQL query to write. Because I expected that there would be lots of properties in DBPedia, I first wrote a query to count how many there are, and afterward wrote a query to actually list them.
There are 48292 things in DBpedia declared to be of rdf:type rdf:Property, as reported by this SPARQL query, run against one of DBpedia's SPARQL endpoints:
select COUNT( ?property ) where {
?property a rdf:Property
}
SPARQL Results
You can get the list by selecting ?property instead of COUNT( ?property ):
select ?property where {
?property a rdf:Property
}
SPARQL Results
I second Joshua Taylor's answer, however if you want to limit the properties to the Dutch DBpedia, you need to change the default-graph-uri query parameter to nl.dbpedia.org and set the SPARQL endpoint to nl.dbpedia.org/sparql, as in the following query. You will get a result-set of just above 8000 elements.
SELECT DISTINCT ?pred WHERE {
?pred a rdf:Property
}
ORDER BY ?pred
run query
These are the Dutch translations of the properties that have been mapped from Wikipedia so far. The full English list is also available. According to mappings.dbpedia.org, there are ~1700 properties with missing Dutch translations.
I've forgotten all I once new about DBpedia and SPARQL and find all the examples too complex and hard to understand when I Google for them.
What I wish to do is pass in two or three Wikipedia pages and get back the set of Wikipedia categories that all of the pages are members of.
This seems that it should be utterly simple in SPARQL so I would appreciate a very minimal example to get me started.
This is actually a variation of your earlier question about getting all pages belonging to two categories. The only difference is that this time, you want two/three subjects rather than objects, so you cannot use a comma-separated enumeration of values, but instead have to write out the triple pattern that you want to match.
For example, to get back all categories that both Spain and Portugal belong to, you could simply do a query like this:
SELECT ?cat
WHERE {
<http://dbpedia.org/resource/Spain> dcterms:subject ?cat .
<http://dbpedia.org/resource/Portugal> dcterms:subject ?cat .
}
what this query does is select all triple patterns that have the same value of ?cat for the dcterms:subject relation for the subjects 'Spain' and 'Portugal'. In other words, it retrieves precisely those categories that both resources are a member of.
The trick is to think in terms of a graph, or triples with connected subjects and objects. It's a bit of a mental shift but once you've got that, query writing becomes a lot easier.
The mapping between wikipedia and dbpedia URI's is as follows:
For
http://en.wikipedia.org/wiki/Spain
DBPedia uri is:
http://dbpedia.org/resource/Spain
So to find out the categories for the above
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?categoryUri ?categoryName
WHERE {
<http://dbpedia.org/resource/Spain> dcterms:subject ?categoryUri.
?categoryUri rdfs:label ?categoryName.
FILTER (lang(?categoryName) = "en")
}
Consider the following script:
PREFIX category: <http://dbpedia.org/resource/Category:>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX dbpedia: <http://dbpedia.org/ontology/>
SELECT DISTINCT *
WHERE {
?s dcterms:subject category:Living_people .
?s foaf:name ?name
}
LIMIT 10000
When running it, I get something like this in result:
Sir Alexander Chapman Ferguson
Sir Alex Ferguson
Though they are different entries, they are definitely the same entities. So I would like to reduce the output when addressing the SPARQL endpoint, i.e. I would like to avoid editing output data because it may be challenging in this case. Could you help me with that? What should be fixed in my query?
As you see when you run your query, both the rows that you mention refer to the same resource: <http://dbpedia.org/resource/Alex_Ferguson>. The fact that you get multiple rows in your query result is simply because there are multiple names for this person.
So if you just need to ensure that you don't get duplicates in your application, simply make sure that your application treats each unique value for "s" in your query result as a separate person.
On the other hand, if your problem is the fact that you get multiple names for a person, you could perhaps use some other properties. For example, dbpedia:fullname only has a single entry, likewise the properties dbpedia:surname and dbpedia:givenName.