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
Related
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 can I retrieve a min constraint on a class' attribute using sparql? I have value min 1000 decimal, and I would like to get 1000
In a hypothetical world that you have such a statement:
Class: X subClassOf: hasObjectProperty min 1 Y
If you write a SPARQL query as:
SELECT *
WHERE {
?s rdfs:subClassOf ?o.
}
You must extract all the refs:subClassOf axioms. However, if you need to precise and know which ones have cardinality restrictions, you need to go further:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix : <http://example.com#>
SELECT *
WHERE {
?s rdfs:subClassOf ?o.
?o ?x ?y.
filter(?s = :X)
}
Among others, you can see the following result:
As you can see, there are 2 relevant items, one is Y and one is the number presented as a non-negative integer. Therefore, one way to get each item is to put a filter for ?x in the SPARQL query and get each one one by one out. For example, filter owl:onClass will give you ?y:
prefix : <http://example.com#>
SELECT *
WHERE {
?s rdfs:subClassOf ?o.
?o owl:onClass ?y.
filter(?s = :X)
Here is the sparql query I used following Artemis' answer
SELECT ?min
WHERE {?s rdfs:subClassOf ?o.
?o owl:minQualifiedCardinality ?min.
FILTER(?s = :value) }
And with jena, I use getLiteral("min").getFloat();
Basically I got a SPARQL query below which works with the arq 2.8.8 but doesn't work with arq2.8.4 as it doesnt recognise the + symbol. I really want a query which can work on the arq 2.8.4 version which is similar to the one I posted. The query I posted basically finds all items which are the sameas each other. For eg if a is the sameas b and b is the sameas c, the query returns both b and c for a.
PREFIX owl: <http://www.w3.org/2002/07/owl#> SELECT * WHERE { ?x owl:sameas+ ?y }
The feature you are using is SPARQL 1.1 and so was not supported by earlier versions of ARQ. The only way you can write a query that gets close to what you do is to do one of the following.
Union paths of different lengths
PREFIX owl: <http://www.w3.org/2002/07/owl#>
SELECT *
WHERE
{
{ ?x owl:sameAs ?y }
UNION
{ ?s owl:sameAs [ owl:sameAs ?y ] . }
UNION
{ ?s owl:sameAs [ owl:sameAs [ owl:sameAs ?y ] ] . }
# Repeat the above pattern up to whatever limit you want
}
Use client side code
Issue an initial query as follows:
PREFIX owl: <http://www.w3.org/2002/07/owl#>
SELECT * WHERE { ?x owl:sameAs ?y }
Make a list of ?y values, then for each value issue a query of the form:
PREFIX owl: <http://www.w3.org/2002/07/owl#>
SELECT * WHERE { <constant> owl:sameAs ?y }
Where you substitute <constant> for one of the values from the list each time and then add the new values of ?y to the list.
Only thing you need to be careful of with this approach is that you keep track of values for which you've already issued the second query to save you repeating queries.
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.
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.