Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completely re-write schema comparison summary #856

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
22 changes: 13 additions & 9 deletions hed/schema/hed_schema_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,8 @@ def section_key(self):
def __eq__(self, other):
if self.name != other.name:
return False
if self.attributes != other.attributes:
# We only want to compare known attributes
self_attr = self.get_known_attributes()
other_attr = other.get_known_attributes()
# We can no longer be sure on the order of attribute values, since owl formatting has no order
if self_attr != other_attr and not self._compare_attributes_no_order(self_attr, other_attr):
return False
if not self._compare_attributes_no_order(self.attributes, other.attributes):
return False
if self.description != other.description:
return False
return True
Expand All @@ -138,8 +133,9 @@ def get_known_attributes(self):

@staticmethod
def _compare_attributes_no_order(left, right):
left = {name: (set(value.split(",")) if isinstance(value, str) else value) for (name, value) in left.items()}
right = {name: (set(value.split(",")) if isinstance(value, str) else value) for (name, value) in right.items()}
if left != right:
left = {name: (set(value.split(",")) if isinstance(value, str) else value) for (name, value) in left.items()}
right = {name: (set(value.split(",")) if isinstance(value, str) else value) for (name, value) in right.items()}

return left == right

Expand Down Expand Up @@ -235,6 +231,7 @@ def get_conversion_factor(self, unit_name):
if HedKey.ConversionFactor in self.attributes:
return float(self.derivative_units.get(unit_name))


class HedTagEntry(HedSchemaEntry):
""" A single tag entry in the HedSchema. """
def __init__(self, *args, **kwargs):
Expand All @@ -252,6 +249,13 @@ def __init__(self, *args, **kwargs):
# Descendent tags below this one
self.children = {}

def __eq__(self, other):
if not super().__eq__(other):
return False
if not self._compare_attributes_no_order(self.inherited_attributes, other.inherited_attributes):
return False
return True

def has_attribute(self, attribute, return_value=False):
""" Returns th existence or value of an attribute in this entry.

Expand Down
Loading