From 67d3df6a1fc798ea2421eb5512a7bf71be262df8 Mon Sep 17 00:00:00 2001 From: Peyman-N Date: Wed, 3 Jul 2024 15:22:09 +0200 Subject: [PATCH 1/2] eq --- pipeline/src/base.py | 13 +++++++++++++ pipeline/src/collection.py | 13 +++++++++++++ pipeline/tests/test_collections.py | 1 + 3 files changed, 27 insertions(+) diff --git a/pipeline/src/base.py b/pipeline/src/base.py index 7f4ee74b..c45bf5c1 100644 --- a/pipeline/src/base.py +++ b/pipeline/src/base.py @@ -34,6 +34,19 @@ def has_property(self, name): if property.name == name: return True return False + + def __eq__(self, other: Node) -> bool: + + eq = True + for property in self.properties: + property_other = getattr(other, property.name, None) + property_self = getattr(self, property.name, None) + if property_other == property_self: + pass + else: + eq = False + + return eq def to_jsonld(self, include_empty_properties=True, embed_linked_nodes=True, with_context=True): """ diff --git a/pipeline/src/collection.py b/pipeline/src/collection.py index b1226025..e6a7893c 100644 --- a/pipeline/src/collection.py +++ b/pipeline/src/collection.py @@ -34,6 +34,19 @@ def __len__(self): def __iter__(self): return iter(self.nodes.values()) + + def __eq__(self, other): + + eq = True + # The current implementation assumes that nodes in both graphs are connected with the same link number. + for key in self.nodes.keys(): + if key in other.nodes.keys(): + if self.nodes[key] != other.nodes[key]: + eq = False + else: + eq = False + + return eq def add(self, *nodes): """ diff --git a/pipeline/tests/test_collections.py b/pipeline/tests/test_collections.py index a6f8ecfd..f86127f8 100644 --- a/pipeline/tests/test_collections.py +++ b/pipeline/tests/test_collections.py @@ -65,6 +65,7 @@ def test_round_trip_multi_file(): new_collection.load(test_output_dir) assert len(collection) == len(new_collection) + assert collection==new_collection for node in new_collection: if node.id == person.id: From 9a755d7ea1d1c63306a0837b9c9a3fb1fce33dae Mon Sep 17 00:00:00 2001 From: Peyman-N Date: Thu, 4 Jul 2024 12:45:57 +0200 Subject: [PATCH 2/2] correction --- pipeline/src/base.py | 9 +++------ pipeline/src/collection.py | 13 ++++++------- pipeline/tests/test_collections.py | 1 - 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/pipeline/src/base.py b/pipeline/src/base.py index c45bf5c1..843c53d2 100644 --- a/pipeline/src/base.py +++ b/pipeline/src/base.py @@ -37,16 +37,13 @@ def has_property(self, name): def __eq__(self, other: Node) -> bool: - eq = True for property in self.properties: property_other = getattr(other, property.name, None) property_self = getattr(self, property.name, None) - if property_other == property_self: - pass - else: - eq = False + if property_other != property_self: + return False - return eq + return True def to_jsonld(self, include_empty_properties=True, embed_linked_nodes=True, with_context=True): """ diff --git a/pipeline/src/collection.py b/pipeline/src/collection.py index e6a7893c..65e421ab 100644 --- a/pipeline/src/collection.py +++ b/pipeline/src/collection.py @@ -37,16 +37,15 @@ def __iter__(self): def __eq__(self, other): - eq = True # The current implementation assumes that nodes in both graphs are connected with the same link number. - for key in self.nodes.keys(): - if key in other.nodes.keys(): - if self.nodes[key] != other.nodes[key]: - eq = False + for node_id in self.nodes: + if node_id in other.nodes.keys(): + if self.nodes[node_id] != other.nodes[node_id]: + return False else: - eq = False + return False - return eq + return True def add(self, *nodes): """ diff --git a/pipeline/tests/test_collections.py b/pipeline/tests/test_collections.py index f86127f8..a6f8ecfd 100644 --- a/pipeline/tests/test_collections.py +++ b/pipeline/tests/test_collections.py @@ -65,7 +65,6 @@ def test_round_trip_multi_file(): new_collection.load(test_output_dir) assert len(collection) == len(new_collection) - assert collection==new_collection for node in new_collection: if node.id == person.id: