Annotators

Importers take an existing schema and annotate it with information

Annotators typically talk to an external ontology. We use the OAK library to wrap a large number of different sources that can be used for annotation, including:

  • BioPortal

  • OLS/ZOOMA

  • Arbitrary ontologies in obo format, OWL, RDF, or JSON

  • Ubergraph

  • Wikidata

  • LOV

For documentation on selecting the right ontology source, see:

class schema_automator.annotators.SchemaAnnotator(ontology_implementation: BasicOntologyInterface | None = None, mine_descriptions: bool = False, allow_partial: bool = False, curie_only: bool = True, assign_element_uris: bool = False, assign_enum_meanings: bool = False)[source]

An engine for enhancing schemas by performing lookup and annotation operations using an ontology service.

A SchemaAnnotator wraps an OAK ontology interface. See OAK documentation for more details

annotate_element(elt: PermissibleValue | Element) None[source]

Annotates an element or a permissible value

Parameters:

elt

Returns:

annotate_schema(schema: SchemaDefinition | str) SchemaDefinition[source]

Annotate all elements of a schema, adding mappings.

This requires that the OntologyInterface implements either BasicOntologyInterface or SearchInterface

enrich(schema: SchemaDefinition | str) SchemaDefinition[source]

Enrich a schema by performing lookups on the external ontology/vocabulary endpoint, and copying over metadata

Currently, the only metadata obtained is text definitions


>>> from schema_automator.annotators.schema_annotator import SchemaAnnotator
>>> from oaklib.selector import get_implementation_from_shorthand
>>> oi = get_implementation_from_shorthand("sqlite:obo:so")
>>> sa = SchemaAnnotator(ontology_implementation=oi)
>>> schema = sa.enrich("tests/data/schema.yaml")
Parameters:

schema

Returns:

class schema_automator.annotators.JsonLdAnnotator(ontology_implementation: BasicOntologyInterface | None = None, mine_descriptions: bool = False, allow_partial: bool = False, curie_only: bool = True, assign_element_uris: bool = False, assign_enum_meanings: bool = False)[source]

Annotates a schema using URIs/Prefixes derived from a JSON-LD file

annotate(schema: str | SchemaDefinition, jsonld_path: str) SchemaDefinition[source]

Annotate a schema

Parameters:
  • schema – schema object (mutated) or path to schema

  • jsonld_path – path to input JSONLD context file

Returns:

annotate_element(el: Definition, mapping_slot: str, jsonld: Dict)[source]

Annotates an element or a permissible value

Parameters:

elt

Returns:

class schema_automator.annotators.LLMAnnotator(ontology_implementation: BasicOntologyInterface | None = None, mine_descriptions: bool = False, allow_partial: bool = False, curie_only: bool = True, assign_element_uris: bool = False, assign_enum_meanings: bool = False, model_name: str | None = None)[source]

Annotates a schema using an LLM.

enrich(schema: SchemaDefinition | str) SchemaDefinition[source]

Enrich a schema using an LLM.

>>> from schema_automator.utils.schemautils import write_schema
>>> annotator = LLMAnnotator(model_name="gpt-4")
>>> schema = annotator.enrich("tests/resources/biopax3.yaml")
>>> write_schema(schema)

Requires installation with the llm extra:

pip install schema-automator[llm]

Note: exercise caution on running this on large schemas with expensive models like gpt-4.

Parameters:

schema

Returns: