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

setwise-index redux of #359 #548

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions src/oaklib/implementations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from oaklib.implementations.ontoportal.ontoportal_implementation_base import (
OntoPortalImplementationBase,
)
from oaklib.implementations.poi.poi_implementation import PoiImplementation
from oaklib.implementations.pronto.pronto_implementation import ProntoImplementation
from oaklib.implementations.rustsim.rustsim_implementation import RustSimImplementation
from oaklib.implementations.simpleobo.simple_obo_implementation import (
Expand Down Expand Up @@ -82,6 +83,7 @@
"GildaImplementation",
"KGXImplementation",
"TranslatorImplementation",
"PoiImplementation",
"OakMetaModelImplementation",
"RustSimImplementation",
]
Expand Down
Empty file.
44 changes: 44 additions & 0 deletions src/oaklib/implementations/poi/pickled_poi_implementation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import inspect
import logging
from dataclasses import dataclass

from oaklib import OntologyResource
from oaklib.implementations.poi.poi_implementation import PoiImplementation


@dataclass
class PickledPoiImplementation(PoiImplementation):
"""
A BitwiseImplementation that is restored from a pickled index.

To create an index on the command line:

.. code-block:: bash

runoak -i poi:sqlite:obo:hp dump -o /tmp/hp.pkl

To retrieve:

.. code-block:: base

runoak -i pickledpoi:/tmp/hp.pkl termset-similarity HP:0000023 HP:0000024 HP:0000013 @ HP:0000016 HP:0000036
"""

pickle_path: str = None

def __post_init__(self):
if self.pickle_path is None:
self.pickle_path = self.resource.slug
self.load(self.pickle_path)
resource = OntologyResource(slug=self.ontology_index.source)
from oaklib.selector import get_implementation_from_shorthand

slug = resource.slug
logging.info(f"Wrapping an existing OAK implementation to fetch {slug}")
inner_oi = get_implementation_from_shorthand(slug)
self.wrapped_adapter = inner_oi
# delegation magic
methods = dict(inspect.getmembers(self.wrapped_adapter))
for m in self.delegated_methods:
mn = m if isinstance(m, str) else m.__name__
setattr(PoiImplementation, mn, methods[mn])
Loading