protected void loadTestData(String dataFile, Resource... contexts) throws RDFParseException, RepositoryException, IOException { logger.debug("loading dataset {}", dataFile); InputStream dataset = ComplexSPARQLQueryTest.class.getResourceAsStream(dataFile); try { conn.add(dataset, "", Rio.getParserFormatForFileName(dataFile).orElseThrow(Rio.unsupportedFormat(dataFile)), contexts); } finally { dataset.close(); } logger.debug("dataset loaded."); } }
/** * Convenience methods for creating RDFWriter objects. This method uses the * registry returned by {@link RDFWriterRegistry#getInstance()} to get a * factory for the specified format and uses this factory to create the * appropriate writer. * * @throws UnsupportedRDFormatException * If no writer is available for the specified RDF format. */ public static RDFWriter createWriter(RDFFormat format, OutputStream out) throws UnsupportedRDFormatException { RDFWriterFactory factory = RDFWriterRegistry.getInstance().get(format).orElseThrow( Rio.unsupportedFormat(format)); return factory.getWriter(out); }
/** * Convenience methods for creating RDFParser objects. This method uses the * registry returned by {@link RDFParserRegistry#getInstance()} to get a * factory for the specified format and uses this factory to create the * appropriate parser. * * @throws UnsupportedRDFormatException * If no parser is available for the specified RDF format. */ public static RDFParser createParser(RDFFormat format) throws UnsupportedRDFormatException { RDFParserFactory factory = RDFParserRegistry.getInstance().get(format).orElseThrow( Rio.unsupportedFormat(format)); return factory.getParser(); }
/** * Convenience methods for creating RDFWriter objects. This method uses the * registry returned by {@link RDFWriterRegistry#getInstance()} to get a * factory for the specified format and uses this factory to create the * appropriate writer. * * @throws UnsupportedRDFormatException * If no writer is available for the specified RDF format. */ public static RDFWriter createWriter(RDFFormat format, Writer writer) throws UnsupportedRDFormatException { RDFWriterFactory factory = RDFWriterRegistry.getInstance().get(format).orElseThrow( Rio.unsupportedFormat(format)); return factory.getWriter(writer); }
URL graphURL = new URL(inputDefaultGraph.stringValue()); conn.add(graphURL, null, Rio.getParserFormatForFileName(graphURL.toString()).orElseThrow( Rio.unsupportedFormat(graphURL.toString()))); conn.add(graphURL, null, Rio.getParserFormatForFileName(graphURL.toString()).orElseThrow( Rio.unsupportedFormat(graphURL.toString())), dataRep.getValueFactory().createIRI(ng)); URL graphURL = new URL(resultDefaultGraph.stringValue()); conn.add(graphURL, null, Rio.getParserFormatForFileName(graphURL.toString()).orElseThrow( Rio.unsupportedFormat(graphURL.toString()))); conn.add(graphURL, null, Rio.getParserFormatForFileName(graphURL.toString()).orElseThrow( Rio.unsupportedFormat(graphURL.toString())), dataRep.getValueFactory().createIRI(ng));
protected final Set<Statement> readExpectedGraphQueryResult() throws Exception { RDFFormat rdfFormat = Rio.getParserFormatForFileName(resultFileURL).orElseThrow( Rio.unsupportedFormat(resultFileURL)); RDFParser parser = Rio.createParser(rdfFormat); parser.setDatatypeHandling(DatatypeHandling.IGNORE); parser.setPreserveBNodeIDs(true); parser.setValueFactory(dataRep.getValueFactory()); 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(); } return result; }
public void testWrite() throws RepositoryException, RDFParseException, IOException, RDFHandlerException { Repository rep1 = new SailRepository(new MemoryStore()); rep1.initialize(); RepositoryConnection con1 = rep1.getConnection(); URL ciaScheme = this.getClass().getResource("/cia-factbook/CIA-onto-enhanced.rdf"); URL ciaFacts = this.getClass().getResource("/cia-factbook/CIA-facts-enhanced.rdf"); con1.add( ciaScheme, ciaScheme.toExternalForm(), Rio.getParserFormatForFileName(ciaScheme.toExternalForm()).orElseThrow( Rio.unsupportedFormat(ciaScheme.toExternalForm()))); con1.add( ciaFacts, ciaFacts.toExternalForm(), Rio.getParserFormatForFileName(ciaFacts.toExternalForm()).orElseThrow( Rio.unsupportedFormat(ciaFacts.toExternalForm()))); StringWriter writer = new StringWriter(); RDFWriter rdfWriter = rdfWriterFactory.getWriter(writer); con1.export(rdfWriter); con1.close(); Repository rep2 = new SailRepository(new MemoryStore()); rep2.initialize(); RepositoryConnection con2 = rep2.getConnection(); con2.add(new StringReader(writer.toString()), "foo:bar", RDFFormat.NQUADS); con2.close(); Assert.assertTrue("result of serialization and re-upload should be equal to original", RepositoryUtil.equals(rep1, rep2)); }
baseURI, Rio.getParserFormatForMIMEType(request.getContentType()).orElseThrow( Rio.unsupportedFormat(request.getContentType()))); break; case DELETE: RDFParser parser = Rio.createParser( Rio.getParserFormatForMIMEType(request.getContentType()).orElseThrow( Rio.unsupportedFormat(request.getContentType())), conn.getValueFactory()); parser.setRDFHandler(new WildcardRDFRemover(conn)); parser.getParserConfig().set(BasicParserSettings.PRESERVE_BNODE_IDS, true);
Rio.getParserFormatForFileName(dataFile).orElseThrow(Rio.unsupportedFormat(dataFile))); Rio.getParserFormatForFileName(graphName).orElseThrow(Rio.unsupportedFormat(graphName)), dataCon.getValueFactory().createIRI(graphName)); Rio.getParserFormatForFileName(resultFile).orElseThrow(Rio.unsupportedFormat(resultFile)));
Rio.unsupportedFormat(RDFFormat.TURTLE)); File outFile = File.createTempFile("sesame-earl-compliance", "." + RDFFormat.TURTLE.getDefaultFileExtension());