0

我正在使用 OSLC V2.0 从 clearquest(作为 RDF)获取数据,将其保存为“.rdf”文件并使用 Apache-Jena 对该文件执行 sparql 查询。

来自 OSLC 响应的数据:

<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:oslc="http://open-services.net/ns/core#"
    xmlns:cq="http://www.ibm.com/xmlns/prod/rational/clearquest/1.0/"
    xmlns:dcterms="http://purl.org/dc/terms/" xmlns:oslc_cm="http://open-services.net/ns/cm#">
    <oslc:ResponseInfo rdf:about="...">
        <dcterms:title>....</dcterms:title>
        <oslc:totalCount>10</oslc:totalCount>
    </oslc:ResponseInfo>
    <rdf:Description rdf:about=".....">
        <cq:user>
         .......
            <cq:vehicle>
                <cq:type>bike</cq:type>
            </cq:vehicle>
            <cq:vehicle>
                <cq:type>car</cq:type>
            </cq:vehicle>
            <cq:vehicle>
               <cq:type>bike</cq:type>
               <cq:type>car</cq:type>
            </cq:vehicle>
          .......
        </cq:user>
        .......
         other user records
        .......
    </rdf:Description>
</rdf:RDF>

代码片段:

InputStream in = new FileInputStream(../../oslc_output.rdf);
Model model = ModelFactory.createDefaultModel();
model.read(in,null);
//model.read(in, "RDF/XML"); - this also didn't work
in.close();

Query query = QueryFactory.create(sparqlQuery);
QueryExecution qe = QueryExecutionFactory.create(query, model);
ResultSet results = qe.execSelect();

当我尝试对此数据执行 SPARQL 时,出现以下错误

        org.apache.jena.riot.RiotException: [line: xxx, col: yyy] {E201} Multiple children of property element
at org.apache.jena.riot.system.ErrorHandlerFactory$ErrorHandlerStd.error(ErrorHandlerFactory.java:128)
at org.apache.jena.riot.lang.LangRDFXML$ErrorHandlerBridge.error(LangRDFXML.java:232)
at org.apache.jena.rdfxml.xmlinput.impl.ARPSaxErrorHandler.error(ARPSaxErrorHandler.java:37)
at org.apache.jena.rdfxml.xmlinput.impl.XMLHandler.warning(XMLHandler.java:196)
at org.apache.jena.rdfxml.xmlinput.impl.XMLHandler.warning(XMLHandler.java:173)
at org.apache.jena.rdfxml.xmlinput.impl.XMLHandler.warning(XMLHandler.java:168)
at org.apache.jena.rdfxml.xmlinput.impl.ParserSupport.warning(ParserSupport.java:207)
at org.apache.jena.rdfxml.xmlinput.states.Frame.warning(Frame.java:55)
at org.apache.jena.rdfxml.xmlinput.states.WantLiteralValueOrDescription.startElement(WantLiteralValueOrDescription.java:38)
at org.apache.jena.rdfxml.xmlinput.impl.XMLHandler.startElement(XMLHandler.java:111)
at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
at org.apache.xerces.impl.XMLNamespaceBinder.handleStartElement(Unknown Source)
at org.apache.xerces.impl.XMLNamespaceBinder.startElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(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 org.apache.jena.rdfxml.xmlinput.impl.RDFXMLParser.parse(RDFXMLParser.java:150)
at org.apache.jena.rdfxml.xmlinput.ARP.load(ARP.java:118)
at org.apache.jena.riot.lang.LangRDFXML.parse(LangRDFXML.java:134)
at org.apache.jena.riot.RDFParserRegistry$ReaderRIOTLang.read(RDFParserRegistry.java:178)
at org.apache.jena.riot.RDFDataMgr.process(RDFDataMgr.java:859)
at org.apache.jena.riot.RDFDataMgr.read(RDFDataMgr.java:259)
at org.apache.jena.riot.RDFDataMgr.read(RDFDataMgr.java:245)
at org.apache.jena.riot.adapters.RDFReaderRIOT.read(RDFReaderRIOT.java:69)
at org.apache.jena.rdf.model.impl.ModelCom.read(ModelCom.java:275)

按照OSLC V2.0如果没有使用 Accept 标头或 rcm.contentType 请求内容类型,则返回 RDF/XML。

以下其中一项有问题
1. 来自 Clearquest 的 RDF/XML 响应
2. 将其保存为“.rdf”文本
3. 使用 apache jena 读取数据

无法发现问题出在哪里..请帮助..提前谢谢:)

4

0 回答 0