Package org.openrdf.rio.turtle

Examples of org.openrdf.rio.turtle.TurtleParser


    return new N3ParserTest().createTestSuite();
  }

  @Override
  protected RDFParser createRDFParser() {
    return new TurtleParser();
  }
View Full Code Here


    InputStream in = url.openStream();

    try {
      final ValueFactory vf = con.getValueFactory();
      RDFParser rdfParser = new TurtleParser();
      rdfParser.setValueFactory(vf);

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

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

      con.begin();
      try {
        rdfParser.parse(in, baseURI);
        con.commit();
      }
      catch (RDFHandlerException e) {
        con.rollback();
        // RDFInserter only throws wrapped StoreExceptions
View Full Code Here

        } catch (final IOException e) {
          System.err.println(e);
          e.printStackTrace();
        }
      } else if (parserType == SesameParserType.TURTLE) {
        final TurtleParser parser = new TurtleParser();
        parser.setRDFHandler(handler);
        try {
          parser.parse(isr, "");
        } catch (final RDFParseException e) {
          System.err.println(e);
          e.printStackTrace();
        } catch (final RDFHandlerException e) {
          System.err.println(e);
View Full Code Here

            final ExtractionResult extractionResult
    ) {
        if (extractionResult == null) {
            throw new NullPointerException("extractionResult cannot be null.");
        }
        final TurtleParser parser = new ExtendedTurtleParser();
        configureParser(parser, verifyDataType, stopAtFirstError, extractionContext, extractionResult);
        return parser;
    }
View Full Code Here

     * @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, '.');
        TurtleParser turtleParser = new TurtleParser();
        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

        } 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 {
View Full Code Here

    @Override
    protected void runTest()
      throws Exception
    {
      // Parse input data
      TurtleParser turtleParser = new TurtleParser();
      turtleParser.setDatatypeHandling(RDFParser.DatatypeHandling.IGNORE);

      Set<Statement> inputCollection = new LinkedHashSet<Statement>();
      StatementCollector inputCollector = new StatementCollector(inputCollection);
      turtleParser.setRDFHandler(inputCollector);

      InputStream in = inputURL.openStream();
      turtleParser.parse(in, inputURL.toExternalForm());
      in.close();

      // Parse expected output data
      NTriplesParser ntriplesParser = new NTriplesParser();
      ntriplesParser.setDatatypeHandling(RDFParser.DatatypeHandling.IGNORE);
View Full Code Here

  /**
   * Returns a new instance of {@link TurtleParser}.
   */
  public RDFParser getParser() {
    return new TurtleParser();
  }
View Full Code Here

    @Override
    protected void runTest() {
      try {
        // Try parsing the input; this should result in an error being
        // reported.
        TurtleParser turtleParser = new TurtleParser();
        turtleParser.setDatatypeHandling(RDFParser.DatatypeHandling.IGNORE);

        turtleParser.setRDFHandler(new StatementCollector());

        InputStream in = inputURL.openStream();
        turtleParser.parse(in, inputURL.toExternalForm());
        in.close();

        fail("Parser parses erroneous data without reporting errors");
      }
      catch (RDFParseException e) {
View Full Code Here

  /**
   * Returns a new instance of {@link TurtleParser}.
   */
  public RDFParser getParser() {
    return new TurtleParser();
  }
View Full Code Here

TOP

Related Classes of org.openrdf.rio.turtle.TurtleParser

Copyright © 2018 www.massapicom. 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.