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, _edge_index: ~oaklib.indexes.edge_index.EdgeIndex | None = None, _entailed_edge_index: ~oaklib.indexes.edge_index.EdgeIndex | 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


Search uses to specify both an input query and search results,

see Datamodels

Search over ontology using the specified search term.

Searching over aliases (synonyms) as well as labels:

>>> from oaklib import get_adapter
>>> from 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
  • search_term

  • config


As basic_search, using multiple terms

  • search_terms

  • config


autosave: bool

For adapters that wrap a transactional source (e.g sqlite), this controls whether results should be auto-committed after each operation

exclude_owl_top_and_bottom: bool

Do not include owl:Thing or owl:Nothing

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


>>> from import SearchConfiguration, SearchTermSyntax
>>> cfg = SearchConfiguration(syntax=SearchTermSyntax.REGULAR_EXPRESSION)