Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SPARQL Type Conversion?

I have the following SPARQL query:

PREFIX ssn: <http://purl.oclc.org/NET/ssnx/ssn#> 
PREFIX dtp: <http://dtp-126.sncs.abdn.ac.uk#> 
PREFIX dbp: <http://dbpedia.org/resource/> 
SELECT ?value ?time WHERE {         
    dtp:CD7514 ssn:madeObservation ?observation .       
    ?observation ssn:observedProperty ?property .   
    ?property ssn:hasValue <http://dbpedia.org/resource/Temperature> .          
    ?observation ssn:observationResult ?observationValue .      
    ?observationValue ssn:hasValue ?value .         
    ?observationValue ssn:observationSamplingTime ?time 
    FILTER(?time > 1291908000)
}

Which, in a nutshell, is selecting all temperature sensor observations from a sensor, dtp:CD7514, and filtering out values less than the given timestamp.

However, adding the filter constraint returns 0 results (when there are observations that match this time region!)

Is it possible that ?time is a varchar/text/String data type and therefore the comparison can't be done? If so, is it possible to do the conversion within SPARQL?

like image 854
Bailz Avatar asked Dec 14 '10 12:12

Bailz


People also ask

What types of queries does SPARQL support?

SPARQL contains capabilities for querying required and optional graph patterns along with their conjunctions and disjunctions. SPARQL also supports aggregation, subqueries, negation, creating values by expressions, extensible value testing, and constraining queries by source RDF graph.

What is SPARQL in Semantic Web?

SPARQL, pronounced 'sparkle', is the standard query language and protocol for Linked Open Data on the web or for RDF triplestores. SPARQL, short for “SPARQL Protocol and RDF Query Language”, enables users to query information from databases or any data source that can be mapped to RDF.

What is optional SPARQL?

OPTIONAL is a binary operator that combines two graph patterns. The optional pattern is any group pattern and may involve any SPARQL pattern types. If the group matches, the solution is extended, if not, the original solution is given (q-opt3. rq).


2 Answers

That's only going to work if the time value you're matching has the same number of digits, as it will do a strong compare. A better fix would be:

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
...
FILTER(xsd:integer(?time) > 1291908000)

That will cast the value in ?time to an integer, and then do a numeric compare on it.

like image 129
Steve Harris Avatar answered Oct 04 '22 22:10

Steve Harris


The solution to this was merely to add quotes around the timestamp.

like image 30
Bailz Avatar answered Oct 04 '22 21:10

Bailz