@@ -25,6 +25,7 @@ public class KvinConnection extends SailConnectionWrapper {
2525 final KvinSail kvinSail ;
2626 final RDF4JValueConverter valueConverter ;
2727 final LiteralConverter literalConverter ;
28+ private static String KVIN_NS = "kvin:" ;
2829 private final Pattern containerMembershipPredicatePattern =
2930 Pattern .compile ("^http://www.w3.org/1999/02/22-rdf-syntax-ns#_[1-9][0-9]*$" );
3031 private Map <Resource , List <Statement >> stmtsBySubject = new LinkedHashMap <>();
@@ -41,10 +42,11 @@ public void addStatement(Resource subj, IRI pred, Value obj, Resource... context
4142 if (contexts .length == 0 ) {
4243 super .addStatement (subj , pred , obj , contexts );
4344 } else {
45+ var vf = kvinSail .getValueFactory ();
4446 for (Resource ctx : contexts ) {
45- if (ctx != null && ctx .isIRI () && ((IRI ) ctx ).getNamespace ().startsWith ("kvin:" )) {
47+ if (ctx != null && ctx .isIRI () && ((IRI ) ctx ).getNamespace ().startsWith (KVIN_NS )) {
4648 stmtsBySubject .computeIfAbsent (subj , key -> new ArrayList <>()).add (
47- kvinSail . getValueFactory (). createStatement (subj , pred , obj , ctx ));
49+ vf . createStatement (subj , pred , obj , vf . createIRI ( ctx . stringValue (). substring ( KVIN_NS . length ())) ));
4850 } else {
4951 super .addStatement (subj , pred , obj , ctx );
5052 }
@@ -57,10 +59,11 @@ public void addStatement(UpdateContext modify, Resource subj, IRI pred, Value ob
5759 if (contexts .length == 0 ) {
5860 super .addStatement (modify , subj , pred , obj , contexts );
5961 } else {
62+ var vf = kvinSail .getValueFactory ();
6063 for (Resource ctx : contexts ) {
61- if (ctx != null && ctx .isIRI () && ((IRI ) ctx ).getNamespace ().startsWith ("kvin:" )) {
64+ if (ctx != null && ctx .isIRI () && ((IRI ) ctx ).getNamespace ().startsWith (KVIN_NS )) {
6265 stmtsBySubject .computeIfAbsent (subj , key -> new ArrayList <>()).add (
63- kvinSail . getValueFactory (). createStatement (subj , pred , obj , ctx ));
66+ vf . createStatement (subj , pred , obj , vf . createIRI ( ctx . stringValue (). substring ( KVIN_NS . length ())) ));
6467 } else {
6568 super .addStatement (modify , subj , pred , obj , contexts );
6669 }
@@ -83,7 +86,7 @@ private void createKvinTuples() {
8386 IRI item = (IRI ) e .getKey ();
8487 return e .getValue ().stream ().map (stmt -> {
8588 IRI predicate = stmt .getPredicate ();
86- return toKvinTuple (item , predicate , stmt .getObject (), currentTime );
89+ return toKvinTuple (item , predicate , stmt .getObject (), currentTime , stmt . getContext () );
8790 });
8891 //System.out.println(tuple);
8992 }).iterator ())) {
@@ -93,7 +96,7 @@ private void createKvinTuples() {
9396 }
9497 }
9598
96- private KvinTuple toKvinTuple (IRI item , IRI predicate , Value rdfValue , long currentTime ) {
99+ private KvinTuple toKvinTuple (IRI item , IRI predicate , Value rdfValue , long currentTime , Resource context ) {
97100 long time = -1 ;
98101 int seqNr = 0 ;
99102 Object value = null ;
@@ -122,7 +125,8 @@ private KvinTuple toKvinTuple(IRI item, IRI predicate, Value rdfValue, long curr
122125 value = convertValue (rdfValue );
123126 }
124127 return new KvinTuple (convertIri (item ).getURI (), convertIri (predicate ).getURI (),
125- Kvin .DEFAULT_CONTEXT , time < 0 ? currentTime : time , seqNr , value );
128+ context .isIRI () ? convertIri ((IRI ) context ).getURI () : Kvin .DEFAULT_CONTEXT ,
129+ time < 0 ? currentTime : time , seqNr , value );
126130 }
127131
128132 private IReference convertIri (IRI rdfValue ) {
0 commit comments