Skip to content

Commit

Permalink
Add ephemeral cache to mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
caufieldjh committed Aug 11, 2024
1 parent 49970ed commit 7391b8a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/ontogpt/engines/knowledge_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ class KnowledgeEngine(ABC):
mappers: Optional[List[BasicOntologyInterface]] = None
"""List of concept mappers, to assist in grounding to desired ID prefix"""

map_cache: Dict[str, str] = field(default_factory=dict)
"""Cache of mappings obtained using the specified mappers."""

labelers: Optional[List[BasicOntologyInterface]] = None
"""Labelers that map CURIEs to labels"""

Expand Down Expand Up @@ -395,6 +398,12 @@ def map_identifier(self, input_id: str, cls: ClassDefinition) -> Iterator[str]:
:param cls:
:return:
"""
if input_id not in self.map_cache:
self.map_cache[input_id] = []
else:
for obj_id in self.map_cache[input_id]:
yield obj_id

try:
if input_id.startswith("http://purl.bioontology.org/ontology"):
# TODO: this should be fixed upstream in OAK
Expand All @@ -416,6 +425,7 @@ def map_identifier(self, input_id: str, cls: ClassDefinition) -> Iterator[str]:
for mapper in self.mappers:
if isinstance(mapper, MappingProviderInterface):
for mapping in mapper.sssom_mappings([input_id]):
self.map_cache[input_id].append(str(mapping.object_id))
yield str(mapping.object_id)
else:
raise ValueError(f"Unknown mapper type {mapper}")
Expand Down

0 comments on commit 7391b8a

Please sign in to comment.