在 JENA virtuoso 的 SPARQL 查询中使用 BIND 时出现空指针异常错误



>我在运行SPARQL查询时出现以下错误,

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)

示例 TTL 文件数据

@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 .

我正在使用Virtuoso SPARQL端点来运行查询

这是我正在运行的代码。

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/>rn" + 
"PREFIX  ns:  <http://example.org/ns#>rn" + 
"rn" + 
"SELECT  ?title ?pricern" + 
"{  ?x ns:price ?p .rn" + 
"   ?x ns:discount ?discountrn" + 
"   BIND (?p*(1-?discount) AS ?price)rn" + 
"   FILTER(?price < 20)rn" + 
"   ?x dc:title ?title . rn" + 
"}";
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>

我在SPARQL查询中使用BIND时遇到了奇怪的问题。我不明白实际问题是什么,或者我不知道为什么会发生这种情况。此外,我正在使用Virtuoso进行图形数据存储,并且使用Jena lib来运行SPARQL查询。运行查询时出现错误。我在谷歌上没有找到任何解决方案。

正如@AKSW的评论中所揭示的那样,答案是

  1. 更新到当前的耶拿(可能还有当前的 Virtuoso 服务器 [无论是企业服务器还是开源服务器]、耶拿的 Virtuoso 提供程序和/或 Virtuoso JDBC 驱动程序(
  2. 使用正确的呼叫/查询配对(即,使用 SPARQLSELECT查询调用耶拿.execSelect(),或使用 SPARQLDESCRIBE查询调用耶拿.execDescribe()(。

最新更新