Search Interface
- class oaklib.interfaces.search_interface.SearchInterface(resource: ~oaklib.resource.OntologyResource | None = None, strict: bool = False, _multilingual: bool | None = None, autosave: bool = <factory>, exclude_owl_top_and_bottom: bool = <factory>, ontology_metamodel_mapper: ~oaklib.mappers.ontology_metadata_mapper.OntologyMetadataMapper | None = None, _converter: ~curies.api.Converter | None = None, auto_relax_axioms: bool | None = None, cache_lookups: bool = False, property_cache: ~oaklib.utilities.keyval_cache.KeyValCache = <factory>, _edge_index: ~oaklib.indexes.edge_index.EdgeIndex | None = None, _entailed_edge_index: ~oaklib.indexes.edge_index.EdgeIndex | None = None, _prefix_map: ~typing.Mapping[str, str] | None = None)[source]
An Ontology Interface that supports text-based search.
The search interface provides a largely implementation-neutral way to query an ontology. It allows for
exact or partial matches
matching the beginning of a term
regular expression search
It also allows you to control which metadata elements are searched over (typically labels and aliases)
Implementations may differ in their behavior. Some implementations may not be able to honor specific requests. For example, the SqlDatabaseImplementation implementation may not be able to fulfil regular expression queries.
Some endpoints may return results that are ranked by relevance, others may be arbitrary
Command Line
A good way to explore this interface is via the search subcommand:
Ubergraph uses relevancy ranking:
runoak -i ubergraph:uberon search limb
Exact match for a label using sqlite:
runoak -i db/cl.db search l=neuron
Inexact match for a label or synonym using sqlite:
poetry run runoak -i db/cl.db search .~neuron
Datamodels
- Search uses https://w3id.org/oak/search to specify both an input query and search results,
see Datamodels
- basic_search(search_term: str, config: SearchConfiguration | None = None) Iterable[str] [source]
Search over ontology using the specified search term.
Searching over aliases (synonyms) as well as labels:
>>> from oaklib import get_adapter >>> from oaklib.datamodels.search import SearchProperty, SearchConfiguration >>> uberon = get_adapter("sqlite:obo:uberon") >>> config = SearchConfiguration(properties=[SearchProperty.ALIAS]) >>> for curie in uberon.basic_search("hand", config=config): ... print(curie, uberon.label(curie)) UBERON:0002398 manus
Searching over mapped identifiers (xrefs):
>>> config = SearchConfiguration(properties=[SearchProperty.MAPPED_IDENTIFIER]) >>> for curie in uberon.basic_search("FMA:9712", config=config): ... print(curie, uberon.label(curie)) UBERON:0002398 manus
Partial search:
>>> config = SearchConfiguration(is_partial=True, properties=[SearchProperty.ALIAS]) >>> for curie in sorted(uberon.basic_search("hand", config=config)): ... print(curie, uberon.label(curie)) ... UBERON:0007723 interphalangeal joint of manual digit 1 UBERON:0007729 interphalangeal joint of manual digit 2 ...
- Parameters:
search_term
config
- Returns:
- multiterm_search(search_terms: List[str], config: SearchConfiguration | None = None) Iterable[str] [source]
As basic_search, using multiple terms
- Parameters:
search_terms
config
- Returns:
- class oaklib.interfaces.search_interface.SearchConfiguration(*args, _if_missing: Callable[[JsonObj, str], Tuple[bool, Any]] | None = None, **kwargs)[source]
Parameters for altering behavior of search
Examples:
>>> from oaklib.datamodels.search import SearchConfiguration, SearchTermSyntax >>> cfg = SearchConfiguration(syntax=SearchTermSyntax.REGULAR_EXPRESSION)