Java Code Examples for org.eclipse.rdf4j.rio.RDFParser#setPreserveBNodeIDs()
The following examples show how to use
org.eclipse.rdf4j.rio.RDFParser#setPreserveBNodeIDs() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SPARQLServiceEvaluationTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Read the expected graph query result from the specified resource * * @param resultFile * @return * @throws Exception */ private Set<Statement> readExpectedGraphQueryResult(String resultFile) throws Exception { RDFFormat rdfFormat = Rio.getParserFormatForFileName(resultFile).orElseThrow(Rio.unsupportedFormat(resultFile)); RDFParser parser = Rio.createParser(rdfFormat); parser.setDatatypeHandling(DatatypeHandling.IGNORE); parser.setPreserveBNodeIDs(true); parser.setValueFactory(SimpleValueFactory.getInstance()); Set<Statement> result = new LinkedHashSet<>(); parser.setRDFHandler(new StatementCollector(result)); InputStream in = SPARQLServiceEvaluationTest.class.getResourceAsStream(resultFile); try { parser.parse(in, null); // TODO check } finally { in.close(); } return result; }
Example 2
Source File: SPARQLQueryTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
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<>(); parser.setRDFHandler(new StatementCollector(result)); InputStream in = new URL(resultFileURL).openStream(); try { parser.parse(in, resultFileURL); } finally { in.close(); } return result; }
Example 3
Source File: SPARQLQueryComplianceTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
private 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(getDataRepository().getValueFactory()); Set<Statement> result = new LinkedHashSet<>(); parser.setRDFHandler(new StatementCollector(result)); InputStream in = new URL(resultFileURL).openStream(); try { parser.parse(in, resultFileURL); } finally { in.close(); } return result; }
Example 4
Source File: FedXBaseTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Read the expected graph query result from the specified resource * * @param resultFile * @return * @throws Exception */ protected Set<Statement> readExpectedGraphQueryResult(String resultFile) throws Exception { RDFFormat rdfFormat = Rio.getParserFormatForFileName(resultFile).get(); if (rdfFormat != null) { RDFParser parser = Rio.createParser(rdfFormat); parser.setPreserveBNodeIDs(true); parser.setValueFactory(SimpleValueFactory.getInstance()); Set<Statement> result = new LinkedHashSet<>(); parser.setRDFHandler(new StatementCollector(result)); InputStream in = SPARQLBaseTest.class.getResourceAsStream(resultFile); try { parser.parse(in, resultFile); } finally { in.close(); } return result; } else { throw new RuntimeException("Unable to determine file type of results file"); } }
Example 5
Source File: HalyardStatsTest.java From Halyard with Apache License 2.0 | 5 votes |
@Test public void testStatsTarget() throws Exception { final HBaseSail sail = new HBaseSail(HBaseServerTestInstance.getInstanceConfig(), "statsTable", true, -1, true, 0, null, null); sail.initialize(); try (InputStream ref = HalyardStatsTest.class.getResourceAsStream("testData.trig")) { RDFParser p = Rio.createParser(RDFFormat.TRIG); p.setPreserveBNodeIDs(true); p.setRDFHandler(new AbstractRDFHandler() { @Override public void handleStatement(Statement st) throws RDFHandlerException { sail.addStatement(st.getSubject(), st.getPredicate(), st.getObject(), st.getContext()); } }).parse(ref, ""); } sail.commit(); sail.close(); File root = File.createTempFile("test_stats", ""); root.delete(); root.mkdirs(); assertEquals(0, ToolRunner.run(HBaseServerTestInstance.getInstanceConfig(), new HalyardStats(), new String[]{"-s", "statsTable", "-t", root.toURI().toURL().toString() + "stats{0}.trig", "-r", "100", "-g", "http://whatever/myStats"})); File stats = new File(root, "stats0.trig"); assertTrue(stats.isFile()); try (InputStream statsStream = new FileInputStream(stats)) { try (InputStream refStream = HalyardStatsTest.class.getResourceAsStream("testStatsTarget.trig")) { Model statsM = Rio.parse(statsStream, "", RDFFormat.TRIG, new ParserConfig().set(BasicParserSettings.PRESERVE_BNODE_IDS, true), SimpleValueFactory.getInstance(), new ParseErrorLogger()); Model refM = Rio.parse(refStream, "", RDFFormat.TRIG, new ParserConfig().set(BasicParserSettings.PRESERVE_BNODE_IDS, true), SimpleValueFactory.getInstance(), new ParseErrorLogger(), SimpleValueFactory.getInstance().createIRI("http://whatever/myStats")); assertEqualModels(refM, statsM); } } }
Example 6
Source File: HalyardStatsTest.java From Halyard with Apache License 2.0 | 5 votes |
@Test public void testStatsTargetPartial() throws Exception { final HBaseSail sail = new HBaseSail(HBaseServerTestInstance.getInstanceConfig(), "statsTable3", true, -1, true, 0, null, null); sail.initialize(); try (InputStream ref = HalyardStatsTest.class.getResourceAsStream("testData.trig")) { RDFParser p = Rio.createParser(RDFFormat.TRIG); p.setPreserveBNodeIDs(true); p.setRDFHandler(new AbstractRDFHandler() { @Override public void handleStatement(Statement st) throws RDFHandlerException { sail.addStatement(st.getSubject(), st.getPredicate(), st.getObject(), st.getContext()); } }).parse(ref, ""); } sail.commit(); sail.close(); File root = File.createTempFile("test_stats", ""); root.delete(); root.mkdirs(); assertEquals(0, ToolRunner.run(HBaseServerTestInstance.getInstanceConfig(), new HalyardStats(), new String[]{"-s", "statsTable3", "-t", root.toURI().toURL().toString() + "stats{0}.trig", "-r", "100", "-g", "http://whatever/myStats", "-c", "http://whatever/graph0"})); File stats = new File(root, "stats0.trig"); assertTrue(stats.isFile()); try (InputStream statsStream = new FileInputStream(stats)) { try (InputStream refStream = HalyardStatsTest.class.getResourceAsStream("testStatsTargetPartial.trig")) { Model statsM = Rio.parse(statsStream, "", RDFFormat.TRIG, new ParserConfig().set(BasicParserSettings.PRESERVE_BNODE_IDS, true), SimpleValueFactory.getInstance(), new ParseErrorLogger()); Model refM = Rio.parse(refStream, "", RDFFormat.TRIG, new ParserConfig().set(BasicParserSettings.PRESERVE_BNODE_IDS, true), SimpleValueFactory.getInstance(), new ParseErrorLogger(), SimpleValueFactory.getInstance().createIRI("http://whatever/myStats")); assertEqualModels(refM, statsM); } } }
Example 7
Source File: JSONParserTest.java From Halyard with Apache License 2.0 | 5 votes |
@Test public void testMethodsThatDoNothing() { RDFParser p = new JSONParser(); p.setVerifyData(true); p.setPreserveBNodeIDs(true); p.setStopAtFirstError(true); p.setDatatypeHandling(RDFParser.DatatypeHandling.NORMALIZE); p.setParseErrorListener(null); p.setParseLocationListener(null); }