-3

My owl file is

 ....
<filePeakHour rdf:datatype="http://www.w3.org/2001/XMLSchema#int"
>16</filePeakHour>
...

I want to create query that retireve SUBJECT where FilePeakHour is 16.

For this, When I run below query in Protege SparqlPlugin, it runs ok

SELECT ?x
WHERE { ?x <http://www.semanticweb.org/administrator/ontologies/2014/2/untitled-ontology-5#filePeakHour>"16"^^xsd:int }

But when I convert it to Jena format

    String queryString = 
    "SELECT ?x WHERE { ?x <http://www.semanticweb.org/administrator/ontologies/2014/2/untitled-ontology-5#filePeakHour>\"16\"^^xsd:int }";

it return errors:

Exception in thread "main" com.hp.hpl.jena.query.QueryParseException: Line 1, column 121: Unresolved prefixed name: xsd:int
at com.hp.hpl.jena.sparql.lang.ParserBase.throwParseException(ParserBase.java:661)
at com.hp.hpl.jena.sparql.lang.ParserBase.resolvePName(ParserBase.java:274)
at com.hp.hpl.jena.sparql.lang.sparql_11.SPARQLParser11.PrefixedName(SPARQLParser11.java:4888)
at com.hp.hpl.jena.sparql.lang.sparql_11.SPARQLParser11.iri(SPARQLParser11.java:4872)
at com.hp.hpl.jena.sparql.lang.sparql_11.SPARQLParser11.RDFLiteral(SPARQLParser11.java:4704)

How to retrieve xsd:int value from owl file in Jena

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
  • possible duplicate of [Unresolved prefixed name: rdfs:subClassOf in SPARQL query](http://stackoverflow.com/questions/9782441/unresolved-prefixed-name-rdfssubclassof-in-sparql-query) – Joshua Taylor Jul 27 '14 at 21:53
  • 1
    It says right in the exception message "Unresolved prefixed name: xsd:int". You need to define the prefix for xsd: with `prefix xsd: ` at the beginning of your query. The linked duplicate was easy to find by searching for the error message "unresolved prefix name". -1 for lack of research effort. – Joshua Taylor Jul 27 '14 at 21:54
  • Also, there's no need to put tag names ([tag:jena] and [tag:sparql]) in the question title; that's what the tags are for. – Joshua Taylor Jul 27 '14 at 21:55

1 Answers1

2

Reading the message of the exception, it seems like you should define the prefix in the query:

PREFIX xsd:   <http://www.w3.org/2001/XMLSchema#>
SELECT ?x
WHERE { ?x <http://www.semanticweb.org/administrator/ontologies/2014/2/untitled-ontology-5#filePeakHour> "16"^^xsd:int }

Other common namespaces you'll probably use and their IRIS can be found in 1.2.1 Namespaces from SPARQL Query Language for RDF. The query validator at sparql.org also includes a bunch. There's a searchable listing of common prefixes for RDF at prefix.cc, too.

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
sergioFC
  • 5,926
  • 3
  • 40
  • 54