n3 1.20.1 → 1.20.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
@@ -759,7 +759,22 @@ class N3Store {
759
759
  * Blank Nodes will be normalized.
760
760
  */
761
761
  contains(other) {
762
- return other.every(quad => this.has(quad));
762
+ if (!(other instanceof N3Store) || this._entityIndex !== other._entityIndex) return other.every(quad => this.has(quad));
763
+ const g1 = this._graphs,
764
+ g2 = other._graphs;
765
+ let s1, s2, p1, p2, o1;
766
+ for (const graph in g2) {
767
+ if (!(s1 = g1[graph])) return false;
768
+ s1 = s1.subjects;
769
+ for (const subject in s2 = g2[graph].subjects) {
770
+ if (!(p1 = s1[subject])) return false;
771
+ for (const predicate in p2 = s2[subject]) {
772
+ if (!(o1 = p1[predicate])) return false;
773
+ for (const object in p2[predicate]) if (!(object in o1)) return false;
774
+ }
775
+ }
776
+ }
777
+ return true;
763
778
  }
764
779
 
765
780
  /**
@@ -800,7 +815,9 @@ class N3Store {
800
815
  * This method is aligned with Array.prototype.filter() in ECMAScript-262.
801
816
  */
802
817
  filter(iteratee) {
803
- const store = new N3Store();
818
+ const store = new N3Store({
819
+ entityIndex: this._entityIndex
820
+ });
804
821
  for (const quad of this) if (iteratee(quad, this)) store.add(quad);
805
822
  return store;
806
823
  }
@@ -816,7 +833,9 @@ class N3Store {
816
833
  * Returns a new dataset containing all quads returned by applying `iteratee` to each quad in the current dataset.
817
834
  */
818
835
  map(iteratee) {
819
- const store = new N3Store();
836
+ const store = new N3Store({
837
+ entityIndex: this._entityIndex
838
+ });
820
839
  for (const quad of this) store.add(iteratee(quad, this));
821
840
  return store;
822
841
  }
@@ -876,7 +895,9 @@ class N3Store {
876
895
  * Returns a new `Dataset` that is a concatenation of this dataset and the quads given as an argument.
877
896
  */
878
897
  union(quads) {
879
- const store = new N3Store();
898
+ const store = new N3Store({
899
+ entityIndex: this._entityIndex
900
+ });
880
901
  store.addAll(this);
881
902
  store.addAll(quads);
882
903
  return store;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n3",
3
- "version": "1.20.1",
3
+ "version": "1.20.3",
4
4
  "description": "Lightning fast, asynchronous, streaming Turtle / N3 / RDF library.",
5
5
  "author": "Ruben Verborgh <ruben.verborgh@gmail.com>",
6
6
  "keywords": [
package/src/N3Store.js CHANGED
@@ -807,7 +807,24 @@ export default class N3Store {
807
807
  * Blank Nodes will be normalized.
808
808
  */
809
809
  contains(other) {
810
- return other.every(quad => this.has(quad));
810
+ if (!(other instanceof N3Store) || this._entityIndex !== other._entityIndex)
811
+ return other.every(quad => this.has(quad));
812
+
813
+ const g1 = this._graphs, g2 = other._graphs;
814
+ let s1, s2, p1, p2, o1;
815
+ for (const graph in g2) {
816
+ if (!(s1 = g1[graph])) return false;
817
+ s1 = s1.subjects;
818
+ for (const subject in (s2 = g2[graph].subjects)) {
819
+ if (!(p1 = s1[subject])) return false;
820
+ for (const predicate in (p2 = s2[subject])) {
821
+ if (!(o1 = p1[predicate])) return false;
822
+ for (const object in p2[predicate])
823
+ if (!(object in o1)) return false;
824
+ }
825
+ }
826
+ }
827
+ return true;
811
828
  }
812
829
 
813
830
  /**
@@ -849,7 +866,7 @@ export default class N3Store {
849
866
  * This method is aligned with Array.prototype.filter() in ECMAScript-262.
850
867
  */
851
868
  filter(iteratee) {
852
- const store = new N3Store();
869
+ const store = new N3Store({ entityIndex: this._entityIndex });
853
870
  for (const quad of this)
854
871
  if (iteratee(quad, this))
855
872
  store.add(quad);
@@ -867,7 +884,7 @@ export default class N3Store {
867
884
  * Returns a new dataset containing all quads returned by applying `iteratee` to each quad in the current dataset.
868
885
  */
869
886
  map(iteratee) {
870
- const store = new N3Store();
887
+ const store = new N3Store({ entityIndex: this._entityIndex });
871
888
  for (const quad of this)
872
889
  store.add(iteratee(quad, this));
873
890
  return store;
@@ -929,7 +946,7 @@ export default class N3Store {
929
946
  * Returns a new `Dataset` that is a concatenation of this dataset and the quads given as an argument.
930
947
  */
931
948
  union(quads) {
932
- const store = new N3Store();
949
+ const store = new N3Store({ entityIndex: this._entityIndex });
933
950
  store.addAll(this);
934
951
  store.addAll(quads);
935
952
  return store;