Java Code Examples for org.eclipse.rdf4j.query.QueryResults#report()
The following examples show how to use
org.eclipse.rdf4j.query.QueryResults#report() .
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: AbstractQueryResultIOTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
protected void doTupleLinksAndStylesheet(TupleQueryResultFormat format, TupleQueryResult input, TupleQueryResult expected, List<String> links, String stylesheetUrl) throws QueryResultHandlerException, QueryEvaluationException, QueryResultParseException, UnsupportedQueryResultFormatException, IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(4096); TupleQueryResultWriter writer = QueryResultIO.createTupleWriter(format, out); writer.startDocument(); writer.handleStylesheet(stylesheetUrl); writer.startHeader(); writer.handleLinks(links); QueryResults.report(input, writer); // System.out.println("output: " + out.toString("UTF-8")); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); TupleQueryResult output = parseTupleInternal(format, in); assertQueryResultsEqual(expected, output); }
Example 2
Source File: SPARQLCSVTupleTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testmultipleVarResults() throws Exception { TupleQueryResultFormat format = getTupleFormat(); ByteArrayOutputStream out = new ByteArrayOutputStream(4096); TupleQueryResultWriter writer = QueryResultIO.createTupleWriter(format, out); writer.startDocument(); writer.startHeader(); writer.handleLinks(Arrays.<String>asList()); QueryResults.report(createTupleMultipleBindingSets(), writer); assertRegex("a,b,c\r\n" + "foo:bar,_:bnode,baz\r\n" + "1,,Hello World!\r\n" + "http://example.org/test/ns/bindingA,http://example.com/other/ns/bindingB,\"http://example.com/other/ns/binding,C\"\r\n" + "\"string with newline at the end \n\",string with space at the end , \r\n" + "''single-quoted string,\"\"\"\"\"double-quoted string\",\t\tunencoded tab characters followed by encoded \t\t(\r\n)?", out.toString("UTF-8")); }
Example 3
Source File: SPARQLCSVTupleTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testSingleVarResults() throws Exception { TupleQueryResultFormat format = getTupleFormat(); ByteArrayOutputStream out = new ByteArrayOutputStream(4096); TupleQueryResultWriter writer = QueryResultIO.createTupleWriter(format, out); writer.startDocument(); writer.startHeader(); writer.handleLinks(Arrays.<String>asList()); QueryResults.report(createTupleSingleVarMultipleBindingSets(), writer); System.out.println(out.toString("UTF-8")); assertRegex("a\r\n" + "foo:bar\r\n" + "2.0(E0)?\r\n" + "_:bnode3\r\n" + "''single-quoted string\r\n" + "\"\"\"\"\"double-quoted string\"\r\n" + "space at the end \r\n" + "space at the end \r\n" + "\"\"\"\"\"double-quoted string with no datatype\"\r\n" + "\"newline at the end \n\"(\r\n)?" + "urn:rdf4j:triple:PDw8dXJuOmE-IDxodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjdHlwZT4gPHVybjpiPj4-(\r\n)?", out.toString("UTF-8")); }
Example 4
Source File: AbstractQueryResultIOTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
protected void doTupleLinksAndStylesheetNoStarts(TupleQueryResultFormat format, TupleQueryResult input, TupleQueryResult expected, List<String> links, String stylesheetUrl) throws QueryResultHandlerException, QueryEvaluationException, QueryResultParseException, UnsupportedQueryResultFormatException, IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(4096); TupleQueryResultWriter writer = QueryResultIO.createTupleWriter(format, out); // Test for handling when startDocument and startHeader are not called writer.handleStylesheet(stylesheetUrl); writer.handleLinks(links); QueryResults.report(input, writer); // System.out.println("output: " + out.toString("UTF-8")); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); TupleQueryResult output = parseTupleInternal(format, in); assertQueryResultsEqual(expected, output); }
Example 5
Source File: AbstractQueryResultIOTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
protected void doTupleLinksAndStylesheetAndNamespaces(TupleQueryResultFormat format, TupleQueryResult input, TupleQueryResult expected, List<String> links, String stylesheetUrl, Map<String, String> namespaces) throws QueryResultHandlerException, QueryEvaluationException, QueryResultParseException, UnsupportedQueryResultFormatException, IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(4096); TupleQueryResultWriter writer = QueryResultIO.createTupleWriter(format, out); for (String nextPrefix : namespaces.keySet()) { writer.handleNamespace(nextPrefix, namespaces.get(nextPrefix)); } writer.startDocument(); writer.handleStylesheet(stylesheetUrl); writer.startHeader(); writer.handleLinks(links); QueryResults.report(input, writer); // System.out.println("output: " + out.toString("UTF-8")); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); TupleQueryResult output = parseTupleInternal(format, in); assertQueryResultsEqual(expected, output); }
Example 6
Source File: AbstractQueryResultIOTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
protected void doTupleLinks(TupleQueryResultFormat format, TupleQueryResult input, TupleQueryResult expected, List<String> links) throws QueryResultHandlerException, QueryEvaluationException, QueryResultParseException, UnsupportedQueryResultFormatException, IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(4096); TupleQueryResultWriter writer = QueryResultIO.createTupleWriter(format, out); writer.startDocument(); writer.startHeader(); writer.handleLinks(links); QueryResults.report(input, writer); // System.out.println("output: " + out.toString("UTF-8")); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); TupleQueryResult output = parseTupleInternal(format, in); assertQueryResultsEqual(expected, output); }
Example 7
Source File: AbstractQueryResultIOTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Test specifically for JSONP callback support. */ protected void doTupleJSONPCallback(TupleQueryResultFormat format, TupleQueryResult input, TupleQueryResult expected) throws QueryResultHandlerException, QueryEvaluationException, QueryResultParseException, UnsupportedQueryResultFormatException, IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(4096); TupleQueryResultWriter writer = QueryResultIO.createTupleWriter(format, out); // only do this test if the callback is enabled if (writer.getSupportedSettings().contains(BasicQueryWriterSettings.JSONP_CALLBACK)) { String callback = "nextfunctionname" + Math.abs(new Random().nextInt()); writer.getWriterConfig().set(BasicQueryWriterSettings.JSONP_CALLBACK, callback); QueryResults.report(input, writer); String result = out.toString("UTF-8"); // System.out.println("output: " + result); assertTrue(result.startsWith(callback + "(")); assertTrue(result.endsWith(");")); // Strip off the callback function and verify that it contains a // valid // JSON object containing the correct results result = result.substring(callback.length() + 1, result.length() - 2); ByteArrayInputStream in = new ByteArrayInputStream(result.getBytes("UTF-8")); TupleQueryResult output = parseTupleInternal(format, in); assertQueryResultsEqual(expected, output); } }
Example 8
Source File: AbstractQueryResultIOTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Test specifically for QName support. */ protected void doTupleLinksAndStylesheetAndNamespacesQName(TupleQueryResultFormat format, TupleQueryResult input, TupleQueryResult expected, List<String> links, String stylesheetUrl, Map<String, String> namespaces) throws QueryResultHandlerException, QueryEvaluationException, QueryResultParseException, UnsupportedQueryResultFormatException, IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(4096); TupleQueryResultWriter writer = QueryResultIO.createTupleWriter(format, out); if (writer.getSupportedSettings().contains(BasicQueryWriterSettings.ADD_SESAME_QNAME)) { // System.out.println("Enabling Sesame qname support"); writer.getWriterConfig().set(BasicQueryWriterSettings.ADD_SESAME_QNAME, true); } for (String nextPrefix : namespaces.keySet()) { writer.handleNamespace(nextPrefix, namespaces.get(nextPrefix)); } writer.startDocument(); writer.handleStylesheet(stylesheetUrl); writer.startHeader(); writer.handleLinks(links); QueryResults.report(input, writer); String result = out.toString("UTF-8"); // System.out.println("output: " + result); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); TupleQueryResult output = parseTupleInternal(format, in); assertQueryResultsEqual(expected, output); // only do this additional test if sesame q:qname is supported by this // writer if (writer.getSupportedSettings().contains(BasicQueryWriterSettings.ADD_SESAME_QNAME)) { assertTrue(result.contains("test:bindingA")); assertFalse(result.contains("other:bindingB")); assertTrue(result.contains("other:binding,C")); } }
Example 9
Source File: QueryResultIO.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Writes a graph query result document in a specific RDF format to an output stream. * * @param gqr The query result to write. * @param format The file format of the document to write. * @param out An OutputStream to write the document to. * @throws IOException If an I/O error occurred while writing the query result document to the * stream. * @throws RDFHandlerException If such an exception is thrown by the used RDF writer. * @throws QueryEvaluationException * @throws UnsupportedRDFormatException If an unsupported query result file format was specified. */ public static void writeGraph(GraphQueryResult gqr, RDFFormat format, OutputStream out) throws IOException, RDFHandlerException, UnsupportedRDFormatException, QueryEvaluationException { RDFWriter writer = Rio.createWriter(format, out); try { QueryResults.report(gqr, writer); } catch (RDFHandlerException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } else { throw e; } } }
Example 10
Source File: SPARQLTSVTupleBackgroundTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
private String toString(TupleQueryResult results) throws QueryResultHandlerException, TupleQueryResultHandlerException, QueryEvaluationException, UnsupportedEncodingException { TupleQueryResultFormat format = getTupleFormat(); ByteArrayOutputStream out = new ByteArrayOutputStream(4096); TupleQueryResultWriter writer = QueryResultIO.createTupleWriter(format, out); writer.startDocument(); writer.startHeader(); writer.handleLinks(Arrays.<String>asList()); QueryResults.report(results, writer); return out.toString("UTF-8"); }
Example 11
Source File: SPARQLTSVTupleTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
private String toString(TupleQueryResult results) throws QueryResultHandlerException, TupleQueryResultHandlerException, QueryEvaluationException, UnsupportedEncodingException { TupleQueryResultFormat format = getTupleFormat(); ByteArrayOutputStream out = new ByteArrayOutputStream(4096); TupleQueryResultWriter writer = QueryResultIO.createTupleWriter(format, out); writer.startDocument(); writer.startHeader(); writer.handleLinks(Arrays.<String>asList()); QueryResults.report(results, writer); return out.toString("UTF-8"); }
Example 12
Source File: SPARQLCSVTupleBackgroundTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testEndOfLine() throws Exception { TupleQueryResultFormat format = getTupleFormat(); ByteArrayOutputStream out = new ByteArrayOutputStream(4096); TupleQueryResultWriter writer = QueryResultIO.createTupleWriter(format, out); writer.startDocument(); writer.startHeader(); writer.handleLinks(Arrays.<String>asList()); QueryResults.report(createTupleNoBindingSets(), writer); assertEquals("\r\n", out.toString("UTF-8").replaceAll("\\S+", "")); }
Example 13
Source File: SPARQLCSVTupleTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testEndOfLine() throws Exception { TupleQueryResultFormat format = getTupleFormat(); ByteArrayOutputStream out = new ByteArrayOutputStream(4096); TupleQueryResultWriter writer = QueryResultIO.createTupleWriter(format, out); writer.startDocument(); writer.startHeader(); writer.handleLinks(Arrays.<String>asList()); QueryResults.report(createTupleNoBindingSets(), writer); assertEquals("\r\n", out.toString("UTF-8").replaceAll("\\S+", "")); }
Example 14
Source File: SPARQLCSVTupleTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testEmptyResults() throws Exception { TupleQueryResultFormat format = getTupleFormat(); ByteArrayOutputStream out = new ByteArrayOutputStream(4096); TupleQueryResultWriter writer = QueryResultIO.createTupleWriter(format, out); writer.startDocument(); writer.startHeader(); writer.handleLinks(Arrays.<String>asList()); QueryResults.report(createTupleNoBindingSets(), writer); assertRegex("a,b,c(\r\n)?", out.toString("UTF-8")); }
Example 15
Source File: AbstractQueryPreparer.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void evaluate(TupleQueryResultHandler handler) throws QueryEvaluationException, TupleQueryResultHandlerException { TupleQueryResult queryResult = evaluate(); QueryResults.report(queryResult, handler); }
Example 16
Source File: SailGraphQuery.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void evaluate(RDFHandler handler) throws QueryEvaluationException, RDFHandlerException { GraphQueryResult queryResult = evaluate(); QueryResults.report(queryResult, handler); }
Example 17
Source File: SailConnectionGraphQuery.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void evaluate(RDFHandler handler) throws QueryEvaluationException, RDFHandlerException { GraphQueryResult queryResult = evaluate(); QueryResults.report(queryResult, handler); }
Example 18
Source File: SailConnectionTupleQuery.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void evaluate(TupleQueryResultHandler handler) throws QueryEvaluationException, TupleQueryResultHandlerException { TupleQueryResult queryResult = evaluate(); QueryResults.report(queryResult, handler); }
Example 19
Source File: AbstractQueryPreparer.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void evaluate(RDFHandler handler) throws QueryEvaluationException, RDFHandlerException { GraphQueryResult queryResult = evaluate(); QueryResults.report(queryResult, handler); }
Example 20
Source File: SailTupleQuery.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void evaluate(TupleQueryResultHandler handler) throws QueryEvaluationException, TupleQueryResultHandlerException { TupleQueryResult queryResult = evaluate(); QueryResults.report(queryResult, handler); }