【问题标题】:Parsing quads with nxparser使用 nxparser 解析四边形
【发布时间】:2015-03-09 16:02:15
【问题描述】:

我正在尝试使用 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> .

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

【问题讨论】:

  • 您正在使用 RDF/XML 解析器来解析 n-quad——这是一种完全不同的格式。您注释掉的位在正确的行上。
  • 非常感谢。我什至没有意识到:)
  • 我会填写您已经使用 apache jena 的内容——除非您出于某种原因真的需要 NXParser?

标签: eclipse parsing rdf n-triples


【解决方案1】:

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

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 可以做你想做的事,但这是处理流的最通用方法。

【讨论】:

  • NxParser nxp = new NxParser(in);这也是寻找它的人的 nxparser 解决方案。你的观点正是我想要的!
猜你喜欢
  • 1970-01-01
  • 2017-04-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多