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

Enable passing a custom Gilda grounder class #120

Merged
merged 4 commits into from
Nov 12, 2021
Merged
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
11 changes: 8 additions & 3 deletions src/pyobo/gilda_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

"""PyOBO's Gilda utilities."""

from typing import Iterable, Optional, Tuple, Union
from typing import Iterable, Optional, Tuple, Type, Union

import bioregistry
import gilda.api
Expand Down Expand Up @@ -84,7 +84,9 @@ def normalize_identifier(prefix: str, identifier: str) -> str:


def get_grounder(
prefix: Union[str, Iterable[str]], unnamed: Optional[Iterable[str]] = None
prefix: Union[str, Iterable[str]],
unnamed: Optional[Iterable[str]] = None,
grounder_cls: Optional[Type[Grounder]] = None,
) -> Grounder:
"""Get a Gilda grounder for the given namespace."""
unnamed = set() if unnamed is None else set(unnamed)
Expand All @@ -101,7 +103,10 @@ def get_grounder(
terms.extend(p_terms)
terms = filter_out_duplicates(terms)
terms = multidict((term.norm_text, term) for term in terms)
return Grounder(terms)
if grounder_cls is None:
return Grounder(terms)
else:
return grounder_cls(terms)


def get_gilda_terms(prefix: str, identifiers_are_names: bool = False) -> Iterable[gilda.term.Term]:
Expand Down