linkml.generators package
Submodules
linkml.generators.csvgen module
Generate CSVs
- class linkml.generators.csvgen.CsvGenerator(schema: Union[str, TextIO, linkml_runtime.linkml_model.meta.SchemaDefinition], **kwargs)[source]
Bases:
linkml.utils.generator.Generator
- generatorname: str = 'csvgen.py'
- generatorversion: str = '0.1.1'
- valid_formats: List[str] = ['csv', 'tsv']
- visit_class(cls: linkml_runtime.linkml_model.meta.ClassDefinition) bool [source]
Visited once per schema class
@param cls: class being visited @return: Visit slots and end class. False means skip and go on
linkml.generators.dotgen module
Generate dotfiles
- class linkml.generators.dotgen.DotGenerator(schema: Union[str, TextIO, linkml_runtime.linkml_model.meta.SchemaDefinition], **kwargs)[source]
Bases:
linkml.utils.generator.Generator
- directory_output: bool = True
- end_class(cls: linkml_runtime.linkml_model.meta.ClassDefinition) None [source]
Visited after visit_class_slots (if visit_class returned true)
@param cls: class being visited
- end_schema(**_) None [source]
Visited once at the end of generation
@param kwargs: Arguments passed through from CLI – implementation dependent
- generatorname: str = 'dotgen.py'
- generatorversion: str = '0.1.1'
- valid_formats: List[str] = ['png', 'bmp', 'canon', 'cgimage', 'cmap', 'cmapx', 'cmapx_np', 'dot', 'dot_json', 'eps', 'exr', 'fig', 'gd', 'gd2', 'gif', 'gtk', 'gv', 'ico', 'imap', 'imap_np', 'ismap', 'jp2', 'jpe', 'jpeg', 'jpg', 'json', 'json0', 'pct', 'pdf', 'pic', 'pict', 'plain', 'plain-ext', 'png', 'pov', 'ps', 'ps2', 'psd', 'sgi', 'svg', 'svgz', 'tga', 'tif', 'tiff', 'tk', 'vml', 'vmlz', 'vrml', 'wbmp', 'webp', 'x11', 'xdot', 'xdot1.2', 'xdot1.4', 'xdot_json', 'xlib']
- visit_all_class_slots: bool = True
- visit_class(cls: linkml_runtime.linkml_model.meta.ClassDefinition) bool [source]
Visited once per schema class
@param cls: class being visited @return: Visit slots and end class. False means skip and go on
- visit_class_slot(cls: linkml_runtime.linkml_model.meta.ClassDefinition, aliased_slot_name: str, slot: linkml_runtime.linkml_model.meta.SlotDefinition)[source]
Visited for each slot in a class. If class level visit_all_slots is true, this is visited once for any class that is inherited (class itself, is_a, mixin, apply_to). Otherwise just the own slots.
@param cls: containing class @param aliased_slot_name: Aliased slot name. May not be unique across all class slots @param slot: slot being visited
linkml.generators.flattener module
linkml.generators.golrgen module
Generate GOlr YAML schema definitions.
These can be converted to solr schema-xml, and used in amigo-bbop tools
See the golr-views directory in this repo for examples
- class linkml.generators.golrgen.GOLRClass(*args, _if_missing: Callable[[ForwardRef(‘JsonObj’), str], Tuple[bool, Any]] = None, **kwargs)[source]
Bases:
linkml_runtime.utils.yamlutils.YAMLRoot
- description: str
- display_name: str
- document_category: str
- fields: List[linkml.generators.golrgen.GOLRField]
- id: str
- schema_generating: bool
- weight: int
- class linkml.generators.golrgen.GOLRField(*args, _if_missing: Callable[[ForwardRef(‘JsonObj’), str], Tuple[bool, Any]] = None, **kwargs)[source]
Bases:
linkml_runtime.utils.yamlutils.YAMLRoot
- cardinality: Optional[str] = None
- description: str
- display_name: str
- id: str
- property: List
- class linkml.generators.golrgen.GolrSchemaGenerator(schema: Union[str, TextIO, linkml_runtime.linkml_model.meta.SchemaDefinition], directory: Optional[str] = None, **kwargs)[source]
Bases:
linkml.utils.generator.Generator
- directory_output: bool = True
- end_class(cls: linkml_runtime.linkml_model.meta.ClassDefinition) None [source]
Visited after visit_class_slots (if visit_class returned true)
@param cls: class being visited
- generatorname: str = 'golrgen.py'
- generatorversion: str = '0.1.1'
- valid_formats: List[str] = ['golr']
- visit_all_class_slots: bool = True
- visit_class(cls: linkml_runtime.linkml_model.meta.ClassDefinition) bool [source]
Visited once per schema class
@param cls: class being visited @return: Visit slots and end class. False means skip and go on
- visit_class_slot(cls: linkml_runtime.linkml_model.meta.ClassDefinition, aliased_slot_name: str, slot: linkml_runtime.linkml_model.meta.SlotDefinition) None [source]
Visited for each slot in a class. If class level visit_all_slots is true, this is visited once for any class that is inherited (class itself, is_a, mixin, apply_to). Otherwise just the own slots.
@param cls: containing class @param aliased_slot_name: Aliased slot name. May not be unique across all class slots @param slot: slot being visited
linkml.generators.graphqlgen module
- class linkml.generators.graphqlgen.GraphqlGenerator(schema: Union[str, TextIO, linkml_runtime.linkml_model.meta.SchemaDefinition], **kwargs)[source]
Bases:
linkml.utils.generator.Generator
- end_class(cls: linkml_runtime.linkml_model.meta.ClassDefinition) None [source]
Visited after visit_class_slots (if visit_class returned true)
@param cls: class being visited
- generatorname: str = 'graphqlgen.py'
- generatorversion: str = '0.1.1'
- valid_formats: List[str] = ['graphql']
- visit_all_class_slots: bool = True
- visit_class(cls: linkml_runtime.linkml_model.meta.ClassDefinition) bool [source]
Visited once per schema class
@param cls: class being visited @return: Visit slots and end class. False means skip and go on
- visit_class_slot(cls: linkml_runtime.linkml_model.meta.ClassDefinition, aliased_slot_name: str, slot: linkml_runtime.linkml_model.meta.SlotDefinition) None [source]
Visited for each slot in a class. If class level visit_all_slots is true, this is visited once for any class that is inherited (class itself, is_a, mixin, apply_to). Otherwise just the own slots.
@param cls: containing class @param aliased_slot_name: Aliased slot name. May not be unique across all class slots @param slot: slot being visited
linkml.generators.infer_model module
Infer a schema from a TSV
- class linkml.generators.infer_model.Hit(term_id: str, name: str, score: float, **kwargs)[source]
Bases:
object
- name: str
- score: float
- term_id: str
- linkml.generators.infer_model.get_pv_element(v: str, zooma_confidence: str, cache: dict = {}) linkml.generators.infer_model.Hit [source]
uses ZOOMA to guess a meaning of an enum permissible value
- Parameters
v –
zooma_confidence –
cache –
- Returns
- linkml.generators.infer_model.infer_enum_meanings(schema: dict, zooma_confidence: str = 'MEDIUM', cache={}) None [source]
linkml.generators.jsonldcontextgen module
Generate JSON-LD contexts
- class linkml.generators.jsonldcontextgen.ContextGenerator(schema: Union[str, TextIO, linkml_runtime.linkml_model.meta.SchemaDefinition], **kwargs)[source]
Bases:
linkml.utils.generator.Generator
- end_schema(base: Optional[str] = None, output: Optional[str] = None, prefixes: Optional[bool] = True, flatprefixes: Optional[bool] = False, model: Optional[bool] = True, **_) None [source]
Visited once at the end of generation
@param kwargs: Arguments passed through from CLI – implementation dependent
- generatorname: str = 'jsonldcontextgen.py'
- generatorversion: str = '0.1.1'
- valid_formats: List[str] = ['context', 'json']
- visit_all_class_slots: bool = False
- visit_class(cls: linkml_runtime.linkml_model.meta.ClassDefinition) bool [source]
Visited once per schema class
@param cls: class being visited @return: Visit slots and end class. False means skip and go on
- visit_schema(base: Optional[str] = None, output: Optional[str] = None, **_)[source]
Visited once at the beginning of generation
@param kwargs: Arguments passed through from CLI – implementation dependent
- visit_slot(aliased_slot_name: str, slot: linkml_runtime.linkml_model.meta.SlotDefinition) None [source]
Visited once for every slot definition in the schema.
@param aliased_slot_name: Aliased name of the slot. May not be unique @param slot: visited slot
linkml.generators.jsonldgen module
Generate JSONld
- class linkml.generators.jsonldgen.JSONLDGenerator(*args, **kwargs)[source]
Bases:
linkml.utils.generator.Generator
- adjust_slot(slot: linkml_runtime.linkml_model.meta.SlotDefinition) None [source]
- end_schema(context: Optional[str] = None, **_) None [source]
Visited once at the end of generation
@param kwargs: Arguments passed through from CLI – implementation dependent
- generatorname: str = 'jsonldgen.py'
- generatorversion: str = '0.0.2'
- valid_formats: List[str] = ['jsonld', 'json']
- visit_class(cls: linkml_runtime.linkml_model.meta.ClassDefinition) bool [source]
Visited once per schema class
@param cls: class being visited @return: Visit slots and end class. False means skip and go on
- visit_slot(aliased_slot_name: str, slot: linkml_runtime.linkml_model.meta.SlotDefinition) None [source]
Visited once for every slot definition in the schema.
@param aliased_slot_name: Aliased name of the slot. May not be unique @param slot: visited slot
linkml.generators.jsonschemagen module
- class linkml.generators.jsonschemagen.JsonSchemaGenerator(schema: Union[str, TextIO, linkml_runtime.linkml_model.meta.SchemaDefinition], top_class: Optional[str] = None, **kwargs)[source]
Bases:
linkml.utils.generator.Generator
Generates JSONSchema documents from a LinkML SchemaDefinition
- end_class(cls: linkml_runtime.linkml_model.meta.ClassDefinition) None [source]
Visited after visit_class_slots (if visit_class returned true)
@param cls: class being visited
- end_schema(**_) None [source]
Visited once at the end of generation
@param kwargs: Arguments passed through from CLI – implementation dependent
- generatorname: str = 'jsonschemagen.py'
- generatorversion: str = '0.0.2'
- valid_formats: List[str] = ['json']
- visit_all_class_slots: bool = True
- visit_class(cls: linkml_runtime.linkml_model.meta.ClassDefinition) bool [source]
Visited once per schema class
@param cls: class being visited @return: Visit slots and end class. False means skip and go on
- visit_class_slot(cls: linkml_runtime.linkml_model.meta.ClassDefinition, aliased_slot_name: str, slot: linkml_runtime.linkml_model.meta.SlotDefinition) None [source]
Visited for each slot in a class. If class level visit_all_slots is true, this is visited once for any class that is inherited (class itself, is_a, mixin, apply_to). Otherwise just the own slots.
@param cls: containing class @param aliased_slot_name: Aliased slot name. May not be unique across all class slots @param slot: slot being visited
linkml.generators.lpgen module
- class linkml.generators.lpgen.LogicProgramGenerator(schema: Union[str, TextIO, linkml_runtime.linkml_model.meta.SchemaDefinition], **kwargs)[source]
Bases:
linkml.utils.generator.Generator
- generatorname: str = 'lpgen.py'
- generatorversion: str = '0.0.2'
- valid_formats: List[str] = ['lp', 'sexpr']
- visit_all_class_slots: bool = True
- visit_class(cls: linkml_runtime.linkml_model.meta.ClassDefinition) bool [source]
Visited once per schema class
@param cls: class being visited @return: Visit slots and end class. False means skip and go on
- visit_class_slot(cls: linkml_runtime.linkml_model.meta.ClassDefinition, aliased_slot_name: str, slot: linkml_runtime.linkml_model.meta.SlotDefinition) None [source]
Visited for each slot in a class. If class level visit_all_slots is true, this is visited once for any class that is inherited (class itself, is_a, mixin, apply_to). Otherwise just the own slots.
@param cls: containing class @param aliased_slot_name: Aliased slot name. May not be unique across all class slots @param slot: slot being visited
- visit_slot(slot_name: str, slot: linkml_runtime.linkml_model.meta.SlotDefinition) None [source]
Add a slot definition per slot
@param slot_name: @param slot: @return:
linkml.generators.markdowngen module
- class linkml.generators.markdowngen.MarkdownGenerator(schema: Union[str, TextIO, linkml_runtime.linkml_model.meta.SchemaDefinition], no_types_dir: bool = False, noyuml: bool = False, warn_on_exist: bool = False, **kwargs)[source]
Bases:
linkml.utils.generator.Generator
- bbin(obj: linkml_runtime.linkml_model.meta.Element) str [source]
Boldify built in types
@param obj: object name or id @return:
- class_hier(cls: linkml_runtime.linkml_model.meta.ClassDefinition, level=0) None [source]
- class_link(ref: Optional[Union[str, linkml_runtime.linkml_model.meta.ClassDefinition]], *, after_link: Optional[str] = None, use_desc: bool = False, add_subset: bool = True) str [source]
- class_type_link(ref: Optional[Union[str, linkml_runtime.linkml_model.meta.ClassDefinition, linkml_runtime.linkml_model.meta.TypeDefinition, linkml_runtime.linkml_model.meta.EnumDefinition]], *, after_link: Optional[str] = None, use_desc: bool = False, add_subset: bool = True) str [source]
- desc_for(obj: linkml_runtime.linkml_model.meta.Element, doing_descs: bool) str [source]
Return a description for object if it is unique (different than its parent)
@param obj: object to be described @param doing_descs: If false, always return an empty string @return: text or empty string
- dir_path(obj: Union[linkml_runtime.linkml_model.meta.ClassDefinition, linkml_runtime.linkml_model.meta.SlotDefinition, linkml_runtime.linkml_model.meta.TypeDefinition, linkml_runtime.linkml_model.meta.EnumDefinition]) str [source]
- directory_output: bool = True
- element_header(obj: linkml_runtime.linkml_model.meta.Element, name: str, curie: str, uri: str) None [source]
- enum_link(ref: Optional[Union[str, linkml_runtime.linkml_model.meta.EnumDefinition]], *, after_link: Optional[str] = None, use_desc: bool = False, add_subset: bool = True) str [source]
- exist_warning(*fpath: str) str [source]
Create a file name out of fpath and check whether it already exists
- generatorname: str = 'markdowngen.py'
- generatorversion: str = '0.1.1'
- is_secondary_ref(en: str) bool [source]
Determine whether ‘en’ is the name of something in the neighborhood of the requested classes
@param en: element name @return: True if ‘en’ is the name of a slot, class or type in the immediate neighborhood of of what we are building
- pred_hier(slot: linkml_runtime.linkml_model.meta.SlotDefinition, level=0) None [source]
- static predicate_cardinality(slot: linkml_runtime.linkml_model.meta.SlotDefinition) str [source]
Emit cardinality for a suffix on a predicate
- static range_cardinality(slot: linkml_runtime.linkml_model.meta.SlotDefinition) str [source]
Emits cardinality decorator at end of type
- slot_field(cls: linkml_runtime.linkml_model.meta.ClassDefinition, slot: linkml_runtime.linkml_model.meta.SlotDefinition) None [source]
- slot_link(ref: Optional[Union[str, linkml_runtime.linkml_model.meta.SlotDefinition]], *, after_link: Optional[str] = None, use_desc: bool = False, add_subset: bool = True) str [source]
- subset_link(ref: Optional[Union[str, linkml_runtime.linkml_model.meta.SubsetDefinition]], *, after_link: Optional[str] = None, use_desc: bool = False) str [source]
- type_link(ref: Optional[Union[str, linkml_runtime.linkml_model.meta.TypeDefinition]], *, after_link: Optional[str] = None, use_desc: bool = False, add_subset: bool = True) str [source]
- valid_formats: List[str] = ['md']
- visit_all_class_slots: bool = False
- visit_class(cls: linkml_runtime.linkml_model.meta.ClassDefinition) bool [source]
Visited once per schema class
@param cls: class being visited @return: Visit slots and end class. False means skip and go on
- visit_enum(enum: linkml_runtime.linkml_model.meta.EnumDefinition) None [source]
Visited once for every enum definition in the schema
@param enum: Enum definition
- visit_schema(directory: Optional[str] = None, classes: Optional[Set[linkml_runtime.linkml_model.meta.ClassDefinitionName]] = None, image_dir: bool = False, index_file: str = 'index.md', noimages: bool = False, **_) None [source]
Visited once at the beginning of generation
@param kwargs: Arguments passed through from CLI – implementation dependent
- visit_slot(aliased_slot_name: str, slot: linkml_runtime.linkml_model.meta.SlotDefinition) None [source]
Visited once for every slot definition in the schema.
@param aliased_slot_name: Aliased name of the slot. May not be unique @param slot: visited slot
- visit_subset(subset: linkml_runtime.linkml_model.meta.SubsetDefinition) None [source]
Visited once for every subset definition in the schema
#param subset: Subset definition
linkml.generators.namespacegen module
- class linkml.generators.namespacegen.NamespaceGenerator(schema: Union[str, TextIO, linkml_runtime.linkml_model.meta.SchemaDefinition], format: str = 'py', genmeta: bool = False, gen_classvars: bool = True, gen_slots: bool = True, **kwargs)[source]
Bases:
linkml.generators.pythongen.PythonGenerator
- generatorname: str = 'namespacegen.py'
- generatorversion: str = '0.9.0'
- valid_formats: List[str] = ['py']
- visit_all_class_slots: bool = False
linkml.generators.owlgen module
Generate OWL ontology corresponding to information model
model classes are translated to OWL classes, slots to OWL properties.
- class linkml.generators.owlgen.OwlSchemaGenerator(schema: Union[str, TextIO, linkml_runtime.linkml_model.meta.SchemaDefinition], ontology_uri_suffix: Optional[str] = None, **kwargs)[source]
Bases:
linkml.utils.generator.Generator
- add_metadata(e: linkml_runtime.linkml_model.meta.SchemaDefinition, uri: rdflib.term.URIRef) None [source]
- end_schema(output: Optional[str] = None, **_) None [source]
Visited once at the end of generation
@param kwargs: Arguments passed through from CLI – implementation dependent
- generatorname: str = 'owlgen.py'
- generatorversion: str = '0.1.1'
- is_slot_object_property(slot: linkml_runtime.linkml_model.meta.SlotDefinition) bool [source]
- valid_formats: List[str] = ['owl', 'ttl', 'json-ld', 'xml', 'n3', 'turtle', 'ttl', 'ntriples', 'nt', 'nt11', 'nquads', 'trix', 'trig']
- visit_class(cls: linkml_runtime.linkml_model.meta.ClassDefinition) bool [source]
Visited once per schema class
@param cls: class being visited @return: Visit slots and end class. False means skip and go on
- visit_schema(output: Optional[str] = None, **_)[source]
Visited once at the beginning of generation
@param kwargs: Arguments passed through from CLI – implementation dependent
- visit_slot(slot_name: str, slot: linkml_runtime.linkml_model.meta.SlotDefinition) None [source]
Add a slot definition per slot
@param slot_name: @param slot: @return:
- visit_type(typ: linkml_runtime.linkml_model.meta.TypeDefinition) None [source]
Visited once for every type definition in the schema
@param typ: Type definition
- visits_are_sorted: bool = True
linkml.generators.prefixmapgen module
Generate JSON-LD contexts
- class linkml.generators.prefixmapgen.PrefixGenerator(schema: Union[str, TextIO, linkml_runtime.linkml_model.meta.SchemaDefinition], **kwargs)[source]
Bases:
linkml.utils.generator.Generator
- end_schema(base: Optional[str] = None, output: Optional[str] = None, **_) None [source]
Visited once at the end of generation
@param kwargs: Arguments passed through from CLI – implementation dependent
- generatorname: str = 'prefixmapgen.py'
- generatorversion: str = '0.1.1'
- valid_formats: List[str] = ['json']
- visit_all_class_slots: bool = False
- visit_class(cls: linkml_runtime.linkml_model.meta.ClassDefinition) bool [source]
Visited once per schema class
@param cls: class being visited @return: Visit slots and end class. False means skip and go on
- visit_schema(base: Optional[str] = None, output: Optional[str] = None, **_)[source]
Visited once at the beginning of generation
@param kwargs: Arguments passed through from CLI – implementation dependent
- visit_slot(aliased_slot_name: str, slot: linkml_runtime.linkml_model.meta.SlotDefinition) None [source]
Visited once for every slot definition in the schema.
@param aliased_slot_name: Aliased name of the slot. May not be unique @param slot: visited slot
linkml.generators.projectgen module
- class linkml.generators.projectgen.ProjectConfiguration(directory: str = 'tmp', generator_args: Dict[str, Any] = <factory>, **kwargs)[source]
Bases:
object
- directory: str = 'tmp'
- generator_args: Dict[str, Any]
- class linkml.generators.projectgen.ProjectGenerator[source]
Bases:
object
- generate(schema_path: str, config: linkml.generators.projectgen.ProjectConfiguration = ProjectConfiguration(directory='tmp', generator_args={}))[source]
linkml.generators.protogen module
- class linkml.generators.protogen.ProtoGenerator(schema: Union[str, TextIO, linkml_runtime.linkml_model.meta.SchemaDefinition], **kwargs)[source]
Bases:
linkml.utils.generator.Generator
A Generator for creating Protobuf schemas from a linkml schema.
- end_class(cls: linkml_runtime.linkml_model.meta.ClassDefinition) None [source]
Visited after visit_class_slots (if visit_class returned true)
@param cls: class being visited
- generatorname: str = 'protogen.py'
- generatorversion: str = '0.1.1'
- valid_formats: List[str] = ['proto']
- visit_all_class_slots: bool = True
- visit_class(cls: linkml_runtime.linkml_model.meta.ClassDefinition) bool [source]
Visited once per schema class
@param cls: class being visited @return: Visit slots and end class. False means skip and go on
- visit_class_slot(cls: linkml_runtime.linkml_model.meta.ClassDefinition, aliased_slot_name: str, slot: linkml_runtime.linkml_model.meta.SlotDefinition) None [source]
Visited for each slot in a class. If class level visit_all_slots is true, this is visited once for any class that is inherited (class itself, is_a, mixin, apply_to). Otherwise just the own slots.
@param cls: containing class @param aliased_slot_name: Aliased slot name. May not be unique across all class slots @param slot: slot being visited
linkml.generators.pythongen module
- class linkml.generators.pythongen.PythonGenerator(schema: Union[str, TextIO, linkml_runtime.linkml_model.meta.SchemaDefinition], format: str = 'py', genmeta: bool = False, gen_classvars: bool = True, gen_slots: bool = True, **kwargs)[source]
Bases:
linkml.utils.generator.Generator
- class_reference_type(slot: linkml_runtime.linkml_model.meta.SlotDefinition, cls: Optional[linkml_runtime.linkml_model.meta.ClassDefinition]) Tuple[str, str, str] [source]
Return the type of a slot referencing a class
- Parameters
slot – slot to be typed
cls – owning class. Used for generating key references
- Returns
Python class reference type, most proximal type, most proximal type name
- end_schema(**_)[source]
Visited once at the end of generation
@param kwargs: Arguments passed through from CLI – implementation dependent
- forward_reference(slot_range: str, owning_class: str) bool [source]
Determine whether slot_range is a forward reference
- gen_class_meta(cls: linkml_runtime.linkml_model.meta.ClassDefinition) str [source]
- static gen_class_reference(rangelist: List[str]) str [source]
Return a basic or a union type depending on the number of elements in range list
- Parameters
rangelist – List of types from distal to proximal
- Returns
- gen_class_variable(cls: linkml_runtime.linkml_model.meta.ClassDefinition, slot: linkml_runtime.linkml_model.meta.SlotDefinition, can_be_positional: bool) str [source]
Generate a class variable declaration for the supplied slot. Note: the can_be_positional attribute works, but it makes tag/value lists unduly complex, as you can’t load them with tag=…, value=… – you HAVE to load positionally. We currently ignore this parameter, meaning that we have a tag/value option for any LinkML element
- Parameters
cls – Owning class
slot – slot definition
can_be_positional – True means that positional parameters are allowed.
- Returns
Initializer string
- gen_class_variables(cls: linkml_runtime.linkml_model.meta.ClassDefinition) str [source]
Generate the variable declarations for a dataclass.
- Parameters
cls – class containing variables to be rendered in inheritence hierarchy
- Returns
variable declarations for target class and its ancestors
- gen_classdef(cls: linkml_runtime.linkml_model.meta.ClassDefinition) str [source]
Generate python definition for class cls
- gen_classdefs() str [source]
Create class definitions for all non-mixin classes in the model Note that apply_to classes are transformed to mixins
- gen_enum_definition(enum: linkml_runtime.linkml_model.meta.EnumDefinition, enum_name: str) str [source]
- gen_enum_description(enum: linkml_runtime.linkml_model.meta.EnumDefinition, enum_name: str) str [source]
- gen_import_list() Dict[str, List[str]] [source]
Generate a list of types to import
- Returns
source file followed by elements to import
- gen_inherited_slots(cls: linkml_runtime.linkml_model.meta.ClassDefinition) str [source]
- gen_postinit(cls: linkml_runtime.linkml_model.meta.ClassDefinition, slot: linkml_runtime.linkml_model.meta.SlotDefinition) Optional[str] [source]
Generate python post init rules for slot in class
- gen_postinits(cls: linkml_runtime.linkml_model.meta.ClassDefinition) str [source]
Generate all the typing and existence checks post initialize
- gen_pv_constructor(pv: linkml_runtime.linkml_model.meta.PermissibleValue, indent: int) List[str] [source]
Generate a permissible value constructor @param pv: Value to be constructed @param indent: number of additional spaces to add on successive lines @return: Permissible value constructor
- gen_pvs(enum: linkml_runtime.linkml_model.meta.EnumDefinition) str [source]
Generate the python compliant permissible value initializers as a set of class variables @param enum: @return:
- gen_pvs2(enum: linkml_runtime.linkml_model.meta.EnumDefinition) str [source]
Generate the non-python compliant permissible value initializers as a set of setattr instructions @param enum: @return:
- gen_slot(slot: linkml_runtime.linkml_model.meta.SlotDefinition) str [source]
- generatorname: str = 'pythongen.py'
- generatorversion: str = '0.9.0'
- is_key_value_class(range_name: linkml_runtime.linkml_model.meta.DefinitionName) bool [source]
Return True if range_name references a class with exactly one key and one value
- Parameters
range_name – class definition (name)
- Returns
True if meets the special case
- key_name_for(class_name: linkml_runtime.linkml_model.meta.ClassDefinitionName) Optional[str] [source]
- primary_keys_for(cls: linkml_runtime.linkml_model.meta.ClassDefinition) List[linkml_runtime.linkml_model.meta.SlotDefinitionName] [source]
Return the primary key for cls.
- Note: At the moment we return at most one entry. At some point, keys will be expanded to support
composite keys.
@param cls: class to get keys for @return: List of primary keys or identifiers
- python_uri_for(uriorcurie: Union[str, rdflib.term.URIRef]) Tuple[str, Optional[str]] [source]
Return the python form of uriorcurie :param uriorcurie: :return: URI and CURIE form
- range_cardinality(slot: linkml_runtime.linkml_model.meta.SlotDefinition, cls: Optional[linkml_runtime.linkml_model.meta.ClassDefinition], positional_allowed: bool) Tuple[str, Optional[str]] [source]
Return the range type including initializers, etc. Generate a class variable declaration for the supplied slot. Note: the positional_allowed attribute works, but it makes tag/value lists unduly complex, as you can’t load them with tag=…, value=… – you HAVE to load positionally. We currently ignore this parameter, meaning that we have a tag/value option for any LinkML element
- Parameters
slot – slot to generate type for
cls – containing class – used to render key slots correctly. If absent, slot is an add-in
positional_allowed – True Means that we are in the positional space and defaults are not supplied
- Returns
python property name and initializer (if any)
- range_type_name(slot: linkml_runtime.linkml_model.meta.SlotDefinition) str [source]
Generate the type name for the slot
- valid_formats: List[str] = ['py']
- visit_all_class_slots: bool = False
- visit_class(cls: linkml_runtime.linkml_model.meta.ClassDefinition) bool [source]
Visited once per schema class
@param cls: class being visited @return: Visit slots and end class. False means skip and go on
- visit_schema(**kwargs) None [source]
Visited once at the beginning of generation
@param kwargs: Arguments passed through from CLI – implementation dependent
- visit_slot(aliased_slot_name: str, slot: linkml_runtime.linkml_model.meta.SlotDefinition) None [source]
Visited once for every slot definition in the schema.
@param aliased_slot_name: Aliased name of the slot. May not be unique @param slot: visited slot
linkml.generators.rdfgen module
YAML Schema to RDF Generator
Generate a JSON LD representation of the model
- class linkml.generators.rdfgen.RDFGenerator(schema: Union[str, TextIO, linkml_runtime.linkml_model.meta.SchemaDefinition], **kwargs)[source]
Bases:
linkml.utils.generator.Generator
- end_schema(output: Optional[str] = None, context: Optional[str] = None, **_) None [source]
Visited once at the end of generation
@param kwargs: Arguments passed through from CLI – implementation dependent
- generatorname: str = 'rdfgen.py'
- generatorversion: str = '0.1.1'
- valid_formats: List[str] = ['ttl', 'json-ld', 'n3', 'nquads', 'nt', 'nt11', 'ntriples', 'trig', 'trix', 'ttl', 'turtle', 'xml']
- visit_all_class_slots: bool = False
linkml.generators.shexgen module
Generate ShEx definition of a model
- class linkml.generators.shexgen.ShExGenerator(schema: Union[str, TextIO, linkml_runtime.linkml_model.meta.SchemaDefinition], **args)[source]
Bases:
linkml.utils.generator.Generator
- end_class(cls: linkml_runtime.linkml_model.meta.ClassDefinition) None [source]
Visited after visit_class_slots (if visit_class returned true)
@param cls: class being visited
- end_schema(output: Optional[str] = None, **_) None [source]
Visited once at the end of generation
@param kwargs: Arguments passed through from CLI – implementation dependent
- generatorname: str = 'shexgen.py'
- generatorversion: str = '0.0.2'
- valid_formats: List[str] = ['shex', 'json', 'rdf']
- visit_all_class_slots: bool = False
- visit_class(cls: linkml_runtime.linkml_model.meta.ClassDefinition) bool [source]
Visited once per schema class
@param cls: class being visited @return: Visit slots and end class. False means skip and go on
- visit_class_slot(cls: linkml_runtime.linkml_model.meta.ClassDefinition, aliased_slot_name: linkml_runtime.linkml_model.meta.SlotDefinitionName, slot: linkml_runtime.linkml_model.meta.SlotDefinition) None [source]
Visited for each slot in a class. If class level visit_all_slots is true, this is visited once for any class that is inherited (class itself, is_a, mixin, apply_to). Otherwise just the own slots.
@param cls: containing class @param aliased_slot_name: Aliased slot name. May not be unique across all class slots @param slot: slot being visited
linkml.generators.sparqlgen module
- class linkml.generators.sparqlgen.SparqlGenerator(schema: Union[str, TextIO, linkml_runtime.linkml_model.meta.SchemaDefinition], format: str = 'sparql', named_graphs: Optional[List[str]] = None, limit: Optional[int] = None, **kwargs)[source]
Bases:
linkml.utils.generator.Generator
- generatorname: str = 'sparqlgen.py'
- serialize(directory=None) str [source]
Generate output in the required format
- Parameters
kwargs – Generater specific parameters
- Returns
Generated output
- valid_formats: List[str] = ['sparql']
- visit_all_class_slots: bool = False
- linkml.generators.sparqlgen.materialize_schema(schemaview: linkml_runtime.utils.schemaview.SchemaView)[source]
linkml.generators.sqlddlgen module
- class linkml.generators.sqlddlgen.Backref(original_column: SQLColumn, backref_column: SQLColumn, order_by: str = None, **kwargs)[source]
Bases:
object
- backref_column: linkml.generators.sqlddlgen.SQLColumn
- order_by: str = None
- original_column: linkml.generators.sqlddlgen.SQLColumn
- class linkml.generators.sqlddlgen.DDLEntity(description: Optional[str] = None, **kwargs)[source]
Bases:
object
abstract grouping
- description: str = None
- class linkml.generators.sqlddlgen.SQLColumn(description: Optional[str] = None, name: Optional[str] = None, mapped_to: Optional[linkml_runtime.linkml_model.meta.SlotDefinition] = None, mapped_to_alias: Optional[str] = None, table: Optional[linkml.generators.sqlddlgen.SQLTable] = None, base_type: Optional[str] = None, is_singular_primary_key: bool = False, foreign_key: Optional[linkml.generators.sqlddlgen.SQLColumn] = None, **kwargs)[source]
Bases:
linkml.generators.sqlddlgen.DDLEntity
represents a Relational Table Column
- base_type: str = None
- foreign_key: Optional[linkml.generators.sqlddlgen.SQLColumn] = None
- is_singular_primary_key: bool = False
- mapped_to: linkml_runtime.linkml_model.meta.SlotDefinition = None
- mapped_to_alias: str = None
- name: str = None
- table: linkml.generators.sqlddlgen.SQLTable = None
- class linkml.generators.sqlddlgen.SQLDDLGenerator(schema: Union[str, TextIO, linkml_runtime.linkml_model.meta.SchemaDefinition], dialect='sqlite', use_foreign_keys=True, rename_foreign_keys=False, direct_mapping=False, **kwargs)[source]
Bases:
linkml.utils.generator.Generator
A Generator for creating SQL DDL
The basic algorithm for mapping a linkml schema S is as follows:
Each schema S corresponds to one database schema D (see SQLSchema)
Each Class C in S is mapped to a table T (see SQLTable)
Each slot S in each C is mapped to a column Col (see SQLColumn)
if the direct_mapping attribute is set to true, then no further transformations are applied. Note that this means:
inline objects are modeled as Text strings
multivalued fields are modeled as single Text strings
this direct mapping is useful for simple spreadsheet/denormalized representations of complex data. however, for other applications, additional transformations should occur. these are:
MULTIVALUED SLOTS
The relational model does not have direct representation of lists. These are normalized as follows.
If the range of the slot is a class, and there are no other slots whose range is this class, and the slot is for a class that has a singular primary key, then a backref is added.
E.g. if we have User 0..* Address, then add a field User_id to Address.
When SQLAlchemy bindings are created, a backref mapping is added
If the range of the slot is an enum or type, then a new linktable is created, and a backref added
E.g. if a class User has a multivalues slot alias whose range is a string, then create a table user_aliases, with two columns (1) alias [a string] and (2) a backref to user
Each mapped slot C.S has a range R
- ranges that are types (literals):
If R is a type, and the slot is NOT multivalued, do a direct type conversion
If R is a type, and the slot is multivalued: * do not include the mapped column * create a new table T_S, with 2 columns: S, and a backref to T
- ranges that are classes:
Ref = map_class_to_table(R) - if R is a class, and the slot is NOT multivalued, and Ref has a singular primary key:
Col.type = ForeignKey(Ref.PK)
if R is a class, and the slot is NOT multivalued, and Ref has NO singular primary key: * add a foreign key C.pk to Ref * add a backref C.S => Ref, C.pk * remove Col from T
If R is a class, and the slot IS multivalued
- dialect: str
- end_class(cls: linkml_runtime.linkml_model.meta.ClassDefinition) None [source]
Visited after visit_class_slots (if visit_class returned true)
@param cls: class being visited
- end_schema(**kwargs) None [source]
Visited once at the end of generation
@param kwargs: Arguments passed through from CLI – implementation dependent
- generatorname: str = 'sqlddlgen.py'
- generatorversion: str = '0.1.1'
- get_sql_range(slot: linkml_runtime.linkml_model.meta.SlotDefinition)[source]
returns a SQL Alchemy column type
- inject_primary_keys: bool = True
- sqlschema: linkml.generators.sqlddlgen.SQLSchema = SQLSchema(description=None, name=None, mapped_to=None, tables={})
- use_inherits: bool = False
- valid_formats: List[str] = ['proto']
- visit_all_class_slots: bool = True
- visit_class(cls: linkml_runtime.linkml_model.meta.ClassDefinition) bool [source]
Visited once per schema class
@param cls: class being visited @return: Visit slots and end class. False means skip and go on
- visit_class_slot(cls: linkml_runtime.linkml_model.meta.ClassDefinition, aliased_slot_name: str, slot: linkml_runtime.linkml_model.meta.SlotDefinition) None [source]
Visited for each slot in a class. If class level visit_all_slots is true, this is visited once for any class that is inherited (class itself, is_a, mixin, apply_to). Otherwise just the own slots.
@param cls: containing class @param aliased_slot_name: Aliased slot name. May not be unique across all class slots @param slot: slot being visited
- write_sqla_python_imperative(model_path: str) str [source]
imperative mapping: https://docs.sqlalchemy.org/en/14/orm/mapping_styles.html#imperative-mapping-with-dataclasses-and-attrs
maps to the python classes generated using PythonGenerator
``` output = StringIO() with redirect_stdout(output):
gen.write_sqla_python_imperative()
- class linkml.generators.sqlddlgen.SQLSchema(description: Optional[str] = None, name: Optional[str] = None, mapped_to: Optional[linkml_runtime.linkml_model.meta.SchemaDefinition] = None, tables: Dict[str, linkml.generators.sqlddlgen.SQLTable] = <factory>, **kwargs)[source]
Bases:
linkml.generators.sqlddlgen.DDLEntity
represents a Relational Schema
- add_table(t: linkml.generators.sqlddlgen.SQLTable)[source]
- all_columns() List[linkml.generators.sqlddlgen.SQLColumn] [source]
- get_table_by_class_name(cn: linkml_runtime.linkml_model.meta.ClassDefinitionName) Optional[linkml.generators.sqlddlgen.SQLTable] [source]
- mapped_to: linkml_runtime.linkml_model.meta.SchemaDefinition = None
- name: str = None
- tables: Dict[str, linkml.generators.sqlddlgen.SQLTable]
- class linkml.generators.sqlddlgen.SQLTable(description: Optional[str] = None, name: Optional[str] = None, mapped_to: Optional[linkml_runtime.linkml_model.meta.ClassDefinition] = None, columns: Dict[str, linkml.generators.sqlddlgen.SQLColumn] = <factory>, in_schema: Optional[linkml.generators.sqlddlgen.SQLSchema] = None, referenced_by: List[linkml.generators.sqlddlgen.SQLColumn] = <factory>, primary_keys: List[linkml.generators.sqlddlgen.SQLColumn] = <factory>, backrefs: List[linkml.generators.sqlddlgen.Backref] = <factory>, **kwargs)[source]
Bases:
linkml.generators.sqlddlgen.DDLEntity
represents a Relational Table
- add_column(c: linkml.generators.sqlddlgen.SQLColumn)[source]
- backrefs: List[linkml.generators.sqlddlgen.Backref]
- columns: Dict[str, linkml.generators.sqlddlgen.SQLColumn]
- get_singular_primary_key() Optional[linkml.generators.sqlddlgen.SQLColumn] [source]
- in_schema: linkml.generators.sqlddlgen.SQLSchema = None
- mapped_to: linkml_runtime.linkml_model.meta.ClassDefinition = None
- name: str = None
- primary_keys: List[linkml.generators.sqlddlgen.SQLColumn]
- referenced_by: List[linkml.generators.sqlddlgen.SQLColumn]
linkml.generators.summarygen module
Generate Summary Spreadsheets
- class linkml.generators.summarygen.SummaryGenerator(schema: Union[str, TextIO, linkml_runtime.linkml_model.meta.SchemaDefinition], **args)[source]
Bases:
linkml.utils.generator.Generator
- generatorname: str = 'summarygen.py'
- generatorversion: str = '0.1.1'
- valid_formats: List[str] = ['tsv']
- visit_class(cls: linkml_runtime.linkml_model.meta.ClassDefinition) bool [source]
Visited once per schema class
@param cls: class being visited @return: Visit slots and end class. False means skip and go on
- visit_class_slot(cls: linkml_runtime.linkml_model.meta.ClassDefinition, aliased_slot_name: str, slot: linkml_runtime.linkml_model.meta.SlotDefinition) None [source]
Visited for each slot in a class. If class level visit_all_slots is true, this is visited once for any class that is inherited (class itself, is_a, mixin, apply_to). Otherwise just the own slots.
@param cls: containing class @param aliased_slot_name: Aliased slot name. May not be unique across all class slots @param slot: slot being visited
linkml.generators.terminusdbgen module
linkml.generators.yamlgen module
Validate linkml input and optionally emit completely resolved biolink yaml output
- class linkml.generators.yamlgen.YAMLGenerator(schema: Union[str, TextIO, linkml_runtime.linkml_model.meta.SchemaDefinition], **kwargs)[source]
Bases:
linkml.utils.generator.Generator
A generator that produces a schema as a YAML Document
- generatorname: str = 'yamlgen.py'
- generatorversion: str = '0.1.0'
- serialize(validateonly: bool = False, **kwargs) str [source]
Generate output in the required format
- Parameters
kwargs – Generater specific parameters
- Returns
Generated output
- valid_formats: List[str] = ['yaml']
linkml.generators.yumlgen module
Generate yuml
https://yuml.me/diagram/scruffy/class/samples
- class linkml.generators.yumlgen.YumlGenerator(schema: Union[str, TextIO, linkml_runtime.linkml_model.meta.SchemaDefinition], **args)[source]
Bases:
linkml.utils.generator.Generator
- static cardinality(slot: linkml_runtime.linkml_model.meta.SlotDefinition, is_attribute: bool = True) str [source]
- class_associations(cn: linkml_runtime.linkml_model.meta.ClassDefinitionName, must_render: bool = False) str [source]
Emit all associations for a focus class. If none are specified, all classes are generated
@param cn: Name of class to be emitted @param must_render: True means render even if this is a target (class is specifically requested) @return: YUML representation of the association
- class_box(cn: linkml_runtime.linkml_model.meta.ClassDefinitionName) str [source]
Generate a box for the class. Populate its interior only if (a) it hasn’t previously been generated and (b) it appears in the gen_classes list
@param cn: @return:
- filtered_cls_slots(cn: linkml_runtime.linkml_model.meta.ClassDefinitionName, all_slots: bool = True, filtr: Optional[Callable[[linkml_runtime.linkml_model.meta.SlotDefinition], bool]] = None) List[linkml_runtime.linkml_model.meta.SlotDefinition] [source]
Return the set of slots associated with the class that meet the filter criteria. Slots will be returned in defining order, with class slots returned last
@param cn: name of class to filter @param all_slots: True means include attributes @param filtr: Slot filter predicate @return: List of slot definitions
- generatorname: str = 'yumlgen.py'
- generatorversion: str = '0.1.1'
- prop_modifier(cls: linkml_runtime.linkml_model.meta.ClassDefinition, slot: linkml_runtime.linkml_model.meta.SlotDefinition) str [source]
- Return the modifiers for the slot:
(i) - inherited (m) - inherited through mixin (a) - injected (pk) - primary ckey
@param cls: @param slot: @return:
- valid_formats: List[str] = ['yuml', 'png', 'pdf', 'jpg', 'json', 'svg']
- visit_all_class_slots: bool = False
Module contents
Generators translate between a SchemaDefinition and an alternative representation such as JsonSchema