From 1c9d69e8ce0f39dfe2d5b532f03d80ec94809bb8 Mon Sep 17 00:00:00 2001 From: IanCa Date: Tue, 28 May 2024 12:52:09 -0500 Subject: [PATCH] Ontology fixes Leave equivalent to blank if it's the same as subclass of fix missing ) --- hed/schema/schema_io/ontology_util.py | 2 +- hed/schema/schema_io/schema2df.py | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/hed/schema/schema_io/ontology_util.py b/hed/schema/schema_io/ontology_util.py index 131e98ffd..1db3e8b8d 100644 --- a/hed/schema/schema_io/ontology_util.py +++ b/hed/schema/schema_io/ontology_util.py @@ -343,7 +343,7 @@ def _convert_df_to_omn(df, annotation_properties=("",)): equivalent_to = row[constants.equivalent_to] equivalent_to = equivalent_to.replace(" and ", "\n\t\tand ") subclass_of = row[constants.subclass_of] - if equivalent_to and equivalent_to != subclass_of: + if equivalent_to: output_text += "\tEquivalentTo:\n" output_text += f"\t\t{equivalent_to}" else: diff --git a/hed/schema/schema_io/schema2df.py b/hed/schema/schema_io/schema2df.py index 46dc6f563..7ff093547 100644 --- a/hed/schema/schema_io/schema2df.py +++ b/hed/schema/schema_io/schema2df.py @@ -246,7 +246,7 @@ def _get_tag_equivalent_to(self, tag_entry): if self._get_as_ids and found_range and found_range != HedKey.NumericRange: section = self._schema[found_range] if any(section.get(v) is None for v in values): - raise ValueError(f"Cannot find schema entry for {v}") + raise ValueError(f"Cannot find schema entry for {values}") for v in values: test_id = section.get(v).attributes.get(HedKey.HedID) if not test_id: @@ -278,9 +278,13 @@ def _get_tag_equivalent_to(self, tag_entry): if self._get_as_ids: attribute_strings.append(f"(hed:HED_0000102 some {schema_id})") else: - attribute_strings.append(f"(inHedSchema some {schema_name}") + attribute_strings.append(f"(inHedSchema some {schema_name})") - return " and ".join([subclass] + attribute_strings) + # If they match, we want to leave equivalent_to blank + final_out = " and ".join([subclass] + attribute_strings) + if final_out == subclass: + return "" + return final_out def _get_subclass_of(self, tag_entry): # Special case for HedTag