SchemaView#

The SchemaView class in the linkml-runtime provides a method for dynamically introspecting and manipulating schemas.

See SchemaView notebooks

class linkml_runtime.utils.schemaview.SchemaView(schema: str | Path | SchemaDefinition, importmap: dict[str, str] | None = None, merge_imports: bool = False, base_dir: str | None = None)[source]#

A SchemaView provides a virtual schema layered on top of a schema plus its import closure.

Most operations are parameterized by imports. If this is set to True (default), then the full import closure is considered when answering

This class utilizes caching for efficient lookup operations.

TODO: decide how to use this in conjunction with the existing schemaloader, which injects into the schema rather than providing dynamic methods.

See:
add_class(cls: ClassDefinition) None[source]#

Add a class to the schema.

Parameters:

cls – class to be added

Returns:

add_enum(enum: EnumDefinition) None[source]#

Add an enum to the schema.

Parameters:

enum – enum to be added

Returns:

add_slot(slot: SlotDefinition) None[source]#

Add a slot to the schema.

Parameters:

slot – slot to be added

Returns:

add_subset(subset: SubsetDefinition) None[source]#

Add a subset to the schema.

Parameters:

subset – subset to be added

Returns:

add_type(type_def: TypeDefinition) None[source]#

Add a type to the schema.

Parameters:

type – type to be added

Returns:

all_aliases() list[str][source]#

Get all aliases.

Returns:

list of aliases

all_class(imports: bool = True) dict[linkml_runtime.linkml_model.meta.ClassDefinitionName, linkml_runtime.linkml_model.meta.ClassDefinition][source]#

Return all classes.

Parameters:

imports – include imports closure

Returns:

all classes in schema view

all_classes(ordered_by: OrderedBy = OrderedBy.PRESERVE, imports: bool = True) dict[linkml_runtime.linkml_model.meta.ClassDefinitionName, linkml_runtime.linkml_model.meta.ClassDefinition][source]#

Retrieve all classes from a schema.

Parameters:
  • ordered_by – an enumerated parameter that returns all the classes in the order specified.

  • imports – include imports closure

Returns:

all classes in schema view

all_element(imports: bool = True) dict[linkml_runtime.linkml_model.meta.ElementName, linkml_runtime.linkml_model.meta.Element][source]#

Retrieve all elements from the schema.

Parameters:

imports – include imports closure

Returns:

all elements in schema view

all_elements(imports: bool = True) dict[linkml_runtime.linkml_model.meta.ElementName, linkml_runtime.linkml_model.meta.Element][source]#

Retrieve all elements from the schema.

Parameters:

imports – include imports closure

Returns:

all elements in schema view

all_enum(imports: bool = True) dict[linkml_runtime.linkml_model.meta.EnumDefinitionName, linkml_runtime.linkml_model.meta.EnumDefinition][source]#

Retrieve all enums from the schema.

Parameters:

imports – include imports closure

Returns:

all enums in schema view

all_enums(imports: bool = True) dict[linkml_runtime.linkml_model.meta.EnumDefinitionName, linkml_runtime.linkml_model.meta.EnumDefinition][source]#

Retrieve all enums from the schema.

Parameters:

imports – include imports closure

Returns:

all enums in schema view

all_schema(imports: bool = True) list[linkml_runtime.linkml_model.meta.SchemaDefinition][source]#

Return all schemas.

Parameters:

imports – include imports closure

Returns:

all schemas

all_slot(**kwargs: dict[str, Any]) dict[linkml_runtime.linkml_model.meta.SlotDefinitionName, linkml_runtime.linkml_model.meta.SlotDefinition][source]#

Retrieve all slots from the schema.

Parameters:

imports – include imports closure

Returns:

all slots in schema view

all_slots(ordered_by: OrderedBy = OrderedBy.PRESERVE, imports: bool = True, attributes: bool = True) dict[linkml_runtime.linkml_model.meta.SlotDefinitionName, linkml_runtime.linkml_model.meta.SlotDefinition][source]#

Retrieve all slots from the schema.

Parameters:
  • ordered_by – an enumerated parameter that returns all the slots in the order specified.

  • imports – include imports closure

  • attributes – include attributes as slots or not, default is to include.

Returns:

all slots in schema view

all_subset(imports: bool = True) dict[linkml_runtime.linkml_model.meta.SubsetDefinitionName, linkml_runtime.linkml_model.meta.SubsetDefinition][source]#

Retrieve all subsets from the schema.

Parameters:

imports – include imports closure

Returns:

all subsets in schema view

all_subsets(imports: bool = True) dict[linkml_runtime.linkml_model.meta.SubsetDefinitionName, linkml_runtime.linkml_model.meta.SubsetDefinition][source]#

Retrieve all subsets from the schema.

Parameters:

imports – include imports closure

Returns:

all subsets in schema view

all_type(imports: bool = True) dict[linkml_runtime.linkml_model.meta.TypeDefinitionName, linkml_runtime.linkml_model.meta.TypeDefinition][source]#

Retrieve all types from the schema.

Parameters:

imports – include imports closure

Returns:

all types in schema view

all_types(imports: bool = True) dict[linkml_runtime.linkml_model.meta.TypeDefinitionName, linkml_runtime.linkml_model.meta.TypeDefinition][source]#

Retrieve all types from the schema.

Parameters:

imports – include imports closure

Returns:

all types in schema view

annotation_dict(element_name: ElementName, imports: bool = True) dict[URIorCURIE, Any][source]#

Return a dictionary where keys are annotation tags and values are annotation values for any given element.

Note this will not include higher-order annotations

See also: https://github.com/linkml/linkml/issues/296

Parameters:
  • element_name

  • imports

Returns:

annotation dictionary

class_ancestors(class_name: ClassDefinitionName | str, imports: bool = True, mixins: bool = True, reflexive: bool = True, is_a: bool = True, depth_first: bool = True) list[linkml_runtime.linkml_model.meta.ClassDefinitionName][source]#

Return the closure of class_parents method.

Parameters:
  • class_name – query class

  • imports – include import closure

  • mixins – include mixins (default is True)

  • is_a – include is_a parents (default is True)

  • reflexive – include self in set of ancestors

  • depth_first

Returns:

ancestor class names

class_children(class_name: ClassDefinitionName | str, imports: bool = True, mixins: bool = True, is_a: bool = True) list[linkml_runtime.linkml_model.meta.ClassDefinitionName][source]#

Return class children.

Parameters:
  • class_name – parent class name

  • imports – include import closure

  • mixins – include mixins (default is True)

  • is_a – include is_a parents (default is True)

Returns:

all direct child class names (is_a and mixins)

class_descendants(class_name: ClassDefinitionName | str, imports: bool = True, mixins: bool = True, reflexive: bool = True, is_a: bool = True) list[linkml_runtime.linkml_model.meta.ClassDefinitionName][source]#

Return the closure of class_children method.

Parameters:
  • class_name – query class

  • imports – include import closure

  • mixins – include mixins (default is True)

  • is_a – include is_a parents (default is True)

  • reflexive – include self in set of descendants

Returns:

descendants class names

class_induced_slots(class_name: ClassDefinitionName | str | None = None, imports: bool = True) list[linkml_runtime.linkml_model.meta.SlotDefinition][source]#

Retrieve all slots that are asserted or inferred for a class, with their inferred semantics.

Parameters:
  • class_name

  • imports

Returns:

inferred slot definition

class_leaves(imports: bool = True, mixins: bool = True, is_a: bool = True) list[linkml_runtime.linkml_model.meta.ClassDefinitionName][source]#

Return all classes that have no children.

Parameters:
  • imports

  • mixins

  • is_a – include is_a parents (default is True)

Returns:

class_name_mappings() dict[str, linkml_runtime.linkml_model.meta.ClassDefinition][source]#

Return a mapping between processed safe class names (following naming conventions) and classes.

For example, a class may have name ‘named thing’, the code-safe version is NamedThing

Returns:

mapping from safe names to class

class_parents(class_name: ClassDefinitionName | str, imports: bool = True, mixins: bool = True, is_a: bool = True) list[linkml_runtime.linkml_model.meta.ClassDefinitionName][source]#
Parameters:
  • class_name – child class name

  • imports – include import closure

  • mixins – include mixins (default is True)

Returns:

all direct parent class names (is_a and mixins)

class_roots(imports: bool = True, mixins: bool = True, is_a: bool = True) list[linkml_runtime.linkml_model.meta.ClassDefinitionName][source]#

Return all classes that have no parents.

Parameters:
  • imports

  • mixins

  • is_a – include is_a parents (default is True)

Returns:

class_slots(class_name: ClassDefinitionName | str, imports: bool = True, direct: bool = False, attributes: bool = True) list[linkml_runtime.linkml_model.meta.SlotDefinitionName][source]#

Return all slots for a class.

Parameters:
  • class_name

  • imports – include imports closure

  • direct – only returns slots directly associated with a class (default is False)

  • attributes – include attribute declarations as well as slots (default is True)

Returns:

all slot names applicable for a class

copy_schema(new_name: str | None = None) SchemaDefinition[source]#

Generate a copy of the schema.

Parameters:

new_name (str | None, optional) – name for the new schema, defaults to None

Returns:

copied SchemaDefinition, optionally with new name

Return type:

SchemaDefinition

delete_class(class_name: ClassDefinitionName, delete_references: bool = True) None[source]#

Delete a class from the schema.

Parameters:

class_name – class to be deleted

Returns:

delete_enum(enum_name: EnumDefinitionName) None[source]#

Delete an enum from the schema.

Parameters:

enum_name – enum to be deleted

Returns:

delete_slot(slot_name: SlotDefinitionName) None[source]#

Delete a slot from the schema.

Parameters:

slot_name – slot to be deleted

Returns:

delete_subset(subset_name: SubsetDefinitionName) None[source]#

Delete a subset from the schema.

Parameters:

subset_name – subset to be deleted

Returns:

delete_type(type_name: TypeDefinitionName) None[source]#

Delete a type from the schema.

Parameters:

type_name – type to be deleted

Returns:

enum_ancestors(enum_name: EnumDefinitionName | str, imports: bool = True, mixins: bool = True, reflexive: bool = True, is_a: bool = True, depth_first: bool = True) list[linkml_runtime.linkml_model.meta.EnumDefinitionName][source]#

Return the closure of enum_parents method.

Parameters:
  • enum_name – query enum

  • imports – include import closure

  • mixins – include mixins (default is True)

  • is_a – include is_a parents (default is True)

  • reflexive – include self in set of ancestors

  • depth_first

Returns:

ancestor enum names

enum_parents(enum_name: EnumDefinitionName | str, imports: bool = False, mixins: bool = False, is_a: bool = True) list[linkml_runtime.linkml_model.meta.EnumDefinitionName][source]#
Parameters:
  • enum_name – child enum name

  • imports – include import closure (False)

  • mixins – include mixins (default is False)

Returns:

all direct parent enum names (is_a and mixins)

expand_curie(uri: str) str[source]#

Expand a URI or CURIE to a full URI.

Parameters:

uri

Returns:

URI as a string

get_children(name: str, mixin: bool = True) list[str][source]#

Get the children of an element (any class, slot, enum, type).

Parameters:
  • name – name of the parent element

  • mixin – include mixins

Returns:

list of child element

get_class(class_name: ClassDefinitionName | str, imports: bool = True, strict: bool = False) ClassDefinition[source]#

Retrieve a class from the schema.

Parameters:
  • class_name – name of the class to be retrieved

  • imports – include import closure

Returns:

class definition

get_classes_by_slot(slot: SlotDefinition, include_induced: bool = False) list[linkml_runtime.linkml_model.meta.ClassDefinitionName][source]#

Get all classes that use a given slot, either as a direct or induced slot.

Parameters:
  • slot – slot in consideration

  • include_induced – supplement all direct slots with induced slots, defaults to False

Returns:

list of slots, either direct, or both direct and induced

get_classes_modifying_slot(slot: SlotDefinition) list[linkml_runtime.linkml_model.meta.ClassDefinition][source]#

Get all ClassDefinitions that modify a given slot.

Parameters:

slot_name – slot in consideration

Returns:

list of ClassDefinitions modifying the slot of interest

get_element(element: ElementName | Element, imports: bool = True) Element[source]#

Fetch an element by name.

Parameters:
  • element – query element

  • imports – include imports closure

Returns:

get_elements_applicable_by_identifier(identifier: str) list[str][source]#

Get a model element by identifier.

The model element corresponding to the given identifier as available via the id_prefixes mapped to that element.

Parameters:

identifier

Returns:

Optional[str]

get_elements_applicable_by_prefix(prefix: str) list[str][source]#

Get a model element by prefix.

The model element corresponding to the given prefix as available via the id_prefixes mapped to that element.

Parameters:

prefix – the prefix of a CURIE

Returns:

Optional[str]

get_enum(enum_name: EnumDefinitionName | str, imports: bool = True, strict: bool = False) EnumDefinition[source]#

Retrieve an enum from the schema.

Parameters:
  • enum_name – name of the enum to be retrieved

  • imports – include import closure

Returns:

enum definition

get_identifier_slot(cn: ClassDefinitionName | str, use_key: bool = False, imports: bool = True) SlotDefinition | None[source]#

Retrieve the slot that is the identifier for the given class.

Parameters:
  • cn – class name

  • imports

Returns:

slot that acts as identifier, if present

get_key_slot(cn: ClassDefinitionName | str, imports: bool = True) SlotDefinition | None[source]#

Retrieve the slot that is the key for the given class.

Parameters:
  • cn – class name

  • imports

Returns:

slot that acts as key, if present

get_mapping_index(imports: bool = True, expand: bool = False) dict[URIorCURIE, list[tuple[MAPPING_TYPE, Element]]][source]#

Return an index of all elements keyed by the mapping value.

The index values are tuples of mapping type and element

Parameters:
  • imports

  • expand – if true the index will be keyed by expanded URIs, not CURIEs

Returns:

index

get_mappings(element_name: ElementName = None, imports: bool = True, expand: bool = False) dict[MAPPING_TYPE, list[URIorCURIE]][source]#

Get all mappings for a given element.

Parameters:
  • element_name – the query element

  • imports – include imports closure

  • expand – expand CURIEs to URIs

Returns:

index keyed by mapping type

get_slot(slot_name: SlotDefinitionName | str, imports: bool = True, attributes: bool = True, strict: bool = False) SlotDefinition[source]#

Retrieve a slot from the schema.

Parameters:
  • slot_name – name of the slot to be retrieved

  • imports – include import closure

  • attributes – include attributes

  • strict – raise ValueError is not found

Returns:

slot definition

get_slots_by_enum(enum_name: EnumDefinitionName | str = None) list[linkml_runtime.linkml_model.meta.SlotDefinition][source]#

Get all slots that use a given enum: schema defined, attribute, or slot_usage.

Parameters:

enum_name – enum in consideration

Returns:

list of slots, either schem or both class attribute defined

get_subset(subset_name: SubsetDefinitionName | str, imports: bool = True, strict: bool = False) SubsetDefinition[source]#

Retrieve a subset from the schema.

Parameters:
  • subset_name – name of the subsey to be retrieved

  • imports – include import closure

Returns:

subset definition

get_type(type_name: TypeDefinitionName | str, imports: bool = True, strict: bool = False) TypeDefinition[source]#

Retrieve a type from the schema.

Parameters:
  • type_name – name of the type to be retrieved

  • imports – include import closure

Returns:

type definition

get_type_designator_slot(cn: ClassDefinitionName | str, imports: bool = True) SlotDefinition | None[source]#

Get the type designator slot for a class.

Parameters:
  • cn – class name

  • imports

Returns:

name of slot that acts as type designator for the given class

get_uri(element: ElementName | Element, imports: bool = True, expand: bool = False, native: bool = False, use_element_type: bool = False) str[source]#

Return the CURIE or URI for a schema element.

If the schema defines a specific URI, this is used; otherwise this is constructed from the default prefix combined with the element name.

Parameters:
  • element – name of schema element

  • imports – include imports closure

  • native – return the native CURIE or URI rather than what is declared in the uri slot

  • expand – expand the CURIE to a URI; defaults to False

Returns:

URI or CURIE as a string

importmap: Mapping[str, str] | None = None#

Optional mapping between schema names and local paths/URLs

imports_closure(imports: bool = True, traverse: bool | None = None, inject_metadata: bool = True) list[linkml_runtime.linkml_model.meta.SchemaDefinitionName][source]#

Return all imports.

Objects in imported classes override one another in a “python-like” order - from the point of view of the importing schema, imports will override one another from first to last, recursively for each layer of imports.

An import tree like:

- main
  - s1
    - s1_1
    - s1_2
        - s1_2_1
        - s1_2_2
  - s2
    - s2_1
    - s2_2

will override objects with the same name, in order:

['s1_1', 's1_2_1', 's1_2_2', 's1_2', 's1', 's2_1', 's2_2', 's2']
Parameters:
  • imports – bool (default: True ) include imported schemas, recursively

  • traverse – bool, optional (default: True ) (Deprecated, use imports ). if true, traverse recursively

Returns:

all schema names in the transitive reflexive imports closure

in_schema(element_name: ElementName) SchemaDefinitionName[source]#

Retrieve the name of the schema in which an element is defined.

Parameters:

element_name

Returns:

name of schema in which element is defined

induced_class(class_name: ClassDefinitionName | str | None = None) ClassDefinition[source]#

Generate an induced class.

  • the class will have no slots

  • the class will have one attribute per class_induced_slots

Induced slots are represented as attributes as these are fully locally owner by the class :param class_name: base class name :param imports: :return: induced class

induced_enum(enum_name: EnumDefinitionName | str | None = None) EnumDefinition[source]#

Generate an induced enum.

Parameters:

enum_name

Returns:

induced_slot(slot_name: SlotDefinitionName | str, class_name: ClassDefinitionName | str | None = None, imports: bool = True, mangle_name: bool = False) SlotDefinition[source]#

Generate a SlotDefinition with all properties materialized.

Given a slot, in the context of a particular class, yield a dynamic SlotDefinition that has all properties materialized.

This makes use of schema slots, such as attributes, slot_usage. It also uses ancestor relationships to infer missing values, for inheritable slots

Parameters:
  • slot_name – slot to be queries

  • class_name – class used as context

  • imports – include imports closure

Returns:

dynamic slot constructed by inference

induced_type(type_name: TypeDefinitionName | str | None = None) TypeDefinition[source]#

Generate an induced type.

Parameters:

type_name

Returns:

inverse(slot_name: SlotDefinition)[source]#

Determine whether the given name is a relationship, and return the inverse (if available).

If that relationship has an inverse, returns the inverse.

Parameters:

slot_name – The name or alias of an element in the model

Returns:

inverse_name

is_inlined(slot: SlotDefinition, imports: bool = True) bool[source]#

Return true if slot is inferred or asserted inline.

Parameters:
  • slot

  • imports

Returns:

is_mixin(element_name: ElementName | Element) bool[source]#

Determine whether the given name is the name of a mixin.

An element is a mixin if one of its properties is “is_mixin:true”

Parameters:

element_name – The name or alias of an element in the model

Returns:

boolean

is_multivalued(slot_name: SlotDefinition) bool[source]#

Return True if slot is multivalued, else returns False.

Parameters:

slot_name – slot to test for multivalued

Return boolean:

is_relationship(class_name: ClassDefinitionName | str | None = None, imports: bool = True) bool[source]#

Test if a class represents a relationship or reified statement.

Parameters:
  • class_name

  • imports

Returns:

true if the class represents a relationship

is_slot_percent_encoded(slot: SlotDefinitionName) bool | None[source]#

Return true if slot or its range is has a percent_encoded annotation.

This is true for type fields that are the range of identifier columns, where the identifier is not guaranteed to be a valid URI or CURIE

Parameters:

slot

Returns:

load_import(imp: str, from_schema: SchemaDefinition | None = None) SchemaDefinition[source]#

Handle import directives.

The value of the import can be:

  • a URL (specified as either a full URL or a CURIE)

  • a local file path

The import should leave off the .yaml suffix.

If the import is a URL then the import is fetched over the network UNLESS this is a metamodel import, in which case it is fetched from within the linkml_runtime package, where the yaml is distributed. This ensures that the version of the metamodel imported matches the version of the linkml_runtime package.

In future, this mechanism may be extended to arbitrary modules, such that we avoid network dependence at runtime in general.

For local paths, the import is resolved relative to the directory containing the source file, or the URL of the source file, if it is a URL.

Parameters:
  • imp

  • from_schema

Returns:

materialize_derived_schema() SchemaDefinition[source]#

Materialize a schema view into a schema definition.

materialize_patterns() None[source]#

Materialize schema by expanding structured patterns into regular expressions based on composite patterns provided in the settings dictionary.

merge_imports() None[source]#

Merge the full imports closure.

merge_schema(schema: SchemaDefinition, clobber: bool = False) None[source]#

Merge another schema into this one.

If the other schema has an element with the same name as an element in this schema, then this element is NOT copied.

Parameters:
  • schema – schema to be merged

  • clobber – if True, then overwrite existing elements

namespaces() Namespaces[source]#

Return the namespaces present in a schema.

Returns:

namespaces

Return type:

Namespaces

ordered(elements: dict[ElementNameType, ElementType], ordered_by: OrderedBy | None = None) dict[ElementNameType, ElementType][source]#

Order a dictionary of elements with some ordering method in OrderedBy.

permissible_value_ancestors(permissible_value_text: str, enum_name: EnumDefinitionName | str, reflexive: bool = True, depth_first: bool = True) list[str][source]#

Return the closure of permissible_value_parents method.

Parameters:
  • permissible_value_text (str) –

  • enum_name (ENUM_NAME) –

  • reflexive (bool, optional) – …, defaults to True

  • depth_first (bool, optional) – …, defaults to True

Returns:

closure of permissible_value_parents

Return type:

list[str]

permissible_value_descendants(permissible_value_text: str, enum_name: EnumDefinitionName | str, reflexive: bool = True, depth_first: bool = True) list[str][source]#

Return the closure of permissible_value_children method.

:enum

permissible_value_parent(permissible_value: str, enum_name: EnumDefinitionName | str) str | PermissibleValueText | None | ValueError[source]#
Parameters:
  • enum_name – child enum name

  • permissible_value – permissible value

Returns:

all direct parent enum names (is_a)

set_modified() None[source]#

Increase the number of schema modifications by 1.

slot_ancestors(slot_name: SlotDefinitionName | str, imports: bool = True, mixins: bool = True, reflexive: bool = True, is_a: bool = True) list[linkml_runtime.linkml_model.meta.SlotDefinitionName][source]#

Return the closure of slot_parents method.

Parameters:
  • slot_name – query slot

  • imports – include import closure

  • mixins – include mixins (default is True)

  • is_a – include is_a parents (default is True)

  • reflexive – include self in set of ancestors

Returns:

ancestor slot names

slot_applicable_range_elements(slot: SlotDefinition) list[linkml_runtime.linkml_model.meta.ClassDefinitionName][source]#

Retrieve all applicable metamodel elements for a slot range.

(metamodel class names returned: class_definition, enum_definition, type_definition)

Typically any given slot has exactly one range, and one metamodel element type, but a proposed feature in LinkML 1.2 is range expressions, where ranges can be defined as unions

Additionally, if linkml:Any is a class_uri then this maps to the any element

Parameters:

slot

Returns:

list of element types

slot_children(slot_name: SlotDefinitionName | str, imports: bool = True, mixins: bool = True, is_a: bool = True) list[linkml_runtime.linkml_model.meta.SlotDefinitionName][source]#

Return slot children.

Parameters:
  • slot_name – parent slot name

  • imports – include import closure

  • mixins – include mixins (default is True)

  • is_a – include is_a parents (default is True)

Returns:

all direct child slot names (is_a and mixins)

slot_descendants(slot_name: SlotDefinitionName | str, imports: bool = True, mixins: bool = True, reflexive: bool = True, is_a: bool = True) list[linkml_runtime.linkml_model.meta.SlotDefinitionName][source]#

Return the closure of slot_children method.

Parameters:
  • slot_name – query slot

  • imports – include import closure

  • mixins – include mixins (default is True)

  • is_a – include is_a parents (default is True)

  • reflexive – include self in set of descendants

Returns:

descendants slot names

slot_is_true_for_metadata_property(slot_name: SlotDefinition, metadata_property: str) bool[source]#

Return true if the value of the provided “metadata_property” is True.

For example, sv.slot_is_true_for_metadata_property(‘id’,’identifier’) will return True if the slot id has the identifier property set to True.

Parameters:
  • slot_name – slot to test for multivalued

  • metadata_property – controlled vocabulary for boolean attribtues

Returns:

boolean

slot_leaves(imports: bool = True, mixins: bool = True) list[linkml_runtime.linkml_model.meta.SlotDefinitionName][source]#

Return all slots that have no children.

Parameters:
  • imports

  • mixins

Returns:

slot_name_mappings() dict[str, linkml_runtime.linkml_model.meta.SlotDefinition][source]#

Return a mapping between processed safe slot names (following naming conventions) and slots.

For example, a slot may have name ‘lives at’, the code-safe version is lives_at

Returns:

mapping from safe names to slot

slot_parents(slot_name: SlotDefinitionName | str, imports: bool = True, mixins: bool = True, is_a: bool = True) list[linkml_runtime.linkml_model.meta.SlotDefinitionName][source]#

Return the parent of a slot, if it exists.

Parameters:
  • slot_name – child slot name

  • imports – include import closure

  • mixins – include mixins (default is True)

Returns:

all direct parent slot names (is_a and mixins)

slot_range_as_union(slot: SlotDefinition) list[linkml_runtime.linkml_model.meta.ElementName][source]#

Retrieve all applicable ranges for a slot.

Typically, any given slot has exactly one range, and one metamodel element type, but a proposed feature in LinkML 1.2 is range expressions, where ranges can be defined as unions

Parameters:

slot

Returns:

list of ranges

slot_roots(imports: bool = True, mixins: bool = True) list[linkml_runtime.linkml_model.meta.SlotDefinitionName][source]#

Return all slots that have no parents.

Parameters:
  • imports

  • mixins

Returns:

type_ancestors(type_name: TYPES, imports: bool = True, reflexive: bool = True, depth_first: bool = True) list[TypeDefinitionName][source]#

Return all ancestors of a type via typeof.

Parameters:
  • type_name – query type

  • imports – include import closure

  • reflexive – include self in set of ancestors

  • depth_first

Returns:

ancestor class names

type_parents(type_name: TypeDefinitionName | str, imports: bool = True) list[linkml_runtime.linkml_model.meta.TypeDefinitionName][source]#

Return the parent of a type, if it exists.

Parameters:
  • type_name – child type name

  • imports – include import closure

Returns:

all direct parent enum names (is_a and mixins)

usage_index() dict[linkml_runtime.linkml_model.meta.ElementName, list[linkml_runtime.utils.schemaview.SchemaUsage]][source]#

Fetch an index that shows the ways in which each element is used.

Returns:

dictionary of SchemaUsages keyed by used elements