Java Code Examples for org.eclipse.rdf4j.query.algebra.evaluation.TripleSource#getStatements()
The following examples show how to use
org.eclipse.rdf4j.query.algebra.evaluation.TripleSource#getStatements() .
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: TripleSources.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Returns the single statement with the given subject, predicate and object or null if none exists. Context * information is disregarded. * * @param subj null for any. * @param pred null for any. * @param obj null for any. * @throws QueryEvaluationException If there is more than one such statement. */ public static Statement single(Resource subj, IRI pred, Value obj, TripleSource store) throws QueryEvaluationException { Statement stmt; try (CloseableIteration<? extends Statement, QueryEvaluationException> stmts = store.getStatements(subj, pred, obj)) { if (stmts.hasNext()) { stmt = stmts.next(); while (stmts.hasNext()) { Statement nextStmt = stmts.next(); if (!org.eclipse.rdf4j.model.util.Statements.isSameTriple(stmt, nextStmt)) { throw new QueryEvaluationException( "Multiple statements for pattern: " + subj + " " + pred + " " + obj); } } } else { stmt = null; } } return stmt; }
Example 2
Source File: MemTripleSourceTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Test method for * {@link org.eclipse.rdf4j.sail.memory.MemTripleSource#getStatements(org.eclipse.rdf4j.model.Resource, org.eclipse.rdf4j.model.IRI, org.eclipse.rdf4j.model.Value, org.eclipse.rdf4j.model.Resource[])} * . */ @Test public final void testGetStatementsThreeContextsThreeContexts() throws Exception { loadTestData("/alp-testdata.ttl", this.alice, this.bob, this.mary); TripleSource source = getTripleSourceCommitted(); try (CloseableIteration<? extends Statement, QueryEvaluationException> statements = source.getStatements(null, null, null, this.alice, this.bob, this.mary)) { List<Statement> list = Iterations.asList(statements); assertEquals(24, list.size()); } }
Example 3
Source File: MemTripleSourceTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Test method for * {@link org.eclipse.rdf4j.sail.memory.MemTripleSource#getStatements(org.eclipse.rdf4j.model.Resource, org.eclipse.rdf4j.model.IRI, org.eclipse.rdf4j.model.Value, org.eclipse.rdf4j.model.Resource[])} * . */ @Test public final void testGetStatementsOneContextPredicateOwlClassNoContexts() throws Exception { loadTestData("/alp-testdata.ttl", this.alice); TripleSource source = getTripleSourceCommitted(); try (CloseableIteration<? extends Statement, QueryEvaluationException> statements = source.getStatements(null, RDF.TYPE, OWL.CLASS)) { List<Statement> list = Iterations.asList(statements); assertEquals(4, list.size()); } }
Example 4
Source File: MemTripleSourceTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Test method for * {@link org.eclipse.rdf4j.sail.memory.MemTripleSource#getStatements(org.eclipse.rdf4j.model.Resource, org.eclipse.rdf4j.model.IRI, org.eclipse.rdf4j.model.Value, org.eclipse.rdf4j.model.Resource[])} * . */ @Test public final void testGetStatementsNoContextsPredicateOwlClassNoContexts() throws Exception { loadTestData("/alp-testdata.ttl"); TripleSource source = getTripleSourceCommitted(); try (CloseableIteration<? extends Statement, QueryEvaluationException> statements = source.getStatements(null, RDF.TYPE, OWL.CLASS)) { List<Statement> list = Iterations.asList(statements); assertEquals(4, list.size()); } }
Example 5
Source File: MemTripleSourceTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Test method for * {@link org.eclipse.rdf4j.sail.memory.MemTripleSource#getStatements(org.eclipse.rdf4j.model.Resource, org.eclipse.rdf4j.model.IRI, org.eclipse.rdf4j.model.Value, org.eclipse.rdf4j.model.Resource[])} * . */ @Test public final void testGetStatementsTwoContextsPredicateOwlClassNoContexts() throws Exception { loadTestData("/alp-testdata.ttl", this.alice, this.bob); TripleSource source = getTripleSourceCommitted(); try (CloseableIteration<? extends Statement, QueryEvaluationException> statements = source.getStatements(null, RDF.TYPE, OWL.CLASS)) { List<Statement> list = Iterations.asList(statements); assertEquals(8, list.size()); } }
Example 6
Source File: MemTripleSourceTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Test method for * {@link org.eclipse.rdf4j.sail.memory.MemTripleSource#getStatements(org.eclipse.rdf4j.model.Resource, org.eclipse.rdf4j.model.IRI, org.eclipse.rdf4j.model.Value, org.eclipse.rdf4j.model.Resource[])} * . */ @Test public final void testGetStatementsTwoContextsPredicateExClassTwoContexts() throws Exception { loadTestData("/alp-testdata.ttl", this.alice, this.bob); TripleSource source = getTripleSourceCommitted(); try (CloseableIteration<? extends Statement, QueryEvaluationException> statements = source.getStatements(null, RDFS.SUBCLASSOF, f.createIRI(EX_NS, "A"), this.alice, this.bob)) { List<Statement> list = Iterations.asList(statements); assertEquals(6, list.size()); } }
Example 7
Source File: MemTripleSourceTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Test method for * {@link org.eclipse.rdf4j.sail.memory.MemTripleSource#getStatements(org.eclipse.rdf4j.model.Resource, org.eclipse.rdf4j.model.IRI, org.eclipse.rdf4j.model.Value, org.eclipse.rdf4j.model.Resource[])} * . */ @Test public final void testGetStatementsNoContextsPredicateOwlClassTwoContexts() throws Exception { loadTestData("/alp-testdata.ttl"); TripleSource source = getTripleSourceCommitted(); try (CloseableIteration<? extends Statement, QueryEvaluationException> statements = source.getStatements(null, RDF.TYPE, OWL.CLASS, this.alice, this.bob)) { List<Statement> list = Iterations.asList(statements); assertEquals(0, list.size()); } }
Example 8
Source File: MemTripleSourceTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Test method for * {@link org.eclipse.rdf4j.sail.memory.MemTripleSource#getStatements(org.eclipse.rdf4j.model.Resource, org.eclipse.rdf4j.model.IRI, org.eclipse.rdf4j.model.Value, org.eclipse.rdf4j.model.Resource[])} * . */ @Test public final void testGetStatementsOneContextPredicateExClassOneContext() throws Exception { loadTestData("/alp-testdata.ttl", this.alice); TripleSource source = getTripleSourceCommitted(); try (CloseableIteration<? extends Statement, QueryEvaluationException> statements = source.getStatements(null, RDFS.SUBCLASSOF, f.createIRI(EX_NS, "A"), this.alice)) { List<Statement> list = Iterations.asList(statements); assertEquals(3, list.size()); } }
Example 9
Source File: MemTripleSourceTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Test method for * {@link org.eclipse.rdf4j.sail.memory.MemTripleSource#getStatements(org.eclipse.rdf4j.model.Resource, org.eclipse.rdf4j.model.IRI, org.eclipse.rdf4j.model.Value, org.eclipse.rdf4j.model.Resource[])} * . */ @Test public final void testGetStatementsNoContextsPredicateExClassNoContexts() throws Exception { loadTestData("/alp-testdata.ttl"); TripleSource source = getTripleSourceCommitted(); try (CloseableIteration<? extends Statement, QueryEvaluationException> statements = source.getStatements(null, RDFS.SUBCLASSOF, f.createIRI(EX_NS, "A"))) { List<Statement> list = Iterations.asList(statements); assertEquals(3, list.size()); } }
Example 10
Source File: MemTripleSourceTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Test method for * {@link org.eclipse.rdf4j.sail.memory.MemTripleSource#getStatements(org.eclipse.rdf4j.model.Resource, org.eclipse.rdf4j.model.IRI, org.eclipse.rdf4j.model.Value, org.eclipse.rdf4j.model.Resource[])} * . */ @Test public final void testGetStatementsNoContextsPredicateOwlThingTwoContexts() throws Exception { loadTestData("/alp-testdata.ttl"); TripleSource source = getTripleSourceCommitted(); try (CloseableIteration<? extends Statement, QueryEvaluationException> statements = source.getStatements(null, RDFS.SUBCLASSOF, OWL.THING, this.alice, this.bob)) { List<Statement> list = Iterations.asList(statements); assertEquals(0, list.size()); } }
Example 11
Source File: MemTripleSourceTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Test method for * {@link org.eclipse.rdf4j.sail.memory.MemTripleSource#getStatements(org.eclipse.rdf4j.model.Resource, org.eclipse.rdf4j.model.IRI, org.eclipse.rdf4j.model.Value, org.eclipse.rdf4j.model.Resource[])} * . */ @Test public final void testGetStatementsTwoContextsOnePredicateTwoContexts() throws Exception { loadTestData("/alp-testdata.ttl", this.alice, this.bob); TripleSource source = getTripleSourceCommitted(); try (CloseableIteration<? extends Statement, QueryEvaluationException> statements = source.getStatements(null, RDFS.SUBCLASSOF, null, this.alice, this.bob)) { List<Statement> list = Iterations.asList(statements); assertEquals(8, list.size()); } }
Example 12
Source File: MemTripleSourceTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Test method for * {@link org.eclipse.rdf4j.sail.memory.MemTripleSource#getStatements(org.eclipse.rdf4j.model.Resource, org.eclipse.rdf4j.model.IRI, org.eclipse.rdf4j.model.Value, org.eclipse.rdf4j.model.Resource[])} * . */ @Test public final void testGetStatementsOneContextExClassPredicateTwoContexts() throws Exception { loadTestData("/alp-testdata.ttl", this.alice); TripleSource source = getTripleSourceCommitted(); try (CloseableIteration<? extends Statement, QueryEvaluationException> statements = source .getStatements(f.createIRI(EX_NS, "C"), RDFS.SUBCLASSOF, null, this.alice, this.bob)) { List<Statement> list = Iterations.asList(statements); assertEquals(1, list.size()); } }
Example 13
Source File: MemTripleSourceTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Test method for * {@link org.eclipse.rdf4j.sail.memory.MemTripleSource#getStatements(org.eclipse.rdf4j.model.Resource, org.eclipse.rdf4j.model.IRI, org.eclipse.rdf4j.model.Value, org.eclipse.rdf4j.model.Resource[])} * . */ @Test public final void testGetStatementsTwoContextsExClassPredicateNoContexts() throws Exception { loadTestData("/alp-testdata.ttl", this.alice, this.bob); TripleSource source = getTripleSourceCommitted(); try (CloseableIteration<? extends Statement, QueryEvaluationException> statements = source .getStatements(f.createIRI(EX_NS, "C"), RDFS.SUBCLASSOF, null)) { List<Statement> list = Iterations.asList(statements); assertEquals(2, list.size()); } }
Example 14
Source File: MemTripleSourceTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Test method for * {@link org.eclipse.rdf4j.sail.memory.MemTripleSource#getStatements(org.eclipse.rdf4j.model.Resource, org.eclipse.rdf4j.model.IRI, org.eclipse.rdf4j.model.Value, org.eclipse.rdf4j.model.Resource[])} * . */ @Test public final void testGetStatementsOneContextPredicateExClassNoContexts() throws Exception { loadTestData("/alp-testdata.ttl", this.alice); TripleSource source = getTripleSourceCommitted(); try (CloseableIteration<? extends Statement, QueryEvaluationException> statements = source.getStatements(null, RDFS.SUBCLASSOF, f.createIRI(EX_NS, "A"))) { List<Statement> list = Iterations.asList(statements); assertEquals(3, list.size()); } }
Example 15
Source File: MemTripleSourceTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Test method for * {@link org.eclipse.rdf4j.sail.memory.MemTripleSource#getStatements(org.eclipse.rdf4j.model.Resource, org.eclipse.rdf4j.model.IRI, org.eclipse.rdf4j.model.Value, org.eclipse.rdf4j.model.Resource[])} * . */ @Test public final void testGetStatementsNoContextsOnePredicateOneContext() throws Exception { loadTestData("/alp-testdata.ttl"); TripleSource source = getTripleSourceCommitted(); try (CloseableIteration<? extends Statement, QueryEvaluationException> statements = source.getStatements(null, RDFS.SUBCLASSOF, null, this.alice)) { List<Statement> list = Iterations.asList(statements); assertEquals(0, list.size()); } }
Example 16
Source File: MemTripleSourceTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Test method for * {@link org.eclipse.rdf4j.sail.memory.MemTripleSource#getStatements(org.eclipse.rdf4j.model.Resource, org.eclipse.rdf4j.model.IRI, org.eclipse.rdf4j.model.Value, org.eclipse.rdf4j.model.Resource[])} * . */ @Test public final void testGetStatementsTwoContextsOnePredicate() throws Exception { loadTestData("/alp-testdata.ttl", this.alice, this.bob); TripleSource source = getTripleSourceCommitted(); try (CloseableIteration<? extends Statement, QueryEvaluationException> statements = source.getStatements(null, RDFS.SUBCLASSOF, null)) { List<Statement> list = Iterations.asList(statements); assertEquals(8, list.size()); } }
Example 17
Source File: MemTripleSourceTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Test method for * {@link org.eclipse.rdf4j.sail.memory.MemTripleSource#getStatements(org.eclipse.rdf4j.model.Resource, org.eclipse.rdf4j.model.IRI, org.eclipse.rdf4j.model.Value, org.eclipse.rdf4j.model.Resource[])} * . */ @Test public final void testGetStatementsTwoContextsPredicateExClassOneContext() throws Exception { loadTestData("/alp-testdata.ttl", this.alice, this.bob); TripleSource source = getTripleSourceCommitted(); try (CloseableIteration<? extends Statement, QueryEvaluationException> statements = source.getStatements(null, RDFS.SUBCLASSOF, f.createIRI(EX_NS, "A"), this.alice)) { List<Statement> list = Iterations.asList(statements); assertEquals(3, list.size()); } }
Example 18
Source File: MemTripleSourceTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Test method for * {@link org.eclipse.rdf4j.sail.memory.MemTripleSource#getStatements(org.eclipse.rdf4j.model.Resource, org.eclipse.rdf4j.model.IRI, org.eclipse.rdf4j.model.Value, org.eclipse.rdf4j.model.Resource[])} * . */ @Test public final void testGetStatementsNoContextsOnePredicate() throws Exception { loadTestData("/alp-testdata.ttl"); TripleSource source = getTripleSourceCommitted(); try (CloseableIteration<? extends Statement, QueryEvaluationException> statements = source.getStatements(null, RDFS.SUBCLASSOF, null)) { List<Statement> list = Iterations.asList(statements); assertEquals(4, list.size()); } }
Example 19
Source File: MemTripleSourceTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Test method for * {@link org.eclipse.rdf4j.sail.memory.MemTripleSource#getStatements(org.eclipse.rdf4j.model.Resource, org.eclipse.rdf4j.model.IRI, org.eclipse.rdf4j.model.Value, org.eclipse.rdf4j.model.Resource[])} * . */ @Test public final void testGetStatementsNoContextsExClassPredicateTwoContexts() throws Exception { loadTestData("/alp-testdata.ttl"); TripleSource source = getTripleSourceCommitted(); try (CloseableIteration<? extends Statement, QueryEvaluationException> statements = source .getStatements(f.createIRI(EX_NS, "C"), RDFS.SUBCLASSOF, null, this.alice, this.bob)) { List<Statement> list = Iterations.asList(statements); assertEquals(0, list.size()); } }
Example 20
Source File: MemoryStoreWithHalyardStrategy.java From Halyard with Apache License 2.0 | 4 votes |
@Override protected NotifyingSailConnection getConnectionInternal() throws SailException { return new MemoryStoreConnection(this) { @Override protected EvaluationStrategy getEvaluationStrategy(Dataset dataset, final TripleSource tripleSource) { EvaluationStrategy es = new HalyardEvaluationStrategy(new TripleSource() { @Override public CloseableIteration<? extends Statement, QueryEvaluationException> getStatements(Resource subj, IRI pred, Value obj, Resource... contexts) throws QueryEvaluationException { return new FilterIteration<Statement, QueryEvaluationException>(tripleSource.getStatements(subj, pred, obj, contexts)){ boolean first = true; @Override public boolean hasNext() throws QueryEvaluationException { if (first) try { first = false; Thread.sleep(20); } catch (InterruptedException ex) { //ignore } return super.hasNext(); //To change body of generated methods, choose Tools | Templates. } @Override protected boolean accept(Statement object) throws QueryEvaluationException { return true; } }; } @Override public ValueFactory getValueFactory() { return tripleSource.getValueFactory(); } }, dataset, null, new HalyardEvaluationStatistics(null, null), -1); es.setOptimizerPipeline(new StandardQueryOptimizerPipeline(es, tripleSource, new EvaluationStatistics())); return es; } }; }