eclipseparsingrdfn-triples

Parsing quads with nxparser


I am trying to parse quads with following piece of code using Nxparser in Eclipse.

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(".");

      }

Normally, parser indicates that it is able to parse N-Quads. Even though, it reads the triples, when I put a quad file (ex.nq) I have the following error:

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)

The file I am using is "ex.nq" and inside I have the following quad:

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

I am not sure if I have problem with file or something else. Any help would be appreciated.


Solution

  • I think you were close, based on the commented out bits.

    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);
    

    There are a number of predefined stream handlers that may do what you want, but this is the most general way to handle streams.