Java Code Examples for org.eclipse.rdf4j.repository.RepositoryConnection#remove()

The following examples show how to use org.eclipse.rdf4j.repository.RepositoryConnection#remove() . 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: RdfCloudTripleStoreConnectionTest.java    From rya with Apache License 2.0 6 votes vote down vote up
public void testDuplicateLiterals() throws Exception {
    RepositoryConnection conn = repository.getConnection();

    IRI loadPerc = VF.createIRI(litdupsNS, "loadPerc");
    Literal lit1 = VF.createLiteral(0.0);
    Literal lit2 = VF.createLiteral(0.0);
    Literal lit3 = VF.createLiteral(0.0);

    conn.add(cpu, loadPerc, lit1);
    conn.add(cpu, loadPerc, lit2);
    conn.add(cpu, loadPerc, lit3);
    conn.commit();

    RepositoryResult<Statement> result = conn.getStatements(cpu, loadPerc, null, true);
    int count = 0;
    while (result.hasNext()) {
        count++;
        result.next();
    }
    result.close();
    assertEquals(1, count);

    //clean up
    conn.remove(cpu, loadPerc, lit1);
    conn.close();
}
 
Example 2
Source File: RdfCloudTripleStoreConnectionTest.java    From rya with Apache License 2.0 6 votes vote down vote up
public void testNotDuplicateUris() throws Exception {
    RepositoryConnection conn = repository.getConnection();

    IRI loadPerc = VF.createIRI(litdupsNS, "loadPerc");
    IRI uri1 = VF.createIRI(litdupsNS, "uri1");
    IRI uri2 = VF.createIRI(litdupsNS, "uri1");
    IRI uri3 = VF.createIRI(litdupsNS, "uri1");

    conn.add(cpu, loadPerc, uri1);
    conn.add(cpu, loadPerc, uri2);
    conn.add(cpu, loadPerc, uri3);
    conn.commit();

    RepositoryResult<Statement> result = conn.getStatements(cpu, loadPerc, null, true);
    int count = 0;
    while (result.hasNext()) {
        count++;
        result.next();
    }
    result.close();
    assertEquals(1, count);

    //clean up
    conn.remove(cpu, loadPerc, uri1);
    conn.close();
}
 
Example 3
Source File: NoReification.java    From inception with Apache License 2.0 5 votes vote down vote up
private void delete(RepositoryConnection aConnection, KnowledgeBase kb, String aIdentifier)
{
    ValueFactory vf = aConnection.getValueFactory();
    IRI iri = vf.createIRI(aIdentifier);
    try (RepositoryResult<Statement> subStmts = aConnection.getStatements(iri, null, null);
            RepositoryResult<Statement> predStmts = aConnection.getStatements(null, iri, null);
            RepositoryResult<Statement> objStmts = aConnection.getStatements(null, null, iri)) {
        aConnection.remove(subStmts);
        aConnection.remove(predStmts);
        aConnection.remove(objStmts);
    }
}
 
Example 4
Source File: NoReification.java    From inception with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteStatement(RepositoryConnection aConnection, KnowledgeBase kb,
        KBStatement aStatement)
{
    aConnection.remove(aStatement.getOriginalTriples());
    aStatement.setOriginalTriples(Collections.emptySet());
}
 
Example 5
Source File: ReificationStrategy.java    From inception with Apache License 2.0 5 votes vote down vote up
default void upsert(RepositoryConnection aConnection, Collection<Statement> aOriginalTriples,
        Collection<Statement> aNewTriples)
{
    // Delete all original triples except the ones which we would re-create anyway
    Set<Statement> triplesToDelete = new HashSet<>();
    aOriginalTriples.forEach(triplesToDelete::add);
    triplesToDelete.removeAll(aNewTriples);
    aConnection.remove(triplesToDelete);
    
    // Store the new triples
    aConnection.add(aNewTriples);
}
 
Example 6
Source File: WikiDataReification.java    From inception with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteStatement(RepositoryConnection aConnection, KnowledgeBase kb,
        KBStatement aStatement)
{
    // Delete original triples
    aConnection.remove(aStatement.getOriginalTriples());
    aConnection.remove(aStatement.getQualifiers().stream()
            .flatMap(qualifier -> qualifier.getOriginalTriples().stream())
            .collect(toList()));
    
    // Clear original triples
    aStatement.setOriginalTriples(emptySet());
    aStatement.getQualifiers()
            .forEach(qualifier -> qualifier.setOriginalTriples(emptySet()));
}
 
Example 7
Source File: WikiDataReification.java    From inception with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteQualifier(RepositoryConnection aConnection, KnowledgeBase kb,
        KBQualifier aQualifier)
{
    if (aQualifier.getStatement().getStatementId() == null) {
        log.error("No statementId");
    }
    else {
        RepositoryConnection conn = aConnection;
        conn.remove(aQualifier.getOriginalTriples());

        aQualifier.getStatement().getQualifiers().remove(aQualifier);
        aQualifier.setOriginalTriples(Collections.emptySet());
    }
}
 
Example 8
Source File: RemoveServlet.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void remove(RepositoryConnection con, Resource subj, IRI pred, Value obj, WorkbenchRequest req)
		throws BadRequestException, RepositoryException {
	if (req.isParameterPresent(CONTEXT)) {
		Resource ctx = req.getResource(CONTEXT);
		if (subj == null && pred == null && obj == null) {
			con.clear(ctx);
		} else {
			con.remove(subj, pred, obj, ctx);
		}
	} else {
		con.remove(subj, pred, obj);
	}
}
 
Example 9
Source File: RdfCloudTripleStoreConnectionTest.java    From rya with Apache License 2.0 5 votes vote down vote up
public void testAddStatement() throws Exception {
        RepositoryConnection conn = repository.getConnection();

        IRI loadPerc = VF.createIRI(litdupsNS, "loadPerc");
        IRI uri1 = VF.createIRI(litdupsNS, "uri1");
        conn.add(cpu, loadPerc, uri1);
        conn.commit();

        RepositoryResult<Statement> result = conn.getStatements(cpu, loadPerc, null, true);
        int count = 0;
        while (result.hasNext()) {
            count++;
            result.next();
        }
        result.close();
        assertEquals(1, count);

        //clean up
        conn.remove(cpu, loadPerc, uri1);

//        //test removal
        result = conn.getStatements(cpu, loadPerc, null, true);
        count = 0;
        while (result.hasNext()) {
            count++;
            result.next();
        }
        result.close();
        assertEquals(0, count);

        conn.close();
    }
 
Example 10
Source File: RemoveStatementsOperation.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void execute(RepositoryConnection con) throws RepositoryException {
	con.remove(getSubject(), getPredicate(), getObject(), getContexts());
}