读取OSLC响应时出错&使用jena执行sparql

时间:2017-03-19 08:35:32

标签: sparql rdf jena clearquest oslc

我正在使用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读取数据

无法找出问题所在.. pl帮助..提前致谢:)

0 个答案:

没有答案