Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions pipeline/src/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also need to check equality self._type_ and self.id (if it is defined, i.e., for LinkedMetadata, but not for EmbeddedMetadata, and if it is not None)

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):
"""
Expand Down
13 changes: 13 additions & 0 deletions pipeline/src/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ def __len__(self):

def __iter__(self):
return iter(self.nodes.values())

def __eq__(self, other):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a preliminary check that the len() of both collections are the same? If they're different, we can return False quickly without needing to check all the nodes.


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):
"""
Expand Down
1 change: 1 addition & 0 deletions pipeline/tests/test_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down