n3 1.22.1 → 1.22.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/N3Store.js CHANGED
@@ -813,6 +813,7 @@ class N3Store {
813
813
  * Blank Nodes will be normalized.
814
814
  */
815
815
  addAll(quads) {
816
+ if (quads instanceof DatasetCoreAndReadableStream) quads = quads.filtered;
816
817
  if (Array.isArray(quads)) this.addQuads(quads);else if (quads instanceof N3Store && quads._entityIndex === this._entityIndex) {
817
818
  if (quads._size !== 0) {
818
819
  this._graphs = merge(this._graphs, quads._graphs);
@@ -831,6 +832,7 @@ class N3Store {
831
832
  * Blank Nodes will be normalized.
832
833
  */
833
834
  contains(other) {
835
+ if (other instanceof DatasetCoreAndReadableStream) other = other.filtered;
834
836
  if (other === this) return true;
835
837
  if (!(other instanceof N3Store) || this._entityIndex !== other._entityIndex) return other.every(quad => this.has(quad));
836
838
  const g1 = this._graphs,
@@ -870,6 +872,7 @@ class N3Store {
870
872
  * Returns a new dataset that contains all quads from the current dataset that are not included in the given dataset.
871
873
  */
872
874
  difference(other) {
875
+ if (other && other instanceof DatasetCoreAndReadableStream) other = other.filtered;
873
876
  if (other === this) return new N3Store({
874
877
  entityIndex: this._entityIndex
875
878
  });
@@ -893,6 +896,7 @@ class N3Store {
893
896
  * Blank Nodes will be normalized.
894
897
  */
895
898
  equals(other) {
899
+ if (other instanceof DatasetCoreAndReadableStream) other = other.filtered;
896
900
  return other === this || this.size === other.size && this.contains(other);
897
901
  }
898
902
 
@@ -913,6 +917,7 @@ class N3Store {
913
917
  * Returns a new dataset containing all quads from the current dataset that are also included in the given dataset.
914
918
  */
915
919
  intersection(other) {
920
+ if (other instanceof DatasetCoreAndReadableStream) other = other.filtered;
916
921
  if (other === this) {
917
922
  const store = new N3Store({
918
923
  entityIndex: this._entityIndex
@@ -1072,20 +1077,32 @@ class DatasetCoreAndReadableStream extends _readableStream.Readable {
1072
1077
  factory: n3Store._factory,
1073
1078
  entityIndex: this.options.entityIndex
1074
1079
  });
1075
- const graphs = n3Store._getGraphs(graph);
1076
1080
  let subjectId, predicateId, objectId;
1077
1081
 
1078
1082
  // Translate IRIs to internal index keys.
1079
1083
  if (subject && !(subjectId = newStore._termToNumericId(subject)) || predicate && !(predicateId = newStore._termToNumericId(predicate)) || object && !(objectId = newStore._termToNumericId(object))) return newStore;
1080
- for (const graph in graphs) {
1081
- const subjects = indexMatch(graphs[graph].subjects, [subjectId, predicateId, objectId]);
1082
- if (subjects) {
1083
- newStore._graphs[graph] = {
1084
- subjects,
1085
- predicates: indexMatch(graphs[graph].predicates, [predicateId, objectId, subjectId]),
1086
- objects: indexMatch(graphs[graph].objects, [objectId, subjectId, predicateId])
1087
- };
1084
+ const graphs = n3Store._getGraphs(graph);
1085
+ for (const graphKey in graphs) {
1086
+ let subjects, predicates, objects;
1087
+ if (!subjectId && predicateId) {
1088
+ if (predicates = indexMatch(graphs[graphKey].predicates, [predicateId, objectId, subjectId])) {
1089
+ subjects = indexMatch(graphs[graphKey].subjects, [subjectId, predicateId, objectId]);
1090
+ objects = indexMatch(graphs[graphKey].objects, [objectId, subjectId, predicateId]);
1091
+ }
1092
+ } else if (objectId) {
1093
+ if (objects = indexMatch(graphs[graphKey].objects, [objectId, subjectId, predicateId])) {
1094
+ subjects = indexMatch(graphs[graphKey].subjects, [subjectId, predicateId, objectId]);
1095
+ predicates = indexMatch(graphs[graphKey].predicates, [predicateId, objectId, subjectId]);
1096
+ }
1097
+ } else if (subjects = indexMatch(graphs[graphKey].subjects, [subjectId, predicateId, objectId])) {
1098
+ predicates = indexMatch(graphs[graphKey].predicates, [predicateId, objectId, subjectId]);
1099
+ objects = indexMatch(graphs[graphKey].objects, [objectId, subjectId, predicateId]);
1088
1100
  }
1101
+ if (subjects) newStore._graphs[graphKey] = {
1102
+ subjects,
1103
+ predicates,
1104
+ objects
1105
+ };
1089
1106
  }
1090
1107
  newStore._size = null;
1091
1108
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n3",
3
- "version": "1.22.1",
3
+ "version": "1.22.3",
4
4
  "description": "Lightning fast, asynchronous, streaming Turtle / N3 / RDF library.",
5
5
  "author": "Ruben Verborgh <ruben.verborgh@gmail.com>",
6
6
  "keywords": [
@@ -40,6 +40,7 @@
40
40
  "docco": "^0.9.1",
41
41
  "eslint": "^8.57.0",
42
42
  "eslint-plugin-import": "^2.29.1",
43
+ "eslint-plugin-jest": "^28.8.3",
43
44
  "jest": "^29.7.0",
44
45
  "pre-commit": "^1.2.2",
45
46
  "rdf-isomorphic": "^1.3.1",
package/src/N3Store.js CHANGED
@@ -861,6 +861,9 @@ export default class N3Store {
861
861
  * Blank Nodes will be normalized.
862
862
  */
863
863
  addAll(quads) {
864
+ if (quads instanceof DatasetCoreAndReadableStream)
865
+ quads = quads.filtered;
866
+
864
867
  if (Array.isArray(quads))
865
868
  this.addQuads(quads);
866
869
  else if (quads instanceof N3Store && quads._entityIndex === this._entityIndex) {
@@ -883,6 +886,9 @@ export default class N3Store {
883
886
  * Blank Nodes will be normalized.
884
887
  */
885
888
  contains(other) {
889
+ if (other instanceof DatasetCoreAndReadableStream)
890
+ other = other.filtered;
891
+
886
892
  if (other === this)
887
893
  return true;
888
894
 
@@ -927,6 +933,9 @@ export default class N3Store {
927
933
  * Returns a new dataset that contains all quads from the current dataset that are not included in the given dataset.
928
934
  */
929
935
  difference(other) {
936
+ if (other && other instanceof DatasetCoreAndReadableStream)
937
+ other = other.filtered;
938
+
930
939
  if (other === this)
931
940
  return new N3Store({ entityIndex: this._entityIndex });
932
941
 
@@ -949,6 +958,9 @@ export default class N3Store {
949
958
  * Blank Nodes will be normalized.
950
959
  */
951
960
  equals(other) {
961
+ if (other instanceof DatasetCoreAndReadableStream)
962
+ other = other.filtered;
963
+
952
964
  return other === this || (this.size === other.size && this.contains(other));
953
965
  }
954
966
 
@@ -969,6 +981,9 @@ export default class N3Store {
969
981
  * Returns a new dataset containing all quads from the current dataset that are also included in the given dataset.
970
982
  */
971
983
  intersection(other) {
984
+ if (other instanceof DatasetCoreAndReadableStream)
985
+ other = other.filtered;
986
+
972
987
  if (other === this) {
973
988
  const store = new N3Store({ entityIndex: this._entityIndex });
974
989
  store._graphs = merge(Object.create(null), this._graphs);
@@ -1108,7 +1123,6 @@ class DatasetCoreAndReadableStream extends Readable {
1108
1123
  if (!this._filtered) {
1109
1124
  const { n3Store, graph, object, predicate, subject } = this;
1110
1125
  const newStore = this._filtered = new N3Store({ factory: n3Store._factory, entityIndex: this.options.entityIndex });
1111
- const graphs = n3Store._getGraphs(graph);
1112
1126
 
1113
1127
  let subjectId, predicateId, objectId;
1114
1128
 
@@ -1118,15 +1132,29 @@ class DatasetCoreAndReadableStream extends Readable {
1118
1132
  object && !(objectId = newStore._termToNumericId(object)))
1119
1133
  return newStore;
1120
1134
 
1121
- for (const graph in graphs) {
1122
- const subjects = indexMatch(graphs[graph].subjects, [subjectId, predicateId, objectId]);
1123
- if (subjects) {
1124
- newStore._graphs[graph] = {
1125
- subjects,
1126
- predicates: indexMatch(graphs[graph].predicates, [predicateId, objectId, subjectId]),
1127
- objects: indexMatch(graphs[graph].objects, [objectId, subjectId, predicateId]),
1128
- };
1135
+ const graphs = n3Store._getGraphs(graph);
1136
+ for (const graphKey in graphs) {
1137
+ let subjects, predicates, objects;
1138
+
1139
+ if (!subjectId && predicateId) {
1140
+ if (predicates = indexMatch(graphs[graphKey].predicates, [predicateId, objectId, subjectId])) {
1141
+ subjects = indexMatch(graphs[graphKey].subjects, [subjectId, predicateId, objectId]);
1142
+ objects = indexMatch(graphs[graphKey].objects, [objectId, subjectId, predicateId]);
1143
+ }
1144
+ }
1145
+ else if (objectId) {
1146
+ if (objects = indexMatch(graphs[graphKey].objects, [objectId, subjectId, predicateId])) {
1147
+ subjects = indexMatch(graphs[graphKey].subjects, [subjectId, predicateId, objectId]);
1148
+ predicates = indexMatch(graphs[graphKey].predicates, [predicateId, objectId, subjectId]);
1149
+ }
1150
+ }
1151
+ else if (subjects = indexMatch(graphs[graphKey].subjects, [subjectId, predicateId, objectId])) {
1152
+ predicates = indexMatch(graphs[graphKey].predicates, [predicateId, objectId, subjectId]);
1153
+ objects = indexMatch(graphs[graphKey].objects, [objectId, subjectId, predicateId]);
1129
1154
  }
1155
+
1156
+ if (subjects)
1157
+ newStore._graphs[graphKey] = { subjects, predicates, objects };
1130
1158
  }
1131
1159
  newStore._size = null;
1132
1160
  }