使用 nxparser 解析四边形

Parsing quads with nxparser

我正在尝试在 Eclipse 中使用 Nxparser 通过以下代码解析四边形。

String FileInput="c://ex.nq";
    System.out.println("Adding "+FileInput);
    // use the FileManager to find the input file
    InputStream in = FileManager.get().open(FileInput);

    if (in == null) {
        throw new IllegalArgumentException("File: " + FileInput+ " not found");
    }
    //InputStream inS = RDFDataMgr.read(dsg, in, Lang.NQ);
    //RDFDataMgr.loadDataset("c://examples.nq", Lang.NQ);
    RDFXMLParser nxp=new RDFXMLParser(in, log4jConfPath); //"http://myuri"


      while (nxp.hasNext()) {
        Node[] ns = nxp.next();

        for (Node n: ns) {
          System.out.print(n.toString());
          System.out.print(" ");
        }
        System.out.println(".");

      }

通常情况下,解析器表明它能够解析N-Quads。尽管它读取三元组,但当我放置四元组文件 (ex.nq) 时,出现以下错误:

org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 7; Element or attribute do not match QName production: QName::=(NCName':')?NCName. 
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLEntityScanner.scanQName(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(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.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl.parse(Unknown Source)
at javax.xml.parsers.SAXParser.parse(Unknown Source)
at org.semanticweb.yars2.rdfxml.ParserThread.run(Unknown Source)

我正在使用的文件是 "ex.nq",里面有以下四边形:

<http://richard.cyganiak.de/foaf.rdf#RC> <http://xmlns.com/foaf/0.1/mbox> <mailto:richard@cyganiak.de> <http://example/2001-10-26_21-32-52> .

我不确定是文件有问题还是其他问题。任何帮助,将不胜感激。

根据注释掉的位,我认为你很接近。

String fileInput="c://ex.nq";

StreamRDF streamHandler = new StreamRDF() {
        @Override void base(String base) {};
        @Override void start() {};
        @Override void finish() {};
        @Override void prefix(String prefix, String iri) {};

        @Override void quad(Quad quad) {
            // Do something with your quad here
        }
        @Override void triple(Triple triple) {
            // Do something with your triple here
        }
};

TypedInputStream in = RDFDataMgr.open(fileInput);

if (in == null) {
    throw new IllegalArgumentException("File " + fileInput + " not found");
}

RDFDataMgr.parse(streamHandler, in);

有许多 predefined stream handlers 可以满足您的需求,但这是处理流的最通用方式。