Examples of RDFParser


Examples of org.openrdf.rio.RDFParser

            ExtractionContext extractionContext,
            InputStream in,
            ExtractionResult extractionResult
    ) throws IOException, ExtractionException {
        try {
            final RDFParser parser = getParser(extractionContext, extractionResult);
            parser.parse(in, extractionContext.getDocumentURI().stringValue());
        } catch (RDFHandlerException ex) {
            throw new IllegalStateException("Unexpected exception.", ex);
        } catch (RDFParseException ex) {
            throw new ExtractionException("Error while parsing RDF document.", ex, extractionResult);
        }
View Full Code Here

Examples of org.openrdf.rio.RDFParser

     * @return <code>true</code> if <i>Turtle</i> patterns are detected, <code>false</code> otherwise.
     * @throws IOException
     */
    public static boolean checkTurtleFormat(InputStream is) throws IOException {
        String sample = extractDataSample(is, '.');
        RDFParser turtleParser = Rio.createParser(RDFFormat.TURTLE);
        turtleParser.setDatatypeHandling(RDFParser.DatatypeHandling.VERIFY);
        turtleParser.setStopAtFirstError(true);
        turtleParser.setVerifyData(true);
        ByteArrayInputStream bais = new ByteArrayInputStream( sample.getBytes() );
        try {
            turtleParser.parse(bais, "");
            return true;
        } catch (Exception e) {
            return false;
        }
    }
View Full Code Here

Examples of org.openrdf.rio.RDFParser

            ExtractionContext extractionContext,
            InputStream in,
            ExtractionResult extractionResult
    ) throws IOException, ExtractionException {
        try {
            final RDFParser parser = getParser(extractionContext, extractionResult);
            parser.parse(in, extractionContext.getDocumentURI().stringValue());
        } catch (RDFHandlerException ex) {
            throw new IllegalStateException("Unexpected exception.", ex);
        } catch (RDFParseException ex) {
            throw new ExtractionException("Error while parsing RDF document.", ex, extractionResult);
        }
View Full Code Here

Examples of org.openrdf.rio.RDFParser

                }
            } finally {
                stream.close();
            }
        } else {
            RDFParser parser = null;
            if ("rdfxml".equals(lang)) {
                parser = new RDFXMLParser(r.getValueFactory());
            } else if ("n3".equals(lang) || "turtle".equals(lang)) {
                parser = new TurtleParser(r.getValueFactory());
            } else if ("ntriples".equals(lang)) {
                parser = new NTriplesParser(r.getValueFactory());
            }
           
            try {
              SailConnection c = null;
              try {
                  c = sail.getConnection();
                  BNodeConverterStatementHandler handler = new BNodeConverterStatementHandler(c);
 
                  parser.setRDFHandler(handler);
                  parser.setParseErrorListener(new LoggingParseErrorListener(sourceURL));
                  parser.setVerifyData(false);
                  parser.setStopAtFirstError(false);
 
                  parser.parse(stream, sourceURL);
                 
                  c.commit();
 
                  _logger.info("Read " + handler.m_count + " statements from '" + sourceURL + "'");
              } catch (RepositoryException e) {
View Full Code Here

Examples of org.openrdf.rio.RDFParser

                public RDFFormat getRDFFormat() {
                    return f;
                }

                public RDFParser getParser() {
                    RDFParser p = pf.getParser();
                    p.setDatatypeHandling(RDFParser.DatatypeHandling.IGNORE);
                    return p;
                }
            };

            oldFactories.add(pf);
View Full Code Here

Examples of org.openrdf.rio.RDFParser

                if (null == format) {
                    LOGGER.warning("could not guess format of file: " + n);
                    return 0;
                }

                RDFParser p = Rio.createParser(format);
                p.setStopAtFirstError(false);
                SailConnectionAdder adder = new SailConnectionAdder(c);
                p.setRDFHandler(adder);

                try {
                    p.parse(is, baseUri);
                } catch (Throwable t) {
                    // Attempt to recover.
                    t.printStackTrace(System.err);
                } finally {
                    is.close();
View Full Code Here

Examples of org.openrdf.rio.RDFParser

     *              mode, then this Sail will also be transactional.
     */
    public GraphSail(final T graph) {
        this(graph, "p,c,pc");

        RDFParser p = Rio.createParser(org.openrdf.rio.RDFFormat.NTRIPLES);
        p.setRDFHandler(new RDFHandler() {
            public void startRDF() throws RDFHandlerException {}
            public void endRDF() throws RDFHandlerException {}
            public void handleNamespace(String s, String s1) throws RDFHandlerException {}
            public void handleStatement(Statement s) throws RDFHandlerException {

View Full Code Here

Examples of org.openrdf.rio.RDFParser

        try {
            SailConnection sc = sail.getConnection();
            sc.begin();
            try {
                RDFHandler h = new SailAdder(sc);
                RDFParser p = Rio.createParser(format);
                p.setRDFHandler(h);
                p.parse(in, "http://example.org/bogusBaseURI/");
                sc.commit();
            } finally {
                sc.rollback();
                sc.close();
            }
View Full Code Here

Examples of org.openrdf.rio.RDFParser

    Set<Statement> model = new LinkedHashSet<Statement>();

    RDFFormat rdfFormat = Rio.getParserFormatForFileName(fileName);
    assertNotNull("Unable to determine RDF format for file: " + fileName, rdfFormat);

    RDFParser parser = Rio.createParser(rdfFormat);
    parser.setDatatypeHandling(DatatypeHandling.IGNORE);
    parser.setPreserveBNodeIDs(true);
    parser.setRDFHandler(new StatementCollector(model));

    InputStream in = modelURL.openStream();
    try {
      parser.parse(in, modelURL.toString());
      return model;
    }
    finally {
      in.close();
    }
View Full Code Here

Examples of org.openrdf.rio.RDFParser

      Resource... contexts)
    throws IOException, RDFParseException, RepositoryException
  {
    OpenRDFUtil.verifyContextNotNull(contexts);

    RDFParser rdfParser = Rio.createParser(dataFormat, getRepository().getValueFactory());

    rdfParser.setVerifyData(true);
    rdfParser.setStopAtFirstError(true);
    rdfParser.setDatatypeHandling(RDFParser.DatatypeHandling.IGNORE);

    RDFInserter rdfInserter = new RDFInserter(this);
    rdfInserter.enforceContext(contexts);
    rdfParser.setRDFHandler(rdfInserter);

    boolean autoCommit = isAutoCommit();
    setAutoCommit(false);

    try {
      if (inputStreamOrReader instanceof InputStream) {
        rdfParser.parse((InputStream)inputStreamOrReader, baseURI);
      }
      else if (inputStreamOrReader instanceof Reader) {
        rdfParser.parse((Reader)inputStreamOrReader, baseURI);
      }
      else {
        throw new IllegalArgumentException(
            "inputStreamOrReader must be an InputStream or a Reader, is a: "
                + inputStreamOrReader.getClass());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.