Java Code Examples for org.eclipse.rdf4j.query.QueryResults#asModel()
The following examples show how to use
org.eclipse.rdf4j.query.QueryResults#asModel() .
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: ComplexSPARQLQueryTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testDescribeA() throws Exception { loadTestData("/testdata-query/dataset-describe.trig"); StringBuilder query = new StringBuilder(); query.append(getNamespaceDeclarations()); query.append("DESCRIBE ex:a"); GraphQuery gq = conn.prepareGraphQuery(QueryLanguage.SPARQL, query.toString()); ValueFactory f = conn.getValueFactory(); IRI a = f.createIRI("http://example.org/a"); IRI p = f.createIRI("http://example.org/p"); try (GraphQueryResult evaluate = gq.evaluate();) { Model result = QueryResults.asModel(evaluate); Set<Value> objects = result.filter(a, p, null).objects(); assertNotNull(objects); for (Value object : objects) { if (object instanceof BNode) { assertTrue(result.contains((Resource) object, null, null)); assertEquals(2, result.filter((Resource) object, null, null).size()); } } } }
Example 2
Source File: ComplexSPARQLQueryTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testDescribeAWhere() throws Exception { loadTestData("/testdata-query/dataset-describe.trig"); StringBuilder query = new StringBuilder(); query.append(getNamespaceDeclarations()); query.append("DESCRIBE ?x WHERE {?x rdfs:label \"a\". } "); GraphQuery gq = conn.prepareGraphQuery(QueryLanguage.SPARQL, query.toString()); ValueFactory f = conn.getValueFactory(); IRI a = f.createIRI("http://example.org/a"); IRI p = f.createIRI("http://example.org/p"); try (GraphQueryResult evaluate = gq.evaluate();) { Model result = QueryResults.asModel(evaluate); Set<Value> objects = result.filter(a, p, null).objects(); assertNotNull(objects); for (Value object : objects) { if (object instanceof BNode) { assertTrue(result.contains((Resource) object, null, null)); assertEquals(2, result.filter((Resource) object, null, null).size()); } } } }
Example 3
Source File: ComplexSPARQLQueryTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testDescribeB() throws Exception { loadTestData("/testdata-query/dataset-describe.trig"); StringBuilder query = new StringBuilder(); query.append(getNamespaceDeclarations()); query.append("DESCRIBE ex:b"); GraphQuery gq = conn.prepareGraphQuery(QueryLanguage.SPARQL, query.toString()); ValueFactory f = conn.getValueFactory(); IRI b = f.createIRI("http://example.org/b"); IRI p = f.createIRI("http://example.org/p"); try (GraphQueryResult evaluate = gq.evaluate();) { Model result = QueryResults.asModel(evaluate); Set<Resource> subjects = result.filter(null, p, b).subjects(); assertNotNull(subjects); for (Value subject : subjects) { if (subject instanceof BNode) { assertTrue(result.contains(null, null, subject)); } } } }
Example 4
Source File: ComplexSPARQLQueryTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testDescribeMultipleA() throws Exception { String update = "insert data { <urn:1> <urn:p1> <urn:v> . [] <urn:blank> <urn:1> . <urn:2> <urn:p2> <urn:3> . } "; conn.prepareUpdate(QueryLanguage.SPARQL, update).execute(); StringBuilder query = new StringBuilder(); query.append(getNamespaceDeclarations()); query.append("DESCRIBE <urn:1> <urn:2> "); GraphQuery gq = conn.prepareGraphQuery(QueryLanguage.SPARQL, query.toString()); ValueFactory vf = conn.getValueFactory(); IRI urn1 = vf.createIRI("urn:1"); IRI p1 = vf.createIRI("urn:p1"); IRI p2 = vf.createIRI("urn:p2"); IRI urn2 = vf.createIRI("urn:2"); IRI blank = vf.createIRI("urn:blank"); try (GraphQueryResult evaluate = gq.evaluate();) { Model result = QueryResults.asModel(evaluate); assertTrue(result.contains(urn1, p1, null)); assertTrue(result.contains(null, blank, urn1)); assertTrue(result.contains(urn2, p2, null)); } }
Example 5
Source File: ComplexSPARQLQueryTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testDescribeMultipleB() throws Exception { String update = "insert data { <urn:1> <urn:p1> <urn:v> . <urn:1> <urn:blank> [] . <urn:2> <urn:p2> <urn:3> . } "; conn.prepareUpdate(QueryLanguage.SPARQL, update).execute(); StringBuilder query = new StringBuilder(); query.append(getNamespaceDeclarations()); query.append("DESCRIBE <urn:1> <urn:2> "); GraphQuery gq = conn.prepareGraphQuery(QueryLanguage.SPARQL, query.toString()); ValueFactory vf = conn.getValueFactory(); IRI urn1 = vf.createIRI("urn:1"); IRI p1 = vf.createIRI("urn:p1"); IRI p2 = vf.createIRI("urn:p2"); IRI urn2 = vf.createIRI("urn:2"); IRI blank = vf.createIRI("urn:blank"); try (GraphQueryResult evaluate = gq.evaluate();) { Model result = QueryResults.asModel(evaluate); assertTrue(result.contains(urn1, p1, null)); assertTrue(result.contains(urn1, blank, null)); assertTrue(result.contains(urn2, p2, null)); } }
Example 6
Source File: ComplexSPARQLQueryTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testDescribeMultipleD() throws Exception { String update = "insert data { <urn:1> <urn:p1> <urn:v> . [] <urn:blank> <urn:1>. <urn:2> <urn:p2> <urn:3> . [] <urn:blank> <urn:2> . <urn:4> <urn:p2> <urn:3> . <urn:4> <urn:blank> [] .} "; conn.prepareUpdate(QueryLanguage.SPARQL, update).execute(); StringBuilder query = new StringBuilder(); query.append(getNamespaceDeclarations()); query.append("DESCRIBE <urn:1> <urn:2> <urn:4> "); GraphQuery gq = conn.prepareGraphQuery(QueryLanguage.SPARQL, query.toString()); ValueFactory vf = conn.getValueFactory(); IRI urn1 = vf.createIRI("urn:1"); IRI p1 = vf.createIRI("urn:p1"); IRI p2 = vf.createIRI("urn:p2"); IRI urn2 = vf.createIRI("urn:2"); IRI urn4 = vf.createIRI("urn:4"); IRI blank = vf.createIRI("urn:blank"); try (GraphQueryResult evaluate = gq.evaluate();) { Model result = QueryResults.asModel(evaluate); assertTrue(result.contains(urn1, p1, null)); assertTrue(result.contains(null, blank, urn1)); assertTrue(result.contains(urn2, p2, null)); assertTrue(result.contains(urn4, p2, null)); assertTrue(result.contains(urn4, blank, null)); } }
Example 7
Source File: GraphQueryResultTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testConstructMultiple() throws Exception { GraphQueryResult result = con.prepareGraphQuery(QueryLanguage.SPARQL, multipleConstructQuery).evaluate(); assertTrue("Query result should not be empty", result.hasNext()); Model model = QueryResults.asModel(result); assertFalse("Query result should not be empty", model.isEmpty()); assertEquals(4, model.size()); }
Example 8
Source File: GraphQueryResultTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testDescribeSingle() throws Exception { GraphQueryResult result = con.prepareGraphQuery(QueryLanguage.SPARQL, singleDescribeQuery).evaluate(); assertTrue("Query result should not be empty", result.hasNext()); Model model = QueryResults.asModel(result); assertFalse("Query result should not be empty", model.isEmpty()); assertEquals(1, model.size()); }
Example 9
Source File: GraphQueryResultTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testDescribeEmpty() throws Exception { GraphQueryResult result = con.prepareGraphQuery(QueryLanguage.SPARQL, emptyDescribeQuery).evaluate(); assertFalse("Query result should be empty", result.hasNext()); Model model = QueryResults.asModel(result); assertTrue("Query result should be empty", model.isEmpty()); }
Example 10
Source File: TripleStoreRDF4J.java From powsybl-core with Mozilla Public License 2.0 | 5 votes |
private void write(DataSource ds, RepositoryConnection conn, Resource context) { LOGGER.info("Writing context {}", context); RepositoryResult<Statement> statements; statements = conn.getStatements(null, null, null, context); Model model = QueryResults.asModel(statements); copyNamespacesToModel(conn, model); String outname = context.toString(); write(model, outputStream(ds, outname)); }
Example 11
Source File: ComplexSPARQLQueryTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testDescribeF() throws Exception { loadTestData("/testdata-query/dataset-describe.trig"); StringBuilder query = new StringBuilder(); query.append(getNamespaceDeclarations()); query.append("DESCRIBE ex:f"); GraphQuery gq = conn.prepareGraphQuery(QueryLanguage.SPARQL, query.toString()); ValueFactory vf = conn.getValueFactory(); IRI f = vf.createIRI("http://example.org/f"); IRI p = vf.createIRI("http://example.org/p"); try (GraphQueryResult evaluate = gq.evaluate();) { Model result = QueryResults.asModel(evaluate); assertNotNull(result); assertEquals(4, result.size()); Set<Value> objects = result.filter(f, p, null).objects(); assertNotNull(objects); for (Value object : objects) { if (object instanceof BNode) { Set<Value> childObjects = result.filter((BNode) object, null, null).objects(); assertNotNull(childObjects); for (Value childObject : childObjects) { if (childObject instanceof BNode) { assertTrue(result.contains((BNode) childObject, null, null)); } } } } } }
Example 12
Source File: ComplexSPARQLQueryTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testDescribeWhere() throws Exception { loadTestData("/testdata-query/dataset-describe.trig"); StringBuilder query = new StringBuilder(); query.append(getNamespaceDeclarations()); query.append("DESCRIBE ?x WHERE {?x rdfs:label ?y . } "); GraphQuery gq = conn.prepareGraphQuery(QueryLanguage.SPARQL, query.toString()); ValueFactory vf = conn.getValueFactory(); IRI a = vf.createIRI("http://example.org/a"); IRI b = vf.createIRI("http://example.org/b"); IRI c = vf.createIRI("http://example.org/c"); IRI e = vf.createIRI("http://example.org/e"); IRI f = vf.createIRI("http://example.org/f"); IRI p = vf.createIRI("http://example.org/p"); try (GraphQueryResult evaluate = gq.evaluate();) { Model result = QueryResults.asModel(evaluate); assertTrue(result.contains(a, p, null)); assertTrue(result.contains(b, RDFS.LABEL, null)); assertTrue(result.contains(c, RDFS.LABEL, null)); assertTrue(result.contains(null, p, b)); assertTrue(result.contains(e, RDFS.LABEL, null)); assertTrue(result.contains(null, p, e)); assertFalse(result.contains(f, null, null)); Set<Value> objects = result.filter(a, p, null).objects(); assertNotNull(objects); for (Value object : objects) { if (object instanceof BNode) { assertTrue(result.contains((Resource) object, null, null)); assertEquals(2, result.filter((Resource) object, null, null).size()); } } } }
Example 13
Source File: NTriplesWriterBackgroundTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override protected Model parse(InputStream reader, String baseURI) throws RDFParseException, RDFHandlerException, IOException { return QueryResults .asModel(QueryResults.parseGraphBackground(reader, baseURI, rdfParserFactory.getRDFFormat())); }
Example 14
Source File: JSONLDWriterBackgroundTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override protected Model parse(InputStream reader, String baseURI) throws RDFParseException, RDFHandlerException, IOException { return QueryResults .asModel(QueryResults.parseGraphBackground(reader, baseURI, rdfParserFactory.getRDFFormat())); }
Example 15
Source File: TriGWriterBackgroundTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override protected Model parse(InputStream reader, String baseURI) throws RDFParseException, RDFHandlerException, IOException { return QueryResults .asModel(QueryResults.parseGraphBackground(reader, baseURI, rdfParserFactory.getRDFFormat())); }
Example 16
Source File: BinaryRDFWriterBackgroundTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override protected Model parse(InputStream reader, String baseURI) throws RDFParseException, RDFHandlerException, IOException { return QueryResults .asModel(QueryResults.parseGraphBackground(reader, baseURI, rdfParserFactory.getRDFFormat())); }
Example 17
Source File: RDFXMLWriterBackgroundTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override protected Model parse(InputStream reader, String baseURI) throws RDFParseException, RDFHandlerException, IOException { return QueryResults .asModel(QueryResults.parseGraphBackground(reader, baseURI, rdfParserFactory.getRDFFormat())); }
Example 18
Source File: RDFXMLPrettyWriterBackgroundTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override protected Model parse(InputStream reader, String baseURI) throws RDFParseException, RDFHandlerException, IOException { return QueryResults .asModel(QueryResults.parseGraphBackground(reader, baseURI, rdfParserFactory.getRDFFormat())); }
Example 19
Source File: TriGPrettyWriterBackgroundTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override protected Model parse(InputStream reader, String baseURI) throws RDFParseException, RDFHandlerException, IOException { return QueryResults .asModel(QueryResults.parseGraphBackground(reader, baseURI, rdfParserFactory.getRDFFormat())); }
Example 20
Source File: NQuadsWriterBackgroundTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override protected Model parse(InputStream reader, String baseURI) throws RDFParseException, RDFHandlerException, IOException { return QueryResults .asModel(QueryResults.parseGraphBackground(reader, baseURI, rdfParserFactory.getRDFFormat())); }