From ae399b82c5ab5037f01ef02a9430141ec0f80429 Mon Sep 17 00:00:00 2001 From: uhbrar Date: Thu, 22 Aug 2024 21:41:12 -0400 Subject: [PATCH 1/4] add get_field --- reasoner_pydantic/base_model.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/reasoner_pydantic/base_model.py b/reasoner_pydantic/base_model.py index dad0e81..6a1a6eb 100644 --- a/reasoner_pydantic/base_model.py +++ b/reasoner_pydantic/base_model.py @@ -26,6 +26,9 @@ def update(self, other): raise NotImplementedError( f"Model {self.__class__.__name__} has no update method" ) + + def get_field(self, field): + getattr(self, field, None) # After running validation on all known properties, make sure everything else is hashable @root_validator(allow_reuse=True, pre=False) From 9089c0453f4ae4ff52b2e3b79ac976b0dfe634a4 Mon Sep 17 00:00:00 2001 From: uhbrar Date: Thu, 22 Aug 2024 21:41:41 -0400 Subject: [PATCH 2/4] add kl/at merging --- reasoner_pydantic/kgraph.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/reasoner_pydantic/kgraph.py b/reasoner_pydantic/kgraph.py index 0f9a8f0..fca6a5f 100644 --- a/reasoner_pydantic/kgraph.py +++ b/reasoner_pydantic/kgraph.py @@ -103,7 +103,12 @@ class Config: def update(self, other): if other.attributes: if self.attributes: - self.attributes.update(other.attributes) + # We need to make sure we don't add a second KL/AT + new_attributes = HashableSet[Attribute] + for attribute in other.attributes: + if attribute.attribute_type_id not in ("biolink:knowledge_level", "biolink:agent_type"): + new_attributes.add(attribute) + self.attributes.update(new_attributes) else: self.attributes = other.attributes if other.sources: From 99045ecfbd353df5371181e1841425e925bb73c7 Mon Sep 17 00:00:00 2001 From: uhbrar Date: Thu, 22 Aug 2024 21:42:19 -0400 Subject: [PATCH 3/4] bump version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 9fb04a1..fa7eb62 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ setup( name="reasoner-pydantic", - version="5.0.4", + version="5.0.5", author="Abrar Mesbah", author_email="amesbah@covar.com", url="https://github.com/TranslatorSRI/reasoner-pydantic", From 594dc3c1c0bc8bd56308baece56dcbf2e7a5fcfb Mon Sep 17 00:00:00 2001 From: uhbrar Date: Thu, 22 Aug 2024 21:45:32 -0400 Subject: [PATCH 4/4] black --- reasoner_pydantic/base_model.py | 2 +- reasoner_pydantic/kgraph.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/reasoner_pydantic/base_model.py b/reasoner_pydantic/base_model.py index 6a1a6eb..ed8ea6d 100644 --- a/reasoner_pydantic/base_model.py +++ b/reasoner_pydantic/base_model.py @@ -26,7 +26,7 @@ def update(self, other): raise NotImplementedError( f"Model {self.__class__.__name__} has no update method" ) - + def get_field(self, field): getattr(self, field, None) diff --git a/reasoner_pydantic/kgraph.py b/reasoner_pydantic/kgraph.py index fca6a5f..286cf4b 100644 --- a/reasoner_pydantic/kgraph.py +++ b/reasoner_pydantic/kgraph.py @@ -106,7 +106,10 @@ def update(self, other): # We need to make sure we don't add a second KL/AT new_attributes = HashableSet[Attribute] for attribute in other.attributes: - if attribute.attribute_type_id not in ("biolink:knowledge_level", "biolink:agent_type"): + if attribute.attribute_type_id not in ( + "biolink:knowledge_level", + "biolink:agent_type", + ): new_attributes.add(attribute) self.attributes.update(new_attributes) else: