Skip to content

Commit

Permalink
feat: RepoSink: delete skolem uris (#670)
Browse files Browse the repository at this point in the history
Co-authored-by: Yalz <[email protected]>
  • Loading branch information
Yalz and Yalz authored Aug 5, 2024
1 parent 2b81020 commit 3be1701
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
import java.util.Deque;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;

/**
* Component that will write linked data models to a specified triples store or RDF repository
*/
public class RepositorySink {
private static final Pattern SKOLEM_PATTERN = Pattern.compile(".*/.well-known/genid/.*");
private final RepositorySinkConnection repositorySinkConnection;

public RepositorySink(String hostUrl, String repositoryId, String namedGraph) {
Expand Down Expand Up @@ -75,6 +77,11 @@ private Set<Resource> getAllSubjectsFromModel(org.eclipse.rdf4j.model.Model mode
subjectStack.push(bnode);
subjects.add(bnode);
}
if (SKOLEM_PATTERN.matcher(object.stringValue()).matches()) {
Resource bnode = (Resource) object;
subjectStack.push(bnode);
subjects.add(bnode);
}
});

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,24 @@ void when_DeleteEntities_Then_EntitiesRemovedFromStore(String namedGraph) throws
void when_UpdateEntities_Then_OldTriplesRemoved(String namedGraph) throws Exception {
repositorySink = new RepositorySink(subject, LOCAL_REPOSITORY_ID, namedGraph);

final List<String> testFiles = IntStream.range(1, 6).mapToObj("src/test/resources/people/%d.nq"::formatted).toList();
final List<String> testFiles = IntStream.rangeClosed(1, 6).mapToObj("src/test/resources/people/%d.nq"::formatted).toList();
populateAndCheckRepository(testFiles, namedGraph);

List<org.apache.jena.rdf.model.Model> models = List.of(RDFParser.source("people/5-updated.nq").toModel());
repositorySink.process(models);

models = List.of(RDFParser.source("people/6-updated.nq").toModel());
repositorySink.process(models);

List<Statement> statements = repositorySink.getRepositoryConnection()
.getStatements(null, null, null).stream().toList();

assertThat(statements)
.hasSize(21)
.hasSize(26)
.anyMatch(statement -> statement.getObject().stringValue().equals("CHANGED"))
.noneMatch(statement -> statement.getObject().stringValue().equals("Taylor"));
.noneMatch(statement -> statement.getObject().stringValue().equals("Taylor"))
.noneMatch(statement -> statement.getObject().stringValue().equals("Twift"))
.noneMatch(statement -> statement.getPredicate().stringValue().equals("http://www.w3.org/2001/vcard-rdf/3.0#Nickname"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<http://somewhere/SaylorTwift/> <http://www.w3.org/2001/vcard-rdf/3.0#FN> "Saylor Swiffer" .
<http://somewhere/SaylorTwift/> <http://www.w3.org/2001/vcard-rdf/3.0#N> <http://somewhere/.well-known/genid/3> .
<http://somewhere/.well-known/genid/3> <http://www.w3.org/2001/vcard-rdf/3.0#Family> "Saylor" .
<http://somewhere/.well-known/genid/3> <http://www.w3.org/2001/vcard-rdf/3.0#Given> <http://somewhere/.well-known/genid/4> .
<http://somewhere/.well-known/genid/4> <http://www.w3.org/2001/vcard-rdf/3.0#Last> "Swiffer" .
6 changes: 6 additions & 0 deletions ldi-core/repository-sink/src/test/resources/people/6.nq
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<http://somewhere/SaylorTwift/> <http://www.w3.org/2001/vcard-rdf/3.0#FN> "Saylor Twift" .
<http://somewhere/SaylorTwift/> <http://www.w3.org/2001/vcard-rdf/3.0#N> <http://somewhere/.well-known/genid/1> .
<http://somewhere/.well-known/genid/1> <http://www.w3.org/2001/vcard-rdf/3.0#Family> "Saylor" .
<http://somewhere/.well-known/genid/1> <http://www.w3.org/2001/vcard-rdf/3.0#Given> <http://somewhere/.well-known/genid/2> .
<http://somewhere/.well-known/genid/2> <http://www.w3.org/2001/vcard-rdf/3.0#Nickname> "1Saylor" .
<http://somewhere/.well-known/genid/2> <http://www.w3.org/2001/vcard-rdf/3.0#Last> "Twift" .

0 comments on commit 3be1701

Please sign in to comment.