Skip to content

Commit

Permalink
get_by_label_all works without sync_attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
francescalb authored Nov 18, 2022
1 parent 10bd9ea commit c414377
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
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

0 comments on commit c414377

Please sign in to comment.