diff --git a/ontopy/ontology.py b/ontopy/ontology.py index 249b8db50..51d09b0c0 100644 --- a/ontopy/ontology.py +++ b/ontopy/ontology.py @@ -377,8 +377,14 @@ def get_by_label_all(self, label, label_annotations=None, prefix=None): entity = self.world.search(**{next(annotations): label}) for key in annotations: entity.extend(self.world.search(**{key: label})) + if self._special_labels and label in self._special_labels: entity.append(self._special_labels[label]) + + entity_accessed_directly = self.world[self.base_iri + label] + if entity_accessed_directly and entity_accessed_directly not in entity: + entity.append(entity_accessed_directly) + if prefix: return [_ for _ in entity if _.namespace.ontology.prefix == prefix] return entity diff --git a/tests/test_basic.py b/tests/test_basic.py index c6b614728..74ed7ad71 100755 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -18,6 +18,14 @@ def test_basic(emmo: "Ontology") -> None: # Add entity directly onto.new_entity("Hydrogen", emmo.Atom) + # Test that new entity is found by both version of get_by_label + assert onto.get_by_label("Hydrogen") == onto.Hydrogen + assert onto.get_by_label_all("Hydrogen") == [onto.Hydrogen] + + onto.sync_attributes() + # Test that after sync_attributes, the entity is not counted more than once + assert onto.get_by_label_all("Hydrogen") == [onto.Hydrogen] + with pytest.raises(LabelDefinitionError): onto.new_entity("Hydr ogen", emmo.Atom) @@ -40,8 +48,6 @@ class H2O(emmo.Molecule): water = H2O() water.hasSpatialDirectPart = [H1, H2, O] - print(onto.label_annotations) - print(onto._label_annotations) name_prefix = "myonto_" onto.sync_attributes(name_policy="sequential", name_prefix=name_prefix) assert f"{onto.base_iri}{name_prefix}0" in onto