I want to get provenance data in DBpedia and here's the sample query:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT DISTINCT ?novel
WHERE {
?novel rdf:type dbo:Novel
} LIMIT 1000 OFFSET 0
This query returns list of novels' resource. How can I get provenance data for each resource, if it's possible?
For example In Ballast to the White Sea originated from Source A, Source A originated from Source B, Source B is originated from Source C, and so on.
You can only use current provenance data existing in the dataset which is declared by prov:wasDerivedFrom property. It gives info about the source(wikipedia page) triples are extracted from. So you can pose such a query:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX prov: <https://www.w3.org/ns/prov#>
SELECT DISTINCT ?novel ?prov
WHERE {
?novel rdf:type dbo:Novel.
?novel prov:wasDerivedFrom ?prov
} LIMIT 1000 OFFSET 0
Related
I have a problem in displaying the result using SPARQL in protege.
I have two classes Panne and Solution and an ObjectProperty hasSolution .
I want to display the Panne that has A Solution ex: GODEX hasSolution SOLGODEX.
I tried
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX panne:<http://www.semanticweb.org/rahma/ontologies/2020/pannesOnto.owl#>
SELECT ?Panne ?Solution
WHERE {
?Panne panne:hasSolution ?Solution}
Without knowing your specific ontology structure, the following will likely need some adaptations.
Currently your query selects all subjects and objects involved in a tuple using panne:hasSolution.
If you want to filter down to only those of a specific solution, you have to include that in the query:
SELECT ?Panne
WHERE {
?Panne panne:hasSolution ex:SOLGODEX .
}
If you want all pairs of panne:Panne and panne:Solution, add the respective patterns to select only members ot those classes:
SELECT ?Panne ?Solution
WHERE {
?Panne a panne:Panne .
?Solution a panne:Solution .
?Panne panne:hasSolution ?Solution .
}
I am new to querying DBPedia using Sparql. I would like to find people related to a person X using DBPedia.
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbpr: <http://dbpedia.org/resource/>
PREFIX dbpo: <http://dbpedia.org/ontology/>
PREFIX dbpprop: <http://dbpedia.org/property/>
SELECT ?P
WHERE {dbpr:Chuck_Norris}
In case you want the people directly related to a person, then you need two triple patterns, one having the person as a subject and another as an object. Here is one way to construct such a query:
SELECT DISTINCT ?has ?of ?person
WHERE {
{?person a foaf:Person;
?of dbr:Chuck_Norris}
UNION
{?person a foaf:Person.
dbr:Chuck_Norris ?has ?person}
}
I'm using dbr: as this is a predefined prefix in DBpedia.
In some cases, you'll get different results if you query on http://live.dbpedia.org/sparql
Now, this query has a limitation. It will get you only relations to other DBpedia resources. Quite often there might be related persons asserted as literals. I don't know of an elegant way to get them, but one way would be to ask for a list of properties that are known to be used for person relations. Here is an example with a list with one value for dbp:spouse:
SELECT DISTINCT ?has ?of ?person
WHERE {
{?person a foaf:Person;
?of dbr:Chuck_Norris}
UNION
{?person a foaf:Person.
dbr:Chuck_Norris ?has ?person}
UNION
{values ?has {dbp:spouse}
dbr:Chuck_Norris ?has ?person .}
}
From http://live.dbpedia.org/sparql this will bring you additionally:
has | person
---------------------------------------------------------
http://dbpedia.org/property/spouse | "Dianne Holechek"#en
http://dbpedia.org/property/spouse | "Gena O'Kelley"#en
---------------------------------------------------------
In general asking for literals like that will bring you a lot of garbage results, which you can reduce using string filters.
How can I get a list of all organisations from DBpedia?
By "organisation", I mean a entity of any type that is either a organisation or any subclass of organisation.
I found the question How to get all companies from DBPedia? but this doesn't work in the current DBpedia SPARQL web version and I wasn't able to adapt the query.
To simply get all resources that are an instance of dbo:Organization or its subclass:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT DISTINCT ?org { ?org a/rdfs:subClassOf* dbo:Organisation . }
However, as the question you linked shows, DBpedia has a cap on how many results are returned. So, as in the answer to said question, you can use a subquery with LIMIT and OFFSET to get all the results in chunks:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT ?org {
SELECT DISTINCT ?org {
?org a/rdfs:subClassOf* dbo:Organisation .
} ORDER BY ?org
}
LIMIT 10000 OFFSET 0
This would get you the first 10000 results. To get the next 10000, just add 10000 to the offset: LIMIT 10000 OFFSET 10000. Then, the next 10000 with OFFSET 20000, and so on.
You can get all organisations with a query like this, giving you English label and Wikipedia page for those resources that have it:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX o: <http://dbpedia.org/ontology/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT DISTINCT ?orgURI ?orgName ?Wikipedia_page
WHERE {
?orgURI a o:Organisation .
OPTIONAL { ?orgURI rdfs:label ?orgName .
FILTER (lang(?orgName) = "en") }
OPTIONAL { ?orgURI ^foaf:primaryTopic ?Wikipedia_page }
}
ORDER BY ?orgName
This will currently return 350033 results for those resources that are classified as http://dbpedia.org/ontology/Organisation.
To get also the members of subclasses of http://dbpedia.org/ontology/Organisation, you can change the first pattern by turning the property into a property path going though zero or more rdfs:subClassOf:
?orgURI a/rdfs:subClassOf* o:Organisation
Please help to list all Mealcourse from the wine Ontology or happy to receive useful links like this one :Sparql query on restriction list (Equivalent To) in protégé
MealCourse
and (hasFood value Pizza)
and(hasDrink value Wine)
Thank you
This is a bit complicated, but if you look into the ontology everything that is defined as a :MealCourse is an owl:equivalentClass, so you need to first find all owl:equivalentClass and then if you look into the result you will see that they are made of owl:intersectionOf parts. Then you need to break this intersection and filter so that you will only get objects that have :MealCourse as part of the intersection.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
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 : <http://www.w3.org/TR/2003/PR-owl-guide-20031209/food#>
SELECT distinct *
WHERE { ?subject owl:equivalentClass ?object.
?object (owl:intersectionOf | owl:unionOf) ?node.
?node rdf:rest*/rdf:first ?eq.
Filter ( ?eq in (:MealCourse ) )
}
orderBy ?subject
On this site, for example, take the first SPARQL query and make something very similar:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX p: <http://dbpedia.org/property/>
SELECT *
WHERE {
?name p:name <http://dbpedia.org/resource/Olivier_Theyskens> .
}
Try to execute it: here
And I get no results. However, modify the query to the following:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX p: <http://dbpedia.org/property/>
SELECT *
WHERE {
?name p:name ?otherthing.
}
And I get results, even though they're not the results I want.
Why doesn't the first query work -- what am I doing wrong? :/
In this case, I think it's because you're ordering your query statement backwards.
The DBpedia resource (<http://dbpedia.org/resource/Olivier_Theyskens>) is the Entity or Subject (?s), the property (p:name) is the Attribute or Predicate (?p), and the value of that property (?name) is the Value or Object (?o).
SPARQL expects all statements to be { ?s ?p ?o }, but yours seems to be written as { ?o ?p ?s }...
To sum up, if you try this query --
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX p: <http://dbpedia.org/property/>
SELECT *
WHERE
{
<http://dbpedia.org/resource/Olivier_Theyskens> p:name ?name .
}
-- you'll get the results I think you want.
The problem with your first query is that p:name links to Literal and you try to match a URI.
If you want your first query to work you have to to use the property http://dbpedia.org/ontology/artist that links to the URI and not the literal:
SELECT *
WHERE {
?s <http://dbpedia.org/ontology/artist> <http://dbpedia.org/resource/The_Velvet_Underground> .
}
Notice the different name space for the property <http://dbpedia.org/ontology/artist> this namespace contains ontology instead of property - ontology is the one used for object properties.