Java Code Examples for org.eclipse.rdf4j.common.iteration.Iterations#addAll()

The following examples show how to use org.eclipse.rdf4j.common.iteration.Iterations#addAll() . 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: KnowledgeBaseServiceImpl.java    From inception with Apache License 2.0 6 votes vote down vote up
@Override
public List<Statement> listStatementsWithPredicateOrObjectReference(KnowledgeBase kb,
        String aIdentifier)
{
    try (StopWatch watch = new StopWatch(log,
            "listStatementsWithPredicateOrObjectReference(%s)", aIdentifier)) {
        try (RepositoryConnection conn = getConnection(kb)) {
            ValueFactory vf = conn.getValueFactory();
            IRI iri = vf.createIRI(aIdentifier);
            try (RepositoryResult<Statement> predStmts = conn.getStatements(null, iri, null);
                    RepositoryResult<Statement> objStmts = conn.getStatements(null, null,
                            iri)) {
                List<Statement> allStmts = new ArrayList<>();
                Iterations.addAll(predStmts, allStmts);
                Iterations.addAll(objStmts, allStmts);
                return allStmts;
            }
        }
    }
}
 
Example 2
Source File: RepositoryConnectionTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testGetStatements() throws Exception {
	testCon.add(bob, name, nameBob);

	assertTrue("Repository should contain statement", testCon.hasStatement(bob, name, nameBob, false));

	try (RepositoryResult<Statement> result = testCon.getStatements(null, name, null, false);) {
		assertNotNull("Iterator should not be null", result);
		assertTrue("Iterator should not be empty", result.hasNext());

		while (result.hasNext()) {
			Statement st = result.next();
			assertNull("Statement should not be in a context ", st.getContext());
			assertTrue("Statement predicate should be equal to name ", st.getPredicate().equals(name));
		}
	}

	List<Statement> list = Iterations.addAll(testCon.getStatements(null, name, null, false), new ArrayList<>());

	assertNotNull("List should not be null", list);
	assertFalse("List should not be empty", list.isEmpty());
}
 
Example 3
Source File: RepositoryConnectionTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testRemoveStatementCollection() throws Exception {
	testCon.begin();
	testCon.add(alice, name, nameAlice);
	testCon.add(bob, name, nameBob);
	testCon.commit();

	assertThat(testCon.hasStatement(bob, name, nameBob, false)).isTrue();
	assertThat(testCon.hasStatement(alice, name, nameAlice, false)).isTrue();

	try (RepositoryResult<Statement> result = testCon.getStatements(null, null, null, false);) {
		Collection<Statement> c = Iterations.addAll(result, new ArrayList<>());

		testCon.remove(c);

		assertThat(testCon.hasStatement(bob, name, nameBob, false)).isFalse();
		assertThat(testCon.hasStatement(alice, name, nameAlice, false)).isFalse();
	}
}
 
Example 4
Source File: RepositoryConnectionTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testGraphSerialization() throws Exception {
	testCon.add(bob, name, nameBob);
	testCon.add(alice, name, nameAlice);

	try (RepositoryResult<Statement> statements = testCon.getStatements(null, null, null, true);) {
		Model graph = Iterations.addAll(statements, new LinkedHashModel());

		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		ObjectOutputStream out = new ObjectOutputStream(baos);
		out.writeObject(graph);
		out.close();

		ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
		ObjectInputStream in = new ObjectInputStream(bais);
		Model deserializedGraph = (Model) in.readObject();
		in.close();

		assertThat(deserializedGraph.isEmpty()).isFalse();
		assertThat(deserializedGraph).hasSameSizeAs(graph);
		for (Statement st : deserializedGraph) {
			assertThat(graph).contains(st);
			assertThat(testCon.hasStatement(st, true)).isTrue();
		}
	}
}
 
Example 5
Source File: VOIDInferencerConnection.java    From semagrow with Apache License 2.0 6 votes vote down vote up
@Override
public void flushUpdates()
        throws SailException
{
    super.flushUpdates();

    if (statementsRemoved) {
        //logger.debug("statements removed, starting inferencing from scratch");
        clearInferred();
        addAxiomStatements();

        newStatements = new TreeModel();
        Iterations.addAll(getWrappedConnection().getStatements(null, null, null, true), newStatements);

        statementsRemoved = false;
    }

    doInferencing();
}
 
Example 6
Source File: IterationBenchmarks.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Benchmark
public Set<String> asSetAddAll() throws Exception {

	HashSet<String> objects = new HashSet<>();
	Iterations.addAll(getIterator(strings), objects);
	return objects;
}
 
Example 7
Source File: IterationBenchmarks.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Benchmark
public Set<String> asSetDuplicateAddAll() throws Exception {

	HashSet<String> objects = new HashSet<>();
	Iterations.addAll(getIterator(duplicates), objects);
	return objects;

}
 
Example 8
Source File: IterationBenchmarks.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Benchmark
public List<String> asListAddAll() throws Exception {

	List<String> objects = new ArrayList<>();
	Iterations.addAll(getIterator(strings), objects);
	return objects;
}
 
Example 9
Source File: IterationBenchmarks.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Benchmark
public List<String> asListDuplicateAddAll() throws Exception {

	List<String> objects = new ArrayList<>();
	Iterations.addAll(getIterator(duplicates), objects);
	return objects;

}
 
Example 10
Source File: MutableTupleQueryResult.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public <E extends Exception> MutableTupleQueryResult(Collection<String> bindingNames,
		Iteration<? extends BindingSet, E> bindingSetIter) throws E {
	this.bindingNames.addAll(bindingNames);
	Iterations.addAll(bindingSetIter, this.bindingSets);
}