1

I am getting below error while running SPARQL query,

ERROR [main] (RDFDefaultErrorHandler.java:40) - (line 7 column 7): {E201} The attributes on this property element, are not permitted with any content; expecting end element tag.
ERROR [main] (RDFDefaultErrorHandler.java:40) - (line 7 column 38): {E201} XML element <res:binding> inside an empty property element, whose attributes prohibit any content.
ERROR [main] (RDFDefaultErrorHandler.java:40) - (line 7 column 52): {E201} XML element <res:variable> inside an empty property element, whose attributes prohibit any content.
ERROR [main] (RDFDefaultErrorHandler.java:40) - (line 7 column 57): {E201} The attributes on this property element, are not permitted with any content; expecting end element tag.
 WARN [main] (RDFDefaultErrorHandler.java:36) - (line 8 column 135): {W102} unqualified use of rdf:datatype is deprecated.
java.lang.NullPointerException
    at com.hp.hpl.jena.rdf.arp.impl.XMLHandler.endElement(XMLHandler.java:149)
    at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
    at org.apache.xerces.impl.XMLNamespaceBinder.handleEndElement(Unknown Source)
    at org.apache.xerces.impl.XMLNamespaceBinder.endElement(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
    at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    at com.hp.hpl.jena.rdf.arp.impl.RDFXMLParser.parse(RDFXMLParser.java:142)
    at com.hp.hpl.jena.rdf.arp.JenaReader.read(JenaReader.java:158)
    at com.hp.hpl.jena.rdf.arp.JenaReader.read(JenaReader.java:145)
    at com.hp.hpl.jena.rdf.arp.JenaReader.read(JenaReader.java:215)
    at com.hp.hpl.jena.rdf.model.impl.ModelCom.read(ModelCom.java:197)
    at com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP.execModel(QueryEngineHTTP.java:169)
    at com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP.execDescribe(QueryEngineHTTP.java:162)
    at com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP.execDescribe(QueryEngineHTTP.java:160)
    at com.hospital.SPARQLQuery.main(SPARQLQuery.java:34)

Sample TTL file data

@prefix dc:   <http://purl.org/dc/elements/1.1/> .
@prefix :     <http://example.org/book/> .
@prefix ns:   <http://example.org/ns#> .

:book1  dc:title     "SPARQL Tutorial" .
:book1  ns:price     42 .
:book1  ns:discount  0.2 .

:book2  dc:title     "The Semantic Web" .
:book2  ns:price     23 .
:book2  ns:discount  0.25 .

I am using the Virtuoso SPARQL endpoint to run a query

here is my code which i am running.

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.rdf.model.Model;


public class SPARQLQuery {

    private static final Logger logger = LogManager.getLogger(SPARQLQuery.class);

    public static void main(String[] args) {

        try {
            String queryString = "PREFIX  dc:  <http://purl.org/dc/elements/1.1/>\r\n" + 
                    "PREFIX  ns:  <http://example.org/ns#>\r\n" + 
                    "\r\n" + 
                    "SELECT  ?title ?price\r\n" + 
                    "{  ?x ns:price ?p .\r\n" + 
                    "   ?x ns:discount ?discount\r\n" + 
                    "   BIND (?p*(1-?discount) AS ?price)\r\n" + 
                    "   FILTER(?price < 20)\r\n" + 
                    "   ?x dc:title ?title . \r\n" + 
                    "}";

            QueryExecution qexec = QueryExecutionFactory.sparqlService("http://localhost:8890/sparql", queryString);
            Model results = qexec.execDescribe();

            results.write(System.out,"TTL");

        }catch(Exception ex) {
            ex.printStackTrace();
        }
    }
}

Maven dependency

<dependency>
    <groupId>com.hp.hpl.jena</groupId>
    <artifactId>arq</artifactId>
    <version>2.8.8</version>
</dependency>

I am facing strange issue while using BIND in my SPARQL query. I don't understand what's the actual problem or I can't figure out why this is happening. Also, I am using the Virtuoso for graph data store and I am using Jena lib for running the SPARQL query. While running the query I am getting error.I didn't find any solution on google.

vimalDev
  • 412
  • 1
  • 4
  • 25
  • 3
    1) You're using an ancient version of Jena... 2) you're executing a `SELECT` query but calling `.execDescribe()` - may I ask why? Obviously, you have to a) call `.execSelect()` or b) use a SPARQL `DESCRIBE` query. Clearly, In case of a), you won't get RDF back and it's not possible to write `TURTLE` to disk given that you'Re selecting just two variables. – UninformedUser May 11 '18 at 10:12
  • Ohh that was the exact issue Thanks @AKSW can you please provide which is the latest Jena version or dependency – vimalDev May 11 '18 at 10:18
  • 1
    For the future, any search engine would answer this faster than me. To be even more precise, there is [a Maven repository](https://mvnrepository.com/artifact/org.apache.jena/jena-arq) that allows for searching. And of course, the [official Apache Jena documentation](https://jena.apache.org/download/index.cgi) are free to use for everybody that has access to the internet. By the way, it contains tutorials for almost everything you need, together with the RDF/SPARQL W3C recommendations, you should be able to solve any further task w.r.t. Semantic Web querying – UninformedUser May 11 '18 at 10:24
  • Thanks for your answer you are right I am using the very old version of Jena.Also sorry for the wasting your time. yes, of course, I need to google for it without asking to you.bdw thanks again your suggestion for the using latest version of Jena solve my other issue also. Thanks again. – vimalDev May 11 '18 at 10:32
  • May I ask you why you did use such an old version? Did you copy the Maven snippet from an older online example? – UninformedUser May 12 '18 at 07:56
  • @AKSW yes maybe I have copied the old example from somewhere. – vimalDev May 14 '18 at 05:59

1 Answers1

2

As revealed in comments by @AKSW, answer is to

  1. update to current Jena (and possibly current Virtuoso server [whether Enterprise or Open Source], Virtuoso Provider for Jena, and/or Virtuoso JDBC driver)
  2. use correct call/query pairing (i.e., call Jena .execSelect() with a SPARQL SELECT query, or call Jena .execDescribe() with a SPARQL DESCRIBE query).
TallTed
  • 9,069
  • 2
  • 22
  • 37