Basic Ontology Interface

About

Code

class oaklib.interfaces.basic_ontology_interface.BasicOntologyInterface(resource: Optional[oaklib.resource.OntologyResource] = None, strict: bool = False)[source]

Basic lookup operations on ontologies

No Object Model is used - input and payloads are simple scalars, dicts, and lists

This presents an intentionally highly simplistic, lossy view of an ontology. It is intended to fit the “80% of uses” scenario - for more advanced uses, use one of the more specialized subclasses

Basic concepts:

  • An ontology is a collection of entities

  • Entities are typically classes (terms), but they may be other types

  • An entity MUST BE uniquely identifier by a CURIE

  • Each entity SHOULD have a single name

  • Entities may have hierarchical parents and children

  • Entities may have simple relationships to other terms

    • A relationship is a simple triple (in OWL terms, these may represent existential relationships)

    • A CURIE is used for the predicate

  • Entities may have aliases (synonyms)

    • these MAY be typed (scoped)

  • Entities have simple key-value metadata associated with them, where keys are open-ended

Out of scope:

  • Many OWL axioms including:

    • Disjointness

    • Equivalence (including “logical definitions”)

    • Property characteristics

  • All OWL expressions

    • but note that simple SomeValuesFrom expressions are included as relationships

  • Information about specific assignments (“axiom annotations” in OWL terms)

    • this includes attribution for synonyms, definitions, …

  • A fixed datamodel for metadata, beyond core minimal information

CURIEs are used as the default means of identifying entities.

In some cases there may not be a defined CURIE form for an entity, such as an ontology, in which case URIs may be used

alias_map_by_curie(curie: str) Dict[str, List[str]][source]

Deprecated since version Replaced: by alias_map(curie)

aliases_by_curie(curie: str) List[str][source]

Deprecated since version Use: entity_aliases(curie)

all_entity_curies(**kwargs) Iterable[str][source]

Deprecated since version Replaced: by entities

all_obsolete_curies() Iterable[str][source]

Deprecated since version Replaced: by obsoletes()

all_ontology_curies() Iterable[str][source]

Deprecated since version Replaced: by ontology_curies

all_relationships() Iterable[Tuple[str, str, str]][source]

returns iterator over all known relationships

Returns

Deprecated since version Use: relationships()

all_subset_curies() Iterable[str][source]

Deprecated since version Replaced: by subset_curies()

clone(resource: Any) None[source]

Clones the ontology interface to a new resource

Parameters

resource

Returns

create_entity(curie: str, label: Optional[str] = None, relationships: Optional[Dict[str, List[str]]] = None) str[source]

Adds an entity to the resource

Parameters
  • curie

  • label

  • relationships

Returns

curie_to_uri(curie: str, strict=False) Optional[str][source]

Expands a CURIE to a URI

Parameters
  • curie

  • strict – (Default is False) if True, exceptions will be raised if curie cannot be expanded

Returns

curies_by_label(label: str) List[str][source]

Fetches all curies with a given label

This SHOULD return maximum one CURIE but there are circumstances where multiple CURIEs may share a label

Parameters

label

Returns

curies_by_subset(subset: str) Iterable[str][source]

Deprecated since version Replaced: by subset_members(subset)

definition(curie: str) Optional[str][source]
Parameters

curie

:return:x`

dump(path: Optional[str] = None, syntax: Optional[str] = None)[source]

Exports current state

Parameters
  • path

  • syntax

Returns

entities(filter_obsoletes=True, owl_type=None) Iterable[str][source]

returns iterator over all known entity CURIEs

Parameters
  • filter_obsoletes – if True, exclude any obsolete/deprecated element

  • owl_type – e.g. owl:Class

Returns

iterator

entity_alias_map(curie: str) Dict[str, List[str]][source]

Returns aliases keyed by alias type (scope in OBO terms)

  • The alias map MUST include rdfs:label annotations

  • The alias map MAY include other properties the implementation deems to serve an alias role

Parameters

curie

Returns

entity_aliases(curie: str) List[str][source]

All aliases/synonyms for a given CURIE

This lumps together all synonym categories (scopes)

Parameters

curie

Returns

entity_metadata_map(curie: str) Dict[str, List[str]][source]

Returns a dictionary keyed by property predicate, with a list of zero or more values, where each key corresponds to any of a set of open-ended metadata predicates

This is a simplified version of the metadata model in many ontologies

Parameters

curie

Returns

get_curies_by_label(label: str) List[str][source]

Deprecated since version Use: curies_by_label(label)

get_definition_by_curie(curie: str) Optional[str][source]

Deprecated since version Use: definition()

get_incoming_relationship_map_by_curie(curie: str) Dict[str, List[str]][source]

Deprecated since version Use: incoming_relationship_map(curie)

get_incoming_relationships(**kwargs) Iterator[Tuple[str, str]][source]

Deprecated since version Replaced: by incoming_relationships(…)

get_label_by_curie(curie: str) Optional[str][source]

Deprecated since version Use: label(curie))

get_labels_for_curies(**kwargs) Iterable[Tuple[str, str]][source]

Deprecated since version Use: labels(…)

get_outgoing_relationship_map_by_curie(curie: str) Dict[str, List[str]][source]

Deprecated since version Use: outgoing_relationship_map(curie)

get_outgoing_relationships(curie: str, predicates: List[str] = None) Iterator[Tuple[str, str]][source]

Deprecated since version Use: outgoing_relationships()

get_prefix_map() Dict[str, str][source]

Deprecated since version Replaced: by prefix_map

get_relationships(**kwargs) Iterator[Tuple[str, str, str]][source]

Deprecated since version Use: relationships()

hierararchical_parents(curie: str, isa_only: bool = False) List[str][source]

Returns all hierarchical parents

The definition of hierarchical parent depends on the provider. For example, in OLS, this will return part-of parents for GO, as well as is-a

This only returns Named Entities; i.e. if an RDF source is wrapped, this will NOT return blank nodes

To get all relationships, see outgoing_relationships

A fresh map is created each invocation

Parameters
  • curie

  • isa_only – restrict hierarchical parents to isa only

Returns

incoming_relationship_map(curie: str) Dict[str, List[str]][source]

Returns a map of all the relationships where the object is the input CURIE

See :ref:outgoing_relationship_map:

Parameters

curie

Returns

incoming_relationships(curie: str, predicates: Optional[List[str]] = None) Iterator[Tuple[str, str]][source]

Returns relationships where curie in the object

Parameters
  • curie

  • predicates – if None, do not filter

Returns

label(curie: str) Optional[str][source]

fetches the unique label for a CURIE

The CURIE may be for a class, individual, property, or ontology

Parameters

curie

Returns

labels(curies: Iterable[str], allow_none=True) Iterable[Tuple[str, str]][source]

fetches the unique label for a CURIE

The CURIE may be for a class, individual, property, or ontology

Parameters
  • curie

  • allow_none

Returns

leafs(predicates: Optional[List[str]] = None, ignore_owl_nothing=True, filter_obsoletes=True) Iterable[str][source]

All leaf nodes, where root is defined as any node that is not the object of a relationship with one of the specified predicates

Parameters
  • predicates

  • ignore_owl_nothing – do not consider artificial/trivial owl:Nothing when calculating (default=True)

  • filter_obsoletes – do not include obsolete/deprecated nodes in results (default=True)

Returns

obsoletes() Iterable[str][source]

returns iterator over all known CURIEs that are obsolete

Returns

iterator

ontologies() Iterable[str][source]

returns iterator over all known ontology CURIEs

Many OntologyInterfaces will wrap a single ontology, others will wrap multiple. Even when a single ontology is wrapped, there may be multiple ontologies included as imports

Returns

iterator

ontology_curies() Iterable[str][source]

Deprecated since version Replaced: by ontologies()

ontology_metadata(ontology: str) Dict[str, List[str]][source]

Basic metadata about an ontology

Parameters

ontology

Returns

ontology_versions(ontology: str) Iterable[str][source]

returns iterator over all version identifiers for an ontology :param ontology: :return: iterator

outgoing_relationship_map(curie: str) Dict[str, List[str]][source]

The return relationship map is keyed by relationship type, where the values are the ‘parents’ or fillers

OWL formulation:

  • is_a: {P : SubClassOf(C P), class(P)}

  • R: {P : SubClassOf(C ObjectSomeValuesFrom( RP), class(P), property(P)}

Parameters

curie – the ‘child’ term

Returns

outgoing_relationships(curie: str, predicates: Optional[List[str]] = None) Iterator[Tuple[str, str]][source]

Returns relationships where the input curie in the subject

Parameters
  • curie

  • predicates – if None, do not filter

Returns

prefix_map() Dict[str, str][source]

Returns a dictionary mapping all prefixes known to the resource to their URI expansion

Returns

prefix map

relationships(subjects: Optional[List[str]] = None, predicates: Optional[List[str]] = None, objects: Optional[List[str]] = None) Iterator[Tuple[str, str, str]][source]

Returns all matching relationships

Parameters
  • subjects

  • predicates

  • objects

Returns

roots(predicates: Optional[List[str]] = None, ignore_owl_thing=True, filter_obsoletes=True, id_prefixes: Optional[List[str]] = None) Iterable[str][source]

All root nodes, where root is defined as any node that is not the subject of a relationship with one of the specified predicates

Parameters
  • predicates

  • ignore_owl_thing – do not consider artificial/trivial owl:Thing when calculating (default=True)

  • filter_obsoletes – do not include obsolete/deprecated nodes in results (default=True)

  • id_prefixes – limit search to specific prefixes

Returns

save()[source]

Saves current state

Returns

set_label(curie: str, label: str) bool[source]

updates the label

Parameters
  • curie

  • label

Returns

simple_mappings_by_curie(curie: str) Iterable[Tuple[str, str]][source]

Yields mappings for a given subject, where each mapping is represented as a simple tuple

Parameters

curie

Returns

iterator over predicate-object tuples

subset_curies() Iterable[str][source]

Deprecated since version Replaced: by subsets()

subset_members(subset: str) Iterable[str][source]

returns iterator over all CURIEs belonging to a subset

Returns

iterator

subsets() Iterable[str][source]

returns iterator over all known subset CURIEs

Returns

iterator

uri_to_curie(uri: str, strict=True) Optional[str][source]

Contracts a URI to a CURIE

If strict conditions hold, then no URI can map to more than one CURIE (i.e one URI base should not start with another).

Parameters
  • uri – URI

  • strict – Boolean [default: True]

Returns

CURIE