From 7e2499c770db6ab6579e96374e5241afcf461560 Mon Sep 17 00:00:00 2001 From: francescalb Date: Wed, 29 Sep 2021 11:35:05 +0200 Subject: [PATCH 01/16] Added __hash__ and __eq__ to ontology.Ontology --- ontopy/ontology.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/ontopy/ontology.py b/ontopy/ontology.py index 59403090e..96703a739 100644 --- a/ontopy/ontology.py +++ b/ontopy/ontology.py @@ -190,6 +190,26 @@ def __objclass__(self): # Play nice with inspect... pass + def __eq__(self, other): + return self.__hash__() == other.__hash__() + + def __str__(self): + """TODO""" + + def __iter__(self): + """TODO""" + + def __delitem__(self): + """TODO""" + + def __setitem__(self, key, value): + """ MAYBE TODO """ + # self[key] = value + # emmo['HAtom'] = emmo.Atom + + def __hash__(self): + return hash((self.base_iri, self.get_entities())) + def get_by_label(self, label, label_annotations=None, namespace=None): """Returns entity with label annotation `label`. From 7e6ab17633dc2182d58656a4251065883d67b90a Mon Sep 17 00:00:00 2001 From: francescalb Date: Wed, 29 Sep 2021 22:56:09 +0200 Subject: [PATCH 02/16] Sorting emmo classes with iris does not work. checkout --- ontopy/ontology.py | 15 +++++++++++++-- ontopy/patch.py | 17 +++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/ontopy/ontology.py b/ontopy/ontology.py index 96703a739..4b4fd1b36 100644 --- a/ontopy/ontology.py +++ b/ontopy/ontology.py @@ -112,6 +112,9 @@ def get_ontology(self, base_iri='emmo-inferred'): return onto + def __hash__(self): + return hash(self.filename) + class Ontology(owlready2.Ontology, OntoGraph): """A generic class extending owlready2.Ontology. @@ -191,7 +194,7 @@ def __objclass__(self): pass def __eq__(self, other): - return self.__hash__() == other.__hash__() + return hash(self) == hash(other) def __str__(self): """TODO""" @@ -208,7 +211,15 @@ def __setitem__(self, key, value): # emmo['HAtom'] = emmo.Atom def __hash__(self): - return hash((self.base_iri, self.get_entities())) + sorted_entities = sorted( + self.get_entities(imported=True, + classes=True, + individuals=False, + object_properties=False, + data_properties=False, + annotation_properties=False, + ), key=lambda e: e.name) + return hash((self.base_iri, tuple(sorted_entities))) def get_by_label(self, label, label_annotations=None, namespace=None): """Returns entity with label annotation `label`. diff --git a/ontopy/patch.py b/ontopy/patch.py index eeb1cae93..1e300cd30 100644 --- a/ontopy/patch.py +++ b/ontopy/patch.py @@ -3,7 +3,7 @@ import types import owlready2 -from owlready2 import ThingClass, PropertyClass, Thing, Restriction, Namespace +from owlready2 import ThingClass, PropertyClass, Thing, Restriction, Namespace, EntityClass from owlready2 import Metadata @@ -67,6 +67,16 @@ def _dir(self): s.update(props) return sorted(s) +def _hash(self): + """Define hash of ThingClass and PropertyClass.""" + try: + return hash(self.iri) + except AttributeError: + return hash(self.name) + +def _eq(self, other): + """Define equality based on hash for ThingClass and PropertyClass.""" + return hash(self) == hash(other) def get_class_annotations(self, all=False, imported=True): """Returns a dict with non-empty annotations. @@ -121,6 +131,8 @@ def get_indirect_is_a(self, skip_classes=True): # Inject methods into ThingClass setattr(ThingClass, '__dir__', _dir) +setattr(ThingClass, '__hash__', _hash) +setattr(ThingClass, '__eq__', _eq) setattr(ThingClass, 'get_preferred_label', get_preferred_label) setattr(ThingClass, 'get_parents', get_parents) setattr(ThingClass, 'get_annotations', get_class_annotations) @@ -147,7 +159,8 @@ def get_property_annotations(self, all=False, imported=True): else: return {k: v for k, v in d.items() if v} - +setattr(PropertyClass, '__hash__', _hash) +#setattr(PropertyClass, '__eq__', _eq) setattr(PropertyClass, 'get_preferred_label', get_preferred_label) setattr(PropertyClass, 'get_parents', get_parents) setattr(PropertyClass, 'get_annotations', get_property_annotations) From 180a05aca73b167f110e0ed193e472e92a2a1eef Mon Sep 17 00:00:00 2001 From: francescalb Date: Thu, 30 Sep 2021 08:21:46 +0200 Subject: [PATCH 03/16] Added test for ontology equality --- tests/test_load_emmo.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/test_load_emmo.py b/tests/test_load_emmo.py index 226c1bd56..4e9b74f00 100644 --- a/tests/test_load_emmo.py +++ b/tests/test_load_emmo.py @@ -12,5 +12,10 @@ def test_load_emmo() -> None: assert EMMO_inferred assert EMMO - assert EMMO_inferred.base_iri == get_emmo(None).base_iri + assert EMMO_inferred == get_emmo(None) + assert EMMO != EMMO_inferred + + EMMO_inferred.new_entity('HydrogenAtom', EMMO_inferred.Atom) + EMMO_inferred.sync_attributes() + #assert EMMO_inferred != get_emmo(None) From 475683d32488713975ee27e8a08aea11d0b73cb7 Mon Sep 17 00:00:00 2001 From: francescalb Date: Thu, 30 Sep 2021 18:03:19 +0200 Subject: [PATCH 04/16] Creating hash and testing ontology equality It now works, but only when the test includes checking for classes and base_iri of the ontology. The test does not include properties. --- ontopy/ontology.py | 7 ++++++- tests/test_load_emmo.py | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ontopy/ontology.py b/ontopy/ontology.py index 4b4fd1b36..28b33335e 100644 --- a/ontopy/ontology.py +++ b/ontopy/ontology.py @@ -211,6 +211,11 @@ def __setitem__(self, key, value): # emmo['HAtom'] = emmo.Atom def __hash__(self): + """Returns hash. + + Note that entities must have iris for this to work, since entities are + sorted by their iris before creating the hash. + """ sorted_entities = sorted( self.get_entities(imported=True, classes=True, @@ -218,7 +223,7 @@ def __hash__(self): object_properties=False, data_properties=False, annotation_properties=False, - ), key=lambda e: e.name) + ), key=lambda e: e.iri) return hash((self.base_iri, tuple(sorted_entities))) def get_by_label(self, label, label_annotations=None, namespace=None): diff --git a/tests/test_load_emmo.py b/tests/test_load_emmo.py index 4e9b74f00..3a1384577 100644 --- a/tests/test_load_emmo.py +++ b/tests/test_load_emmo.py @@ -17,5 +17,5 @@ def test_load_emmo() -> None: EMMO_inferred.new_entity('HydrogenAtom', EMMO_inferred.Atom) EMMO_inferred.sync_attributes() - #assert EMMO_inferred != get_emmo(None) + assert EMMO_inferred != get_emmo(None) From 3b6585e3dc8dec13d7b8bb6e48d973fbceadbafa Mon Sep 17 00:00:00 2001 From: francescalb Date: Thu, 30 Sep 2021 18:29:35 +0200 Subject: [PATCH 05/16] Extended possibilities for ThingClass hash Preffered is hash on iri, second, try prefLabel, third try name fourth try label --- ontopy/ontology.py | 2 +- ontopy/patch.py | 16 +++++++++++++--- tests/test_load_emmo.py | 1 - 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/ontopy/ontology.py b/ontopy/ontology.py index 28b33335e..fea7f5660 100644 --- a/ontopy/ontology.py +++ b/ontopy/ontology.py @@ -223,7 +223,7 @@ def __hash__(self): object_properties=False, data_properties=False, annotation_properties=False, - ), key=lambda e: e.iri) + ), key=lambda e: e.iri) return hash((self.base_iri, tuple(sorted_entities))) def get_by_label(self, label, label_annotations=None, namespace=None): diff --git a/ontopy/patch.py b/ontopy/patch.py index 1e300cd30..1d448c4a7 100644 --- a/ontopy/patch.py +++ b/ontopy/patch.py @@ -3,7 +3,7 @@ import types import owlready2 -from owlready2 import ThingClass, PropertyClass, Thing, Restriction, Namespace, EntityClass +from owlready2 import ThingClass, PropertyClass, Thing, Restriction, Namespace from owlready2 import Metadata @@ -67,17 +67,26 @@ def _dir(self): s.update(props) return sorted(s) + def _hash(self): """Define hash of ThingClass and PropertyClass.""" try: return hash(self.iri) except AttributeError: - return hash(self.name) + try: + return hash(self.prefLabel) + except AttributeError: + try: + return hash(self.name) + except AttributeError: + return hash(self.label) + def _eq(self, other): """Define equality based on hash for ThingClass and PropertyClass.""" return hash(self) == hash(other) + def get_class_annotations(self, all=False, imported=True): """Returns a dict with non-empty annotations. @@ -159,8 +168,9 @@ def get_property_annotations(self, all=False, imported=True): else: return {k: v for k, v in d.items() if v} + setattr(PropertyClass, '__hash__', _hash) -#setattr(PropertyClass, '__eq__', _eq) +# setattr(PropertyClass, '__eq__', _eq) setattr(PropertyClass, 'get_preferred_label', get_preferred_label) setattr(PropertyClass, 'get_parents', get_parents) setattr(PropertyClass, 'get_annotations', get_property_annotations) diff --git a/tests/test_load_emmo.py b/tests/test_load_emmo.py index 3a1384577..77c7e5324 100644 --- a/tests/test_load_emmo.py +++ b/tests/test_load_emmo.py @@ -18,4 +18,3 @@ def test_load_emmo() -> None: EMMO_inferred.new_entity('HydrogenAtom', EMMO_inferred.Atom) EMMO_inferred.sync_attributes() assert EMMO_inferred != get_emmo(None) - From d2ad9160d8751880cd3c3e54c4b5a457e71c333d Mon Sep 17 00:00:00 2001 From: francescalb Date: Mon, 25 Oct 2021 13:03:46 +0200 Subject: [PATCH 06/16] Only hash on iri for ThingClass in hash, and ontology hash including everything except annotation_properties and Individuals --- ontopy/ontology.py | 4 ++-- ontopy/patch.py | 12 +----------- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/ontopy/ontology.py b/ontopy/ontology.py index fea7f5660..944a3fd28 100644 --- a/ontopy/ontology.py +++ b/ontopy/ontology.py @@ -220,8 +220,8 @@ def __hash__(self): self.get_entities(imported=True, classes=True, individuals=False, - object_properties=False, - data_properties=False, + object_properties=True, + data_properties=True, annotation_properties=False, ), key=lambda e: e.iri) return hash((self.base_iri, tuple(sorted_entities))) diff --git a/ontopy/patch.py b/ontopy/patch.py index 1d448c4a7..72890d432 100644 --- a/ontopy/patch.py +++ b/ontopy/patch.py @@ -70,17 +70,7 @@ def _dir(self): def _hash(self): """Define hash of ThingClass and PropertyClass.""" - try: - return hash(self.iri) - except AttributeError: - try: - return hash(self.prefLabel) - except AttributeError: - try: - return hash(self.name) - except AttributeError: - return hash(self.label) - + return hash(self.iri) def _eq(self, other): """Define equality based on hash for ThingClass and PropertyClass.""" From 63513fe917abf421048576c7120621e5fe29ae5d Mon Sep 17 00:00:00 2001 From: francescalb Date: Wed, 29 Sep 2021 22:56:09 +0200 Subject: [PATCH 07/16] Sorting emmo classes with iris does not work. --- ontopy/patch.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ontopy/patch.py b/ontopy/patch.py index 72890d432..007d4e551 100644 --- a/ontopy/patch.py +++ b/ontopy/patch.py @@ -3,7 +3,7 @@ import types import owlready2 -from owlready2 import ThingClass, PropertyClass, Thing, Restriction, Namespace +from owlready2 import ThingClass, PropertyClass, Thing, Restriction, Namespace, EntityClass from owlready2 import Metadata @@ -67,6 +67,16 @@ def _dir(self): s.update(props) return sorted(s) +def _hash(self): + """Define hash of ThingClass and PropertyClass.""" + try: + return hash(self.iri) + except AttributeError: + return hash(self.name) + +def _eq(self, other): + """Define equality based on hash for ThingClass and PropertyClass.""" + return hash(self) == hash(other) def _hash(self): """Define hash of ThingClass and PropertyClass.""" @@ -158,7 +168,6 @@ def get_property_annotations(self, all=False, imported=True): else: return {k: v for k, v in d.items() if v} - setattr(PropertyClass, '__hash__', _hash) # setattr(PropertyClass, '__eq__', _eq) setattr(PropertyClass, 'get_preferred_label', get_preferred_label) From 3fa0e529fcccc1f707c8473a68f12f6cac56f0a7 Mon Sep 17 00:00:00 2001 From: francescalb Date: Thu, 30 Sep 2021 18:29:35 +0200 Subject: [PATCH 08/16] Only use iri for calculating the hash --- ontopy/patch.py | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/ontopy/patch.py b/ontopy/patch.py index 007d4e551..836c89fa4 100644 --- a/ontopy/patch.py +++ b/ontopy/patch.py @@ -3,7 +3,7 @@ import types import owlready2 -from owlready2 import ThingClass, PropertyClass, Thing, Restriction, Namespace, EntityClass +from owlready2 import ThingClass, PropertyClass, Thing, Restriction, Namespace from owlready2 import Metadata @@ -67,21 +67,12 @@ def _dir(self): s.update(props) return sorted(s) -def _hash(self): - """Define hash of ThingClass and PropertyClass.""" - try: - return hash(self.iri) - except AttributeError: - return hash(self.name) - -def _eq(self, other): - """Define equality based on hash for ThingClass and PropertyClass.""" - return hash(self) == hash(other) def _hash(self): """Define hash of ThingClass and PropertyClass.""" return hash(self.iri) + def _eq(self, other): """Define equality based on hash for ThingClass and PropertyClass.""" return hash(self) == hash(other) @@ -168,6 +159,7 @@ def get_property_annotations(self, all=False, imported=True): else: return {k: v for k, v in d.items() if v} + setattr(PropertyClass, '__hash__', _hash) # setattr(PropertyClass, '__eq__', _eq) setattr(PropertyClass, 'get_preferred_label', get_preferred_label) From 4b08fa6ea8fd0315ebfe7f4828c1e446b2651e9f Mon Sep 17 00:00:00 2001 From: francescalb Date: Mon, 25 Oct 2021 22:56:34 +0200 Subject: [PATCH 09/16] Added __eq__ in Ontology based on triples Note that consistency of blank nodes is not checked. --- ontopy/ontology.py | 64 ++++++++++++++++++++++++---------------------- ontopy/patch.py | 14 ---------- 2 files changed, 34 insertions(+), 44 deletions(-) diff --git a/ontopy/ontology.py b/ontopy/ontology.py index 944a3fd28..6dabebabe 100644 --- a/ontopy/ontology.py +++ b/ontopy/ontology.py @@ -112,9 +112,6 @@ def get_ontology(self, base_iri='emmo-inferred'): return onto - def __hash__(self): - return hash(self.filename) - class Ontology(owlready2.Ontology, OntoGraph): """A generic class extending owlready2.Ontology. @@ -193,38 +190,45 @@ def __objclass__(self): # Play nice with inspect... pass - def __eq__(self, other): - return hash(self) == hash(other) - - def __str__(self): - """TODO""" - - def __iter__(self): - """TODO""" + def __hash__(self): + """ Returns hash based on base_iri + This is done to keep Ontology hashable when defining __eq__. + """ + return hash(self.base_iri) - def __delitem__(self): - """TODO""" + def __eq__(self, other): + """Checks if this ontology is equal to other. - def __setitem__(self, key, value): - """ MAYBE TODO """ - # self[key] = value - # emmo['HAtom'] = emmo.Atom + Equality of all triples obtained from self.get_triples(), + i.e. all triples except blank nodes. + """ + return set(self.get_triples()) == set(other.get_triples()) - def __hash__(self): - """Returns hash. + def _sorted_entities(self): + """Return sorted entities + """ + return sorted(e.iri for e in self.get_entities( + imported=True, classes=True, + individuals=True, object_properties=True, + data_properties=True, annotation_properties=True)) - Note that entities must have iris for this to work, since entities are - sorted by their iris before creating the hash. + def get_triples(self): + """ Returns all triples unabbreviated """ - sorted_entities = sorted( - self.get_entities(imported=True, - classes=True, - individuals=False, - object_properties=True, - data_properties=True, - annotation_properties=False, - ), key=lambda e: e.iri) - return hash((self.base_iri, tuple(sorted_entities))) + def _unabbreviate(i): + if isinstance(i, int): + if i >= 0: + return self._unabbreviate(i) + else: + return "_:" # blank nodes are given random neg. storid + else: + return i + + for s, p, o in self.world.get_triples(): + s = _unabbreviate(s) + p = _unabbreviate(p) + o = _unabbreviate(o) + yield s, p, o def get_by_label(self, label, label_annotations=None, namespace=None): """Returns entity with label annotation `label`. diff --git a/ontopy/patch.py b/ontopy/patch.py index 836c89fa4..eeb1cae93 100644 --- a/ontopy/patch.py +++ b/ontopy/patch.py @@ -68,16 +68,6 @@ def _dir(self): return sorted(s) -def _hash(self): - """Define hash of ThingClass and PropertyClass.""" - return hash(self.iri) - - -def _eq(self, other): - """Define equality based on hash for ThingClass and PropertyClass.""" - return hash(self) == hash(other) - - def get_class_annotations(self, all=False, imported=True): """Returns a dict with non-empty annotations. @@ -131,8 +121,6 @@ def get_indirect_is_a(self, skip_classes=True): # Inject methods into ThingClass setattr(ThingClass, '__dir__', _dir) -setattr(ThingClass, '__hash__', _hash) -setattr(ThingClass, '__eq__', _eq) setattr(ThingClass, 'get_preferred_label', get_preferred_label) setattr(ThingClass, 'get_parents', get_parents) setattr(ThingClass, 'get_annotations', get_class_annotations) @@ -160,8 +148,6 @@ def get_property_annotations(self, all=False, imported=True): return {k: v for k, v in d.items() if v} -setattr(PropertyClass, '__hash__', _hash) -# setattr(PropertyClass, '__eq__', _eq) setattr(PropertyClass, 'get_preferred_label', get_preferred_label) setattr(PropertyClass, 'get_parents', get_parents) setattr(PropertyClass, 'get_annotations', get_property_annotations) From 61011d5fa2e05f1429d8ad2cf613e07359550ecc Mon Sep 17 00:00:00 2001 From: francescalb Date: Mon, 25 Oct 2021 23:02:53 +0200 Subject: [PATCH 10/16] Added testing of new relation --- tests/test_load_emmo.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/test_load_emmo.py b/tests/test_load_emmo.py index 77c7e5324..6398f3aa3 100644 --- a/tests/test_load_emmo.py +++ b/tests/test_load_emmo.py @@ -7,14 +7,19 @@ def test_load_emmo() -> None: from emmopy import get_emmo EMMO_inferred = get_emmo() + EMMO_inf = get_emmo(None) EMMO = get_emmo(inferred=False) assert EMMO_inferred assert EMMO - assert EMMO_inferred == get_emmo(None) + assert EMMO_inferred == EMMO_inf assert EMMO != EMMO_inferred EMMO_inferred.new_entity('HydrogenAtom', EMMO_inferred.Atom) EMMO_inferred.sync_attributes() - assert EMMO_inferred != get_emmo(None) + assert EMMO_inferred != EMMO_inf + + EMMO_inferred2 = get_emmo() + EMMO_inferred2.Atom.comment.append('New triple') + assert EMMO_inferred2 != EMMO_inf From b7371d089d5003ef54c1ef4f5395b710a71e6e38 Mon Sep 17 00:00:00 2001 From: "Francesca L. Bleken" <48128015+francescalb@users.noreply.github.com> Date: Mon, 1 Nov 2021 13:32:51 +0100 Subject: [PATCH 11/16] Name of inferred ontology not shortened any longer Co-authored-by: Casper Welzel Andersen <43357585+CasperWA@users.noreply.github.com> --- tests/test_load_emmo.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/test_load_emmo.py b/tests/test_load_emmo.py index 6398f3aa3..85d2b2f68 100644 --- a/tests/test_load_emmo.py +++ b/tests/test_load_emmo.py @@ -7,19 +7,20 @@ def test_load_emmo() -> None: from emmopy import get_emmo EMMO_inferred = get_emmo() - EMMO_inf = get_emmo(None) + EMMO_inferred_again = get_emmo(None) EMMO = get_emmo(inferred=False) assert EMMO_inferred + assert EMMO_inferred_again assert EMMO - assert EMMO_inferred == EMMO_inf + assert EMMO_inferred == EMMO_inferred_again assert EMMO != EMMO_inferred EMMO_inferred.new_entity('HydrogenAtom', EMMO_inferred.Atom) EMMO_inferred.sync_attributes() - assert EMMO_inferred != EMMO_inf + assert EMMO_inferred != EMMO_inferred_again EMMO_inferred2 = get_emmo() EMMO_inferred2.Atom.comment.append('New triple') - assert EMMO_inferred2 != EMMO_inf + assert EMMO_inferred2 != EMMO_inferred_again From 14ff1c22c8d551477ba813fd5a2254c3e6fb3609 Mon Sep 17 00:00:00 2001 From: francescalb Date: Mon, 1 Nov 2021 13:54:16 +0100 Subject: [PATCH 12/16] Removed helper function to sort entities as it is no longer needed --- ontopy/ontology.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/ontopy/ontology.py b/ontopy/ontology.py index 6dabebabe..2cc2385f3 100644 --- a/ontopy/ontology.py +++ b/ontopy/ontology.py @@ -204,14 +204,6 @@ def __eq__(self, other): """ return set(self.get_triples()) == set(other.get_triples()) - def _sorted_entities(self): - """Return sorted entities - """ - return sorted(e.iri for e in self.get_entities( - imported=True, classes=True, - individuals=True, object_properties=True, - data_properties=True, annotation_properties=True)) - def get_triples(self): """ Returns all triples unabbreviated """ From b8e700d4d7e14fb83c350fb485b79b8f04311bb0 Mon Sep 17 00:00:00 2001 From: "Francesca L. Bleken" <48128015+francescalb@users.noreply.github.com> Date: Mon, 1 Nov 2021 13:55:57 +0100 Subject: [PATCH 13/16] Improved on return of dummy variables Co-authored-by: Casper Welzel Andersen <43357585+CasperWA@users.noreply.github.com> --- ontopy/ontology.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ontopy/ontology.py b/ontopy/ontology.py index 2cc2385f3..f57012482 100644 --- a/ontopy/ontology.py +++ b/ontopy/ontology.py @@ -211,10 +211,8 @@ def _unabbreviate(i): if isinstance(i, int): if i >= 0: return self._unabbreviate(i) - else: - return "_:" # blank nodes are given random neg. storid - else: - return i + return "_:" # blank nodes are given random neg. storid + return i for s, p, o in self.world.get_triples(): s = _unabbreviate(s) From 1da61a5dfd58dba7a8684bdf318b533ce4f32cdf Mon Sep 17 00:00:00 2001 From: francescalb Date: Mon, 1 Nov 2021 13:58:28 +0100 Subject: [PATCH 14/16] Clarify documentation of __eq__ for Ontology --- ontopy/ontology.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ontopy/ontology.py b/ontopy/ontology.py index f57012482..e3f30bfdf 100644 --- a/ontopy/ontology.py +++ b/ontopy/ontology.py @@ -200,7 +200,8 @@ def __eq__(self, other): """Checks if this ontology is equal to other. Equality of all triples obtained from self.get_triples(), - i.e. all triples except blank nodes. + i.e. blank nodes are not distinguished, but relations + to blank nodes are included. """ return set(self.get_triples()) == set(other.get_triples()) From 76edb29d965db08ab32405b4f711bb1d440c8b4a Mon Sep 17 00:00:00 2001 From: "Francesca L. Bleken" <48128015+francescalb@users.noreply.github.com> Date: Mon, 1 Nov 2021 19:35:13 +0100 Subject: [PATCH 15/16] write out short names and skip unnecessary intermediate variables Co-authored-by: Casper Welzel Andersen <43357585+CasperWA@users.noreply.github.com> --- ontopy/ontology.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/ontopy/ontology.py b/ontopy/ontology.py index e3f30bfdf..87807a471 100644 --- a/ontopy/ontology.py +++ b/ontopy/ontology.py @@ -215,11 +215,8 @@ def _unabbreviate(i): return "_:" # blank nodes are given random neg. storid return i - for s, p, o in self.world.get_triples(): - s = _unabbreviate(s) - p = _unabbreviate(p) - o = _unabbreviate(o) - yield s, p, o + for subject, predicate, obj in self.world.get_triples(): + yield _unabbreviate(subject), _unabbreviate(predicate), _unabbreviate(obj) def get_by_label(self, label, label_annotations=None, namespace=None): """Returns entity with label annotation `label`. From 1ea3bc9b0525affc052563511738228fd3fa0525 Mon Sep 17 00:00:00 2001 From: francescalb Date: Tue, 2 Nov 2021 12:43:08 +0100 Subject: [PATCH 16/16] Too long line with long variable names fixed --- ontopy/ontology.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ontopy/ontology.py b/ontopy/ontology.py index 87807a471..3947cdc9d 100644 --- a/ontopy/ontology.py +++ b/ontopy/ontology.py @@ -216,7 +216,9 @@ def _unabbreviate(i): return i for subject, predicate, obj in self.world.get_triples(): - yield _unabbreviate(subject), _unabbreviate(predicate), _unabbreviate(obj) + yield (_unabbreviate(subject), + _unabbreviate(predicate), + _unabbreviate(obj)) def get_by_label(self, label, label_annotations=None, namespace=None): """Returns entity with label annotation `label`.