From a25680725a766bc65380ae4c7dfb876c1b3f7c47 Mon Sep 17 00:00:00 2001 From: iQuxLE Date: Wed, 26 Feb 2025 12:49:50 -0800 Subject: [PATCH] add aliases to index_fields to be able to index aliases as well --- src/curategpt/wrappers/ontology/ontology_wrapper.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/curategpt/wrappers/ontology/ontology_wrapper.py b/src/curategpt/wrappers/ontology/ontology_wrapper.py index b596d43..9ff07b4 100644 --- a/src/curategpt/wrappers/ontology/ontology_wrapper.py +++ b/src/curategpt/wrappers/ontology/ontology_wrapper.py @@ -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 @@ -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(): @@ -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)