Package org.openrdf.rio

Examples of org.openrdf.rio.RDFParser


    if (httpCode == HttpURLConnection.HTTP_OK) {
      String mimeType = getResponseMIMEType(method);
      try {
        RDFFormat format = RDFFormat.matchMIMEType(mimeType, rdfFormats);
        RDFParser parser = Rio.createParser(format, getValueFactory());
        parser.setPreserveBNodeIDs(true);
        parser.setRDFHandler(handler);
        parser.parse(method.getResponseBodyAsStream(), method.getURI().getURI());
      }
      catch (UnsupportedRDFormatException e) {
        throw new RepositoryException("Server responded with an unsupported file format: " + mimeType);
      }
      catch (RDFParseException e) {
View Full Code Here


  /* Adapted from Sesame's RepositoryConnectionBase.addInputStreamOrReader() */
  private void addData(Graph graph, InputStream is, RDFFormat dataFormat, String baseURI, Resource... contexts) throws RDFParseException, RDFHandlerException, IOException
   {
    OpenRDFUtil.verifyContextNotNull(contexts);

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

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

    RDFGraphInserter rdfInserter = new RDFGraphInserter(graph, contexts);
    rdfParser.setRDFHandler(rdfInserter);
    rdfParser.parse(is, baseURI);
  }   
View Full Code Here

  {
    RepositoryConnection con = dataRep.getConnection();
    con.setAutoCommit(false);
    try {
      RDFFormat rdfFormat = Rio.getParserFormatForFileName(graphURI.toString(), RDFFormat.TURTLE);
      RDFParser rdfParser = Rio.createParser(rdfFormat, dataRep.getValueFactory());
      rdfParser.setVerifyData(false);
      rdfParser.setDatatypeHandling(DatatypeHandling.IGNORE);
      // rdfParser.setPreserveBNodeIDs(true);

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

      URL graphURL = new URL(graphURI.toString());
      InputStream in = graphURL.openStream();
      try {
        rdfParser.parse(in, graphURI.toString());
      }
      finally {
        in.close();
      }
View Full Code Here

    throws Exception
  {
    RDFFormat rdfFormat = Rio.getParserFormatForFileName(resultFileURL);

    if (rdfFormat != null) {
      RDFParser parser = Rio.createParser(rdfFormat);
      parser.setDatatypeHandling(DatatypeHandling.IGNORE);
      parser.setPreserveBNodeIDs(true);

      Set<Statement> result = new LinkedHashSet<Statement>();
      parser.setRDFHandler(new StatementCollector(result));

      InputStream in = new URL(resultFileURL).openStream();
      try {
        parser.parse(in, resultFileURL);
      }
      finally {
        in.close();
      }
View Full Code Here

            final boolean verifyDataType,
            final boolean stopAtFirstError,
            final ExtractionContext extractionContext,
            final ExtractionResult extractionResult
    ) {
        final RDFParser parser = Rio.createParser(RDFFormat.RDFXML);
        configureParser(parser, verifyDataType, stopAtFirstError, extractionContext, extractionResult);
        return parser;
    }
View Full Code Here

            final boolean verifyDataType,
            final boolean stopAtFirstError,
            final ExtractionContext extractionContext,
            final ExtractionResult extractionResult
    ) {
        final RDFParser parser = Rio.createParser(RDFFormat.NTRIPLES);
        configureParser(parser, verifyDataType, stopAtFirstError, extractionContext, extractionResult);
        return parser;
    }
View Full Code Here

            final boolean verifyDataType,
            final boolean stopAtFirstError,
            final ExtractionContext extractionContext,
            final ExtractionResult extractionResult
    ) {
        final RDFParser parser = Rio.createParser(RDFFormat.NQUADS);
        configureParser(parser, verifyDataType, stopAtFirstError, extractionContext, extractionResult);
        return parser;
    }
View Full Code Here

            final boolean verifyDataType,
            final boolean stopAtFirstError,
            final ExtractionContext extractionContext,
            final ExtractionResult extractionResult
    ) {
        final RDFParser parser = Rio.createParser(RDFFormat.TRIX);
        configureParser(parser, verifyDataType, stopAtFirstError, extractionContext, extractionResult);
        return parser;
    }
View Full Code Here

        } catch (XSLTStylesheetException xslte) {
            throw new ExtractionException("An error occurred during the XSLT application.", xslte);
        }

        try {
            RDFParser parser
                    = RDFParserFactory.getInstance().getRDFXMLParser(
                        verifyDataType, stopAtFirstError, extractionContext, out
                    );
            parser.parse(
                    new StringReader(buffer.getBuffer().toString()),
                    extractionContext.getDocumentURI().stringValue()
            );
        } catch (RDFHandlerException ex) {
            throw new IllegalStateException(
View Full Code Here

     * @throws RDFParseException
     */
    public static Statement[] parseRDF(RDFFormat format, InputStream is, String baseURI)
    throws RDFHandlerException, IOException, RDFParseException {
        final StatementCollector handler = new StatementCollector();
        final RDFParser parser = getParser(format);
        parser.setVerifyData(true);
        parser.setStopAtFirstError(true);
        parser.setPreserveBNodeIDs(true);
        parser.setRDFHandler(handler);
        parser.parse(is, baseURI);
        return handler.getStatements().toArray( new Statement[handler.getStatements().size()] );
    }
View Full Code Here

TOP

Related Classes of org.openrdf.rio.RDFParser

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.