private RDFParser getParser(RdfFormat rdfFormat) { if (rdfFormat == RdfFormat.RDFXML) return Rio.createParser(RDFFormat.RDFXML); else if (rdfFormat == RdfFormat.JSONLD) return Rio.createParser(RDFFormat.JSONLD); else if (rdfFormat == RdfFormat.TURTLE) return Rio.createParser(RDFFormat.TURTLE); else if (rdfFormat == RdfFormat.RDFA) return Rio.createParser(RDFFormat.RDFA); else return Rio.createParser(RDFFormat.N3); }
/** * Creates a new {@link RDFParser} instance. * * @param format parser format. * @return parser instance. * @throws IllegalArgumentException if format is not supported. */ public static RDFParser getParser(RDFFormat format) { return Rio.createParser(format); }
private RDFParser getParser(RdfFormat rdfFormat) { if (rdfFormat == RdfFormat.RDFXML) return Rio.createParser(RDFFormat.RDFXML); else if (rdfFormat == RdfFormat.JSONLD) return Rio.createParser(RDFFormat.JSONLD); else if (rdfFormat == RdfFormat.TURTLE) return Rio.createParser(RDFFormat.TURTLE); else if (rdfFormat == RdfFormat.RDFA) return Rio.createParser(RDFFormat.RDFA); else return Rio.createParser(RDFFormat.N3); }
OntopRepositoryConnection(OntopRepository rep, OntopConnection connection, RDF4JInputQueryFactory inputQueryFactory) { this.repository = rep; this.ontopConnection = connection; this.inputQueryFactory = inputQueryFactory; this.isOpen = true; this.isActive = false; this.rdfParser = Rio.createParser(RDFFormat.RDFXML, this.repository.getValueFactory()); this.namespaces = new HashMap<>(); }
OntopRepositoryConnection(OntopRepository rep, OntopConnection connection, RDF4JInputQueryFactory inputQueryFactory) { this.repository = rep; this.ontopConnection = connection; this.inputQueryFactory = inputQueryFactory; this.isOpen = true; this.isActive = false; this.rdfParser = Rio.createParser(RDFFormat.RDFXML, this.repository.getValueFactory()); this.namespaces = new HashMap<>(); }
/** * Convenience methods for creating RDFParser objects that use the specified ValueFactory to create RDF * model objects. * * @throws UnsupportedRDFormatException * If no parser is available for the specified RDF format. * @see #createParser(RDFFormat) * @see RDFParser#setValueFactory(ValueFactory) */ public static RDFParser createParser(RDFFormat format, ValueFactory valueFactory) throws UnsupportedRDFormatException { RDFParser rdfParser = createParser(format); rdfParser.setValueFactory(valueFactory); return rdfParser; }
/** * Convenience methods for creating RDFParser objects that use the specified ValueFactory to create RDF * model objects. * * @throws UnsupportedRDFormatException * If no parser is available for the specified RDF format. * @see #createParser(RDFFormat) * @see RDFParser#setValueFactory(ValueFactory) */ public static RDFParser createParser(RDFFormat format, ValueFactory valueFactory) throws UnsupportedRDFormatException { RDFParser rdfParser = createParser(format); rdfParser.setValueFactory(valueFactory); return rdfParser; }
/** * Convenience methods for creating RDFParser objects that use the specified ValueFactory to create RDF * model objects. * * @throws UnsupportedRDFormatException * If no parser is available for the specified RDF format. * @see #createParser(RDFFormat) * @see RDFParser#setValueFactory(ValueFactory) */ public static RDFParser createParser(RDFFormat format, ValueFactory valueFactory) throws UnsupportedRDFormatException { RDFParser rdfParser = createParser(format); rdfParser.setValueFactory(valueFactory); return rdfParser; }
/** * Returns a new instance of a configured NTriplesParser. * * @param verifyDataType data verification enable if <code>true</code>. * @param stopAtFirstError the parser stops at first error if <code>true</code>. * @param extractionContext the extraction context where the parser is used. * @param extractionResult the output extraction result. * @return a new instance of a configured NTriples parser. */ public RDFParser getNTriplesParser( 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; }
/** * Returns a new instance of a configured ManchesterSyntaxParser. * * @param verifyDataType data verification enable if <code>true</code>. * @param stopAtFirstError the parser stops at first error if <code>true</code>. * @param extractionContext the extraction context where the parser is used. * @param extractionResult the output extraction result. * @return a new instance of a configured Manchester Syntax parser. */ public RDFParser getManchesterSyntaxParser( final boolean verifyDataType, final boolean stopAtFirstError, final ExtractionContext extractionContext, final ExtractionResult extractionResult ) { final RDFParser parser = Rio.createParser(OWLAPIRDFFormat.MANCHESTER_OWL); configureParser(parser, verifyDataType, stopAtFirstError, extractionContext, extractionResult); return parser; }
public static void main(String[] args) throws IOException, RDFParseException, RDFHandlerException, UnsupportedRDFormatException { if (args.length < 2) { System.out.println("Usage: java org.eclipse.rdf4j.rio.Rio <inputFile> <outputFile>"); System.exit(1); return; } String inputFile = args[0]; String outputFile = args[1]; try (FileOutputStream outStream = new FileOutputStream(outputFile); FileInputStream inStream = new FileInputStream(inputFile);) { createParser(getParserFormatForFileName(inputFile).orElse(RDFFormat.RDFXML)).setRDFHandler( createWriter(getWriterFormatForFileName(outputFile).orElse(RDFFormat.RDFXML), outStream)).parse(inStream, "file:" + inputFile); } }
public static void main(String[] args) throws IOException, RDFParseException, RDFHandlerException, UnsupportedRDFormatException { if (args.length < 2) { System.out.println("Usage: java org.eclipse.rdf4j.rio.Rio <inputFile> <outputFile>"); System.exit(1); return; } String inputFile = args[0]; String outputFile = args[1]; try (FileOutputStream outStream = new FileOutputStream(outputFile); FileInputStream inStream = new FileInputStream(inputFile);) { createParser(getParserFormatForFileName(inputFile).orElse(RDFFormat.RDFXML)).setRDFHandler( createWriter(getWriterFormatForFileName(outputFile).orElse(RDFFormat.RDFXML), outStream)).parse(inStream, "file:" + inputFile); } }
public static void main(String[] args) throws IOException, RDFParseException, RDFHandlerException, UnsupportedRDFormatException { if (args.length < 2) { System.out.println("Usage: java org.eclipse.rdf4j.rio.Rio <inputFile> <outputFile>"); System.exit(1); return; } String inputFile = args[0]; String outputFile = args[1]; try (FileOutputStream outStream = new FileOutputStream(outputFile); FileInputStream inStream = new FileInputStream(inputFile);) { createParser(getParserFormatForFileName(inputFile).orElse(RDFFormat.RDFXML)).setRDFHandler( createWriter(getWriterFormatForFileName(outputFile).orElse(RDFFormat.RDFXML), outStream)).parse(inStream, "file:" + inputFile); } }
private void translateRDFDocument(final InputStream in, final OutputStream out, final RDFFormat inFormat, final RDFFormat outFormat, final String baseURI) throws SailException, IOException, RDFHandlerException, RDFParseException { RDFParser p = Rio.createParser(inFormat); RDFWriter w = Rio.createWriter(outFormat, out); p.setRDFHandler(w); p.parse(in, baseURI); } }
@Override protected void addAxiomStatements() throws SailException { RDFParser parser = Rio.createParser(RDFFormat.TURTLE); if (axiomClosureNeeded) { loadAxiomStatements(parser, "/schema/spin-full.ttl"); } else { loadAxiomStatements(parser, "/schema/sp.ttl"); loadAxiomStatements(parser, "/schema/spin.ttl"); loadAxiomStatements(parser, "/schema/spl.spin.ttl"); } }
@Override protected void addAxiomStatements() throws SailException { RDFParser parser = Rio.createParser(RDFFormat.TURTLE); if (axiomClosureNeeded) { loadAxiomStatements(parser, "/schema/spin-full.ttl"); } else { loadAxiomStatements(parser, "/schema/sp.ttl"); loadAxiomStatements(parser, "/schema/spin.ttl"); loadAxiomStatements(parser, "/schema/spl.spin.ttl"); } }
private Statement parseNtriples(String ntriples) throws IOException, RDFParseException, RDFHandlerException { RDFParser parser = Rio.createParser(RDFFormat.NTRIPLES, vf); parser.setPreserveBNodeIDs(true); StatementCollector collector = new StatementCollector(); parser.setRDFHandler(collector); parser.parse(new StringReader(ntriples), "http://example.com/"); Statement st = collector.getStatements().iterator().next(); return st; }
@Override public void handleResponse(HttpMethod method) throws IOException, AGHttpException { String mimeType = getResponseMIMEType(method); if (!mimeType.equals(getRequestMIMEType())) { throw new AGHttpException("unexpected response MIME type: " + mimeType); } InputStream response = getInputStream(method); // Note: we ignore charset specified in the response. Reader reader = new InputStreamReader(response, StandardCharsets.UTF_8); try { RDFParser parser = Rio.createParser(format, vf); parser.setPreserveBNodeIDs(true); parser.setRDFHandler(rdfhandler); parser.parse(reader, method.getURI().getURI()); } catch (RDFParseException | RDFHandlerException e) { throw new AGHttpException(e); } }
protected void loadDataset(String datasetFile) throws RDFParseException, RepositoryException, IOException { logger.debug("loading dataset..."); InputStream dataset = org.eclipse.rdf4j.query.parser.sparql.SPARQLUpdateTest.class.getResourceAsStream(datasetFile); try { RDFParser parser = Rio.createParser(RDFFormat.TRIG, f); parser.setPreserveBNodeIDs(true); StatementCollector collector = new StatementCollector(); parser.setRDFHandler(collector); parser.parse(dataset, ""); con.add(collector.getStatements()); } catch (RDFParseException e) { throw new RuntimeException(e); } catch (RDFHandlerException e) { throw new RuntimeException(e); } finally { dataset.close(); } }
private Model parseTurtleGraph(final String configFile) throws IOException, RDFParseException, RDFHandlerException, FileNotFoundException { RDFParser parser = Rio.createParser(RDFFormat.TURTLE, vf); parser.setPreserveBNodeIDs(true); StatementCollector collector = new StatementCollector(); parser.setRDFHandler(collector); try (final InputStream fis = Util.resourceAsStream(configFile)) { parser.parse(fis, ""); } return new LinkedHashModel(collector.getStatements()); }