Skip to content

Commit

Permalink
Merge pull request #133 from iQuxLE/add_aliases_to_index_fields
Browse files Browse the repository at this point in the history
add "aliases" to OntologyClass for indexing
  • Loading branch information
iQuxLE authored Feb 28, 2025
2 parents dc25bf2 + a256807 commit a9579e2
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/curategpt/wrappers/ontology/ontology_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class OntologyWrapper(BaseWrapper):
default_max_search_results: int = 500
fetch_definitions: bool = field(default=True)
fetch_relationships: bool = field(default=True)
fetch_aliases: bool = field(default=True)
relationships_as_fields: bool = field(default=False)

branches: List[str] = None
Expand Down Expand Up @@ -97,6 +98,12 @@ def objects(
for chunked_entities in chunk(selected_ids, 100):
for id, defn, _ in adapter.definitions(chunked_entities):
definitions[id] = defn
aliases_by_entity = {}
if self.fetch_aliases:
for sub in entities:
entity_aliases = list(adapter.entity_aliases(sub))
cleaned = [alias if alias is not None else "" for alias in entity_aliases]
aliases_by_entity[sub] = cleaned
relationships = defaultdict(list)
if self.fetch_relationships:
for sub, pred, obj in adapter.relationships():
Expand All @@ -121,6 +128,7 @@ def objects(
id=shorthand,
label=labels[id],
original_id=id,
aliases=aliases_by_entity.get(id, []),
)
for pred, tgt in relationships.get(id, []):
k = self._as_shorthand(pred)
Expand Down

0 comments on commit a9579e2

Please sign in to comment.