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

Corrected so that get_by_label_all also returns all concepts #503

Merged
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
6 changes: 6 additions & 0 deletions ontopy/ontology.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down