From 3be1701703e530d6e3cd6e3fba0dfb74ba2561f1 Mon Sep 17 00:00:00 2001 From: Jan Robert <15772440+Yalz@users.noreply.github.com> Date: Mon, 5 Aug 2024 14:40:24 +0200 Subject: [PATCH] feat: RepoSink: delete skolem uris (#670) Co-authored-by: Yalz --- .../informatievlaanderen/ldes/ldi/RepositorySink.java | 7 +++++++ .../ldes/ldi/RepositorySinkIT.java | 11 ++++++++--- .../src/test/resources/people/6-updated.nq | 5 +++++ .../repository-sink/src/test/resources/people/6.nq | 6 ++++++ 4 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 ldi-core/repository-sink/src/test/resources/people/6-updated.nq create mode 100644 ldi-core/repository-sink/src/test/resources/people/6.nq diff --git a/ldi-core/repository-sink/src/main/java/be/vlaanderen/informatievlaanderen/ldes/ldi/RepositorySink.java b/ldi-core/repository-sink/src/main/java/be/vlaanderen/informatievlaanderen/ldes/ldi/RepositorySink.java index e1a15e4ac..32b65a8d7 100644 --- a/ldi-core/repository-sink/src/main/java/be/vlaanderen/informatievlaanderen/ldes/ldi/RepositorySink.java +++ b/ldi-core/repository-sink/src/main/java/be/vlaanderen/informatievlaanderen/ldes/ldi/RepositorySink.java @@ -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) { @@ -75,6 +77,11 @@ private Set 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); + } }); } diff --git a/ldi-core/repository-sink/src/test/java/be/vlaanderen/informatievlaanderen/ldes/ldi/RepositorySinkIT.java b/ldi-core/repository-sink/src/test/java/be/vlaanderen/informatievlaanderen/ldes/ldi/RepositorySinkIT.java index 1da54b9f4..1e65f5437 100644 --- a/ldi-core/repository-sink/src/test/java/be/vlaanderen/informatievlaanderen/ldes/ldi/RepositorySinkIT.java +++ b/ldi-core/repository-sink/src/test/java/be/vlaanderen/informatievlaanderen/ldes/ldi/RepositorySinkIT.java @@ -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 testFiles = IntStream.range(1, 6).mapToObj("src/test/resources/people/%d.nq"::formatted).toList(); + final List testFiles = IntStream.rangeClosed(1, 6).mapToObj("src/test/resources/people/%d.nq"::formatted).toList(); populateAndCheckRepository(testFiles, namedGraph); List 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 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 diff --git a/ldi-core/repository-sink/src/test/resources/people/6-updated.nq b/ldi-core/repository-sink/src/test/resources/people/6-updated.nq new file mode 100644 index 000000000..1305f827e --- /dev/null +++ b/ldi-core/repository-sink/src/test/resources/people/6-updated.nq @@ -0,0 +1,5 @@ + "Saylor Swiffer" . + . + "Saylor" . + . + "Swiffer" . diff --git a/ldi-core/repository-sink/src/test/resources/people/6.nq b/ldi-core/repository-sink/src/test/resources/people/6.nq new file mode 100644 index 000000000..aaa4bf10e --- /dev/null +++ b/ldi-core/repository-sink/src/test/resources/people/6.nq @@ -0,0 +1,6 @@ + "Saylor Twift" . + . + "Saylor" . + . + "1Saylor" . + "Twift" . \ No newline at end of file