Skip to content

Commit 2d964d4

Browse files
committed
Support empty context when inserting data.
1 parent 71d56ea commit 2d964d4

File tree

1 file changed

+5
-3
lines changed
  • bundles/io.github.linkedfactory.core/src/main/java/io/github/linkedfactory/core/rdf4j/kvin

1 file changed

+5
-3
lines changed

bundles/io.github.linkedfactory.core/src/main/java/io/github/linkedfactory/core/rdf4j/kvin/KvinConnection.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ public void addStatement(Resource subj, IRI pred, Value obj, Resource... context
4545
var vf = kvinSail.getValueFactory();
4646
for (Resource ctx : contexts) {
4747
if (ctx != null && ctx.isIRI() && ((IRI) ctx).getNamespace().startsWith(KVIN_NS)) {
48+
String newCtx = ctx.stringValue().substring(KVIN_NS.length());
4849
stmtsBySubject.computeIfAbsent(subj, key -> new ArrayList<>()).add(
49-
vf.createStatement(subj, pred, obj, vf.createIRI(ctx.stringValue().substring(KVIN_NS.length()))));
50+
vf.createStatement(subj, pred, obj, newCtx.isEmpty() ? null : vf.createIRI(newCtx)));
5051
} else {
5152
super.addStatement(subj, pred, obj, ctx);
5253
}
@@ -62,8 +63,9 @@ public void addStatement(UpdateContext modify, Resource subj, IRI pred, Value ob
6263
var vf = kvinSail.getValueFactory();
6364
for (Resource ctx : contexts) {
6465
if (ctx != null && ctx.isIRI() && ((IRI) ctx).getNamespace().startsWith(KVIN_NS)) {
66+
String newCtx = ctx.stringValue().substring(KVIN_NS.length());
6567
stmtsBySubject.computeIfAbsent(subj, key -> new ArrayList<>()).add(
66-
vf.createStatement(subj, pred, obj, vf.createIRI(ctx.stringValue().substring(KVIN_NS.length()))));
68+
vf.createStatement(subj, pred, obj, newCtx.isEmpty() ? null : vf.createIRI(newCtx)));
6769
} else {
6870
super.addStatement(modify, subj, pred, obj, contexts);
6971
}
@@ -125,7 +127,7 @@ private KvinTuple toKvinTuple(IRI item, IRI predicate, Value rdfValue, long curr
125127
value = convertValue(rdfValue);
126128
}
127129
return new KvinTuple(convertIri(item).getURI(), convertIri(predicate).getURI(),
128-
context.isIRI() ? convertIri((IRI) context).getURI() : Kvin.DEFAULT_CONTEXT,
130+
context != null && context.isIRI() ? convertIri((IRI) context).getURI() : Kvin.DEFAULT_CONTEXT,
129131
time < 0 ? currentTime : time, seqNr, value);
130132
}
131133

0 commit comments

Comments
 (0)