2015-04-20 12 views
5

utilizzando la seguente query:SPARQL ricerca di xsd: integer solo, senza decimali

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#> 
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> 
PREFIX uni: <http://localhost/SemanticSearch/semanticsearch.owl#> 

SELECT 
    DISTINCT * 
WHERE { 
    ?uri uni:altLabel "5"^^xsd:integer. 
    ?uri rdf:type ?type 
} 

restituisce anche URI che hanno un altLabel con xsd:decimal 5.x ho davvero bisogno per tornare solo il ?uri che hanno altLabel di xsd:integer. C'è comunque per raggiungere questo obiettivo?

risposta

4

È sempre più semplice se è possibile fornire dati reali che possiamo interrogare. In futuro, si prega di fornire dati che possiamo interrogare. perché allora possiamo effettivamente testare le richieste a riguardo. In ogni caso, ecco un set di dati molto semplice con due risorse, una con valore xsd: decimal e una con xsd: valore intero.

@prefix xsd: <http://www.w3.org/2001/XMLSchema#>. 
@prefix uni: <http://localhost/SemanticSearch/semanticsearch.owl#>. 
@prefix : <urn:ex:>. 

:a uni:altLabel "5"^^xsd:integer ; a :somethingWithAnInteger . 
:b uni:altLabel "5"^^xsd:decimal ; a :somethingWithADecimal . 

È possibile filtrare i tipi di dati particolari che si desidera utilizzare il tipo di dati funzione:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> 
PREFIX uni: <http://localhost/SemanticSearch/semanticsearch.owl#> 

SELECT DISTINCT * WHERE { 
    ?uri uni:altLabel ?altLabel . 
    ?uri rdf:type ?type 
    filter(?altLabel = "5"^^xsd:integer && datatype(?altLabel) = xsd:integer) 
} 

----------------------------------------------------------- 
| uri  | altLabel | type       | 
=========================================================== 
| <urn:ex:a> | 5  | <urn:ex:somethingWithAnInteger> | 
-----------------------------------------------------------