Can't execute a specific SPARQL query on DBPedia :/ - sparql

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.

Related

Matching two words together in sparql

How to List the laureate awards (given by their label) for which the description of the contribution (given by nobel:motivation) contains the word "human" together with the word "peace" (i.e., both words must be there).
I have use the bds:search namespace from the the full-text search feature of Blazegraph.
After visiting this link i have composed this query
Free text search in sparql when you have multiword and scaping character
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX bds: <http://www.bigdata.com/rdf/search#>
PREFIX nobel: <http://data.nobelprize.org/terms/>
SELECT ?awards ?description
WHERE {
?entity rdfs:label ?awards .
?entity nobel:motivation ?description .
FILTER ( bds:search ( ?description, '"human" AND "peace"' ) )
}
This query is returning me the following error on execution shown in image.
Error Image
How to correct this query and get the desired result?
You may take a look at the specification of this dataset or download an RDF dump of the dataset
Use bds:search to search for "human" category.Then apply filter and contain function to "peace".
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX bds: <http://www.bigdata.com/rdf/search#>
PREFIX nobel: <http://data.nobelprize.org/terms/>
PREFIX bif: <http://www.openlinksw.com/schemas/bif#>
SELECT ?awards ?description
WHERE {
?entity rdfs:label ?awards .
?entity nobel:motivation ?description .
?description bds:search "human" .
FILTER (CONTAINS(?description, "peace"))
}

How to query dbpedia.org with sparql

I'm very new in OpenData and try to write a query in SPARQL.
My goal is to get data for following set of criteria:
- Category: Home_automation
- select all items from type "Thing"
- with at least one entry in "is Product of"
- that have a picture-url with a German description
I tried the following:
PREFIX cat: <http://dbpedia.org/resource/Category:>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT *
WHERE {
cat:Home_automation skos:broader ?x
}
But now I don't know how to add the other filters to the where clause.
I tried to user broader:... to get the items, but I think that was the wrong direction.
I tested the queries with: https://dbpedia.org/sparql
The result should be:
| (label) | (url)
|--------------------------|-----------------------------------
|"Kurzzeitwecker"#de | urls to the picture of the device
|"Staubsauger"#de | -||-
|"Waschmaschine"#de | -||-
|"Geschirrspülmaschine"#de | -||-
Does anyone have some tips please?
UPDATE: new query:
PREFIX cat: <http://dbpedia.org/resource/Category:>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?s ?label WHERE {
?s ?p cat:Home_automation .
?s rdf:type owl:Thing .
?s rdfs:label ?label
FILTER (LANG(?label)='de')
}
order by ?p
It is not clear what you want. You must first know what exact related information dbpedia contains and how they are structured.
However, you can try discovering what types of relationships cat:Home_automation is involved in, thus, you may know better what you want.
I suggest starting by generic queries, to specify how cat:Home_automation occurs in dbpedia, then, you might be able to go more specific, and pose further queries.
A query to list triples where cat:Home_automation is an subject:
PREFIX cat: <http://dbpedia.org/resource/Category:>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT ?p ?o WHERE {
cat:Home_automation ?p ?o
}
order by ?p
A query to list triples where cat:Home_automation is an object:
PREFIX cat: <http://dbpedia.org/resource/Category:>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT ?s ?p WHERE {
?s ?p cat:Home_automation
}
order by ?p
check the results, see what is interesting for you, and then continue with further queries.

How to get all organisations from DBPedia?

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

Virtuoso SPARQL query unable to compare float constants

I have a local copy of DBpedia 2014 loaded onto Virtuoso 7.1. I run the following query:
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?o, datatype(?o)
WHERE {
<http://dbpedia.org/resource/Caesar_Creek_State_Park> <http://www.w3.org/2003/01/geo/wgs84_pos#long> ?o .
}
obtaining the following result:
o callret-1
-84.0653 http://www.w3.org/2001/XMLSchema#float
-84.0139 http://www.w3.org/2001/XMLSchema#float
I now execute the (seemingly true) query:
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
ASK
WHERE {
<http://dbpedia.org/resource/Caesar_Creek_State_Park> <http://www.w3.org/2003/01/geo/wgs84_pos#long> "-84.0139"^^<http://www.w3.org/2001/XMLSchema#float> .
}
where the return value is false!
Next I try ensuring the float value with a FILTER:
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?o
WHERE {
<http://dbpedia.org/resource/Caesar_Creek_State_Park> <http://www.w3.org/2003/01/geo/wgs84_pos#long> ?o .
FILTER ( datatype(?o) = xsd:float )
}
This returns:
o
-84.0653
-84.0139
Which is good. Next, I try to sneak in an extra triple pattern into the previous query:
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?o
WHERE {
<http://dbpedia.org/resource/Caesar_Creek_State_Park> <http://www.w3.org/2003/01/geo/wgs84_pos#long> ?o .
<http://dbpedia.org/resource/Caesar_Creek_State_Park> <http://www.w3.org/2003/01/geo/wgs84_pos#long> "-84.0139"^^<http://www.w3.org/2001/XMLSchema#float> .
FILTER ( datatype(?o) = <http://www.w3.org/2001/XMLSchema#float> )
}
which returns empty!
Sadly, the online endpoint at lod.openlinksw.com/sparql doesn't have latitudes and longitudes loaded, so I wasn't able to replicate the problem for you to see first-hand.
Any suggetions? My main question is: how can I place a literal float in a triple pattern of a query in order to obtain a match?
I'm pretty sure that Virtuoso is rounding or truncating the value when it's printing the value. As a very simple example that you can run on the public DBpedia endpoint (which runs Virtuoso):
select ?x, (str(?x) as ?sx) {
values ?x {
"1.11111"^^xsd:float
"1.11115"^^xsd:float
"1.11119"^^xsd:float
}
}
SPARQL Results
x sx
--------------------------
1.11111 1.111109972000122
1.11115 1.111150026321411
1.11119 1.111189961433411
If you want to compare exact values, you'll probably want to extract those string forms and look for them explicitly.
And of course, there's the obligatory link to What Every Computer Scientist Should Know About Floating-Point Arithmetic

SPARQL queries for Pizza ontology

i have to use ROWLKit
http://www.dis.uniroma1.it/quonto/?q=node/30
(1) can anybody suggest two sparql queries for the Pizza.owl ?
(2) is this query valid ?
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX pizza: <http://www.co-ode.org/ontologies/pizza/pizza.owl#>
SELECT *
WHERE { ?p rdf:type pizza:Pizza;
pizza:hasTopping ?t.
?t rdf:type pizza:TomatoTopping }
(3) if it is a valid query then: is the response an empty result?
SELECT DISTINCT *
WHERE {
?NombrePizza ?Relacion pizza:MushroomTopping .
?Relacion owl:inverseOf pizza:isToppingOf .
OPTIONAL {
?NombrePizza2 ?Relacion2 pizza:HamTopping .
?Relacion2 owl:inverseOf pizza:isToppingOf .
}
FILTER(?NombrePizza2 = ?NombrePizza)
}
(1) can anybody suggest two sparql queries for the Pizza.owl ?
Here are two examples:
SELECT * WHERE { ?s ?p ?o }
and:
SELECT ?class WHERE { ?class a owl:Class }
(2) is this query valid ?
Yes.
(3) if it is a valid query then: is the response an empty result?
I assume that you mean "if I query the RDF document that serialises the pizza ontology, is the response an empty result?". The answer is yes.
(2) appears to be a valid query
I don't understand part (3) of your question. (2) cannot be compared to a boolean since it returns a Result Set, if you want a boolean result then you need to use an ASK query. If an ASK query returns true then it means that there are solutions to the query in the data you are querying so it would not be an empty result.