### Testing Rewrite Rules Setup Source: https://github.com/linkml/linkml-model/blob/main/tests/test_rewrite_rules/httpd/README.md Instructions for setting up and running unit tests for the w3id.org rewrite rules. Ensure Docker is running and necessary Python packages are installed. ```bash > cd httpd > docker image build . -t w3id > docker run --rm -d -p 8091:80 --name w3id -v `pwd`/linkml:/w3id/linkml w3id > cd ../../.. > pipenv install > pipenv shell (linkml) > cd tests/test_rewrite_rules (linkml) > export SERVER="http://localhost:8091" (linkml) > python test_rewrite_rules.py ssss ---------------------------------------------------------------------- Ran 4 tests in 0.000s OK (skipped=6) (linkml) > exit > docker stop w3id ``` -------------------------------- ### Install LinkML Model with uv Source: https://github.com/linkml/linkml-model/blob/main/README.md Installs the LinkML model project dependencies using uv. Ensure you are in the project's root directory. ```bash > cd linkml-model > uv sync ``` -------------------------------- ### Example Class Instance (Python) Source: https://github.com/linkml/linkml-model/blob/main/linkml_model/model/docs/specification/02instances.md Demonstrates the functional syntax for creating an instance of a class, specifying its type and assignments for slots. ```python Person(id=..., name=..., age=..., ) ``` -------------------------------- ### Combined Instance Example in Python Source: https://github.com/linkml/linkml-model/blob/main/linkml_model/model/docs/specification/02instances.md A comprehensive example of an InstanceOfClass for a 'Person' type, demonstrating nested structures, collections, atomic values, and references. ```python Person( id=String^"SSN:123", name=String^"Alex", aliases=[String^"Alexandra"], address=None, phone=PhoneNumber^"+1 800 555 0100", height= Measurement(value=Decimal^170.2 unit=UnitCode["cm"]), relationships=[ FamilialRelationship( type=RelationshipType["SIBLING_OF"], related_to=Person&"SSN:456" ) ] ) ``` -------------------------------- ### Class Definition Example: YAML Source: https://github.com/linkml/linkml-model/blob/main/linkml_model/model/docs/specification/03schemas.md Example of defining LinkML ClassDefinitions using YAML syntax, corresponding to the functional Python example. ```yaml NamedThing: abstract: true slots: - id - name Person: description: A person, living or dead is_a: NamedThing attributes: height: ... age: ... ``` -------------------------------- ### Schema Example: YAML Syntax Source: https://github.com/linkml/linkml-model/blob/main/linkml_model/model/docs/specification/03schemas.md This snippet demonstrates how a LinkML schema can be represented in YAML format. It mirrors the structure shown in the functional syntax example, including id, imports, prefixes, classes, slots, enums, and types. ```yaml id: http://example.org/personinfo imports: ... prefixes: ... classes: ... slots: ... enums: ... types: ... ``` -------------------------------- ### YAML Schema Example for Inheritance Source: https://github.com/linkml/linkml-model/blob/main/linkml_model/model/docs/specification/07codegen.md Illustrates a simple LinkML schema with a base class 'NamedThing' and a derived class 'Person' demonstrating inheritance. ```yaml classes: NamedThing: attributes: id: Person: is_a: NamedThing attributes: address: ``` -------------------------------- ### Instance Path Accessor Examples Source: https://github.com/linkml/linkml-model/blob/main/linkml_model/model/docs/specification/02instances.md Demonstrates how to access specific data within an instance using dot notation for slots and bracket notation for collection members. ```python i == i i.id == String^"SSN:123" i.height.unit == String^"cm" i.relationships[0].related_to == Person&"SSN:456" ``` -------------------------------- ### Collection Instance Examples Source: https://github.com/linkml/linkml-model/blob/main/linkml_model/model/docs/specification/02instances.md Demonstrates various ways to represent collections (lists) of instances, including primitive types, class instances, heterogeneous collections, and empty collections. ```plaintext [String^"A", String^"B", Integer^5] ``` ```plaintext [Person(name=..., ...), Person(name=..., ...)] ``` ```plaintext [Person(name=..., ...), Integer^5, None] ``` ```plaintext [] ``` -------------------------------- ### Slot Definition Example in Python Source: https://github.com/linkml/linkml-model/blob/main/linkml_model/model/docs/specification/03schemas.md An example of defining slots within a LinkML schema using Python syntax. This demonstrates the structure for 'id' and 'name' slots. ```python SchemaDefinition( slots=[ SlotDefinition( name=String^"id", identifier=Boolean^True, description=String^"A unique identifier for an object", range=TypeDefinitionReference&"String", ... ), SlotDefinition( name=String^"name", description=String^"...", range=String^"String", ... ) ``` -------------------------------- ### Run Tests Source: https://github.com/linkml/linkml-model/blob/main/README.md Executes the test suite for the LinkML model project. This command is typically run after installation or code changes. ```bash > make test ``` -------------------------------- ### Schema Resolution Examples Source: https://github.com/linkml/linkml-model/blob/main/linkml_model/model/docs/specification/04derived-schemas.md Demonstrates the mapping of specific definition references to their corresponding entries within the schema's class or slot dictionaries. ```python m.classes["Person"] ``` ```python m.slots["vital_status"] ``` -------------------------------- ### Instance Reference Example in Python Source: https://github.com/linkml/linkml-model/blob/main/linkml_model/model/docs/specification/02instances.md Shows a syntactically valid instance reference for a Person type. Schema validation requires a ClassDefinition with an identifier. ```python Person&"SSN:456" ``` -------------------------------- ### Class Definition Example: Functional Syntax Source: https://github.com/linkml/linkml-model/blob/main/linkml_model/model/docs/specification/03schemas.md Example of defining LinkML ClassDefinitions using the functional Python syntax. Includes basic properties like name, abstract, slots, and attributes. ```python [ ClassDefinition( name=String^"NamedThing", abstract=True, slots=[ SlotDefinitionReference&"id", SlotDefinitionReference&"name", ... ] ), ClassDefinition( name=String^"Person", description=String^"A person, living or dead", is_a=ClassDefinitionReference&"NamedThing", attributes=[ SlotDefinition( name=String^"height", ...), SlotDefinition( name=String^"age", ...) ), ... ], ``` -------------------------------- ### None Instance Example Source: https://github.com/linkml/linkml-model/blob/main/linkml_model/model/docs/specification/02instances.md Shows how to represent a null or missing value using the 'None' symbol. This is equivalent to omitting the assignment. ```python Person(address=None) ``` -------------------------------- ### Derived Class URI Example Source: https://github.com/linkml/linkml-model/blob/main/linkml_model/model/docs/specification/04derived-schemas.md Demonstrates how class URIs are derived when not explicitly specified, using prefixes and default prefixes. This ensures consistent URI generation for schema elements. ```yaml prefixes: foo: http://example.org/foo/ bar: http://example.org/bar/ default_prefix: foo classes: A: class_uri: bar:A ... B: ... ``` -------------------------------- ### Resolve Function Examples Source: https://github.com/linkml/linkml-model/blob/main/linkml_model/model/docs/specification/04derived-schemas.md Illustrates how the Resolve function maps different definition types to their corresponding entries within a schema's internal structure. ```python m.slots[] ``` ```python m.classes[] ``` ```python m.enums[] ``` ```python m.types[] ``` -------------------------------- ### Define ClassDefinition with Inheritance and Attributes in YAML Source: https://context7.com/linkml/linkml-model/llms.txt A complete ClassDefinition example in YAML, demonstrating single inheritance, mixins, inline attributes, unique keys, and rules. ```yaml # A complete ClassDefinition example in YAML classes: Person: description: A person with an identifier and address is_a: NamedThing # single inheritance mixins: - HasAliases # multiple mixins allowed slots: - id - name - primary_address - age attributes: nickname: # inline attribute (slot owned by this class) range: string multivalued: true unique_keys: by_name_and_age: unique_key_slots: - name - age rules: - preconditions: slot_conditions: age: maximum_value: 18 postconditions: none_of: - slot_conditions: primary_address: range_expression: slot_conditions: country: equals_string: USA description: Minors cannot have a USA address in this model tree_root: false disjoint_with: - Organization ``` -------------------------------- ### Derived Slot Algorithm Example Source: https://github.com/linkml/linkml-model/blob/main/linkml_model/model/docs/specification/04derived-schemas.md Illustrates the application of the DerivedSlot algorithm to populate derived attributes for classes. This is applied to each applicable slot for any given class. ```python for c in m.classes: for s in ApplicableSlots(c): d = DerivedSlot(m,s,c) c.attributes[s] = d ``` -------------------------------- ### YAML Equivalent of Minimal Schema Source: https://context7.com/linkml/linkml-model/llms.txt This YAML represents the same minimal schema definition as the Python example, showing the declarative format. ```yaml id: https://example.org/my-schema name: my-schema description: A minimal person schema license: https://creativecommons.org/publicdomain/zero/1.0/ version: "1.0.0" default_prefix: ex default_range: string imports: - linkml:types ``` -------------------------------- ### TypeDefinition Python Example Source: https://context7.com/linkml/linkml-model/llms.txt Instantiates a TypeDefinition object in Python to represent a custom string type with a name and typeof attribute. ```python from linkml_model import TypeDefinition t = TypeDefinition(name="EmailString", typeof="string") print(t.name) # EmailString print(t.typeof) # string ``` -------------------------------- ### Atomic Instance Examples in Python Source: https://github.com/linkml/linkml-model/blob/main/linkml_model/model/docs/specification/02instances.md Illustrates syntactically valid instances of atomic types like Integer and PhoneNumber. Note that schema validation is separate from syntactic validity. ```python Integer^23 ``` ```python Integer^"ABC" ``` ```python PhoneNumber^"+1 800 555 0100" ``` -------------------------------- ### YAML Serialization of a LinkML Schema Source: https://github.com/linkml/linkml-model/blob/main/linkml_model/model/docs/specification/03schemas.md Example of a LinkML schema serialized in YAML format. This format is human-readable and commonly used for defining schemas. ```yaml classes: Person: description: ... slots: - id - name - height - date_of_birth - occupation - knows slots: id: identifier: true range: string name: range: string date_of_birth: range: date height: range: float occupation: range: JobCode knows: range: Person multivalued: true enums: JobCode: permissible_values: ForkliftDriver: ...: types: date: ... ``` -------------------------------- ### Schema Example: Functional Syntax Source: https://github.com/linkml/linkml-model/blob/main/linkml_model/model/docs/specification/03schemas.md This snippet shows the basic structure of a LinkML schema defined using functional syntax. It includes common top-level elements like id, imports, prefixes, classes, slots, enums, and types. ```python SchemaDefinition( id=String^"http://example.org/organization", imports=[...], prefixes=[...], classes=[...], slots=[...], enums=[...], types=[...], ) ``` -------------------------------- ### Access LinkML Types Module Artifacts Source: https://context7.com/linkml/linkml-model/llms.txt Shows how to get the URL for the types.yaml artifact and the local file path for the types.py artifact from the LinkML types module. ```python print(types.yaml.url) # https://w3id.org/linkml/types.yaml ``` ```python print(types.python.file) # /path/to/linkml_model/types.py ``` -------------------------------- ### Python Functional Syntax for Schema Definition Source: https://github.com/linkml/linkml-model/blob/main/linkml_model/model/docs/specification/03schemas.md Example of a LinkML schema defined using Python functional syntax. This is a programmatic way to define schemas, useful for generation and manipulation. ```python SchemaDefinition( id=String^"http://example.org/organization", name=String^"organization", prefixes=[ Prefix(prefix_prefix=Ncname^"linkml" prefix_reference=Uri^"https://w3id.org/linkml/"), Prefix(prefix_prefix=Ncname^"org" prefix_reference=Uri^"http://example.org/organization/"), Prefix(prefix_prefix=Ncname^"schema" prefix_reference=Uri^"http://schema.org"), Prefix(prefix_prefix=Ncname^"wgs" prefix_reference=Uri^"http://www.w3.org/2003/01/geo/wgs84_pos#"), Prefix(prefix_prefix=Ncname^"qudt" prefix_reference=Uri^"http://qudt.org/1.1/schema/qudt#") ], default_prefix=String^"org", imports=[ Uriorcurie^"linkml:types" ], classes=[ ClassDefinition( name=String^"Person", slots=[ SlotDefinition&"id", SlotDefinition&"name", SlotDefinition&"height", SlotDefinition&"age", SlotDefinition&"knows", SlotDefinition&"job", ... ] ), ClassDefinition( name=String^"Organization", slots=[ SlotDefinition&"id", ... ] ), ... ], slots=[ SlotDefinition( name=SlotDefinition&"id", identifier=Boolean^True, description=String^"...", range=TypeDefinition&"String", ... ), SlotDefinition( name=SlotDefinition&"name", description=SlotDefinition&"...", ... ), SlotDefinition( name=String^"occupation", ... ), SlotDefinition( name=String^"date_of_birth", ... ), SlotDefinition( name=String^"knows", description=String^"...", range=ClassDefinition&"Person", multivalued=Boolean^True, ... ) ], enums=[ EnumDefinition( name=String^"JobCode", permissible_values=[...], ) ], types=[ TypeDefinition( name=String^"Date", ... ), TypeDefinition( name=String^"String", ... ), ] ) ``` -------------------------------- ### Get GitHub Raw URL for LinkML Model Artifacts Source: https://context7.com/linkml/linkml-model/llms.txt Demonstrates how to obtain raw GitHub URLs for specific git tags, the latest commit on a branch, or the latest published release of the LinkML model. ```python print(meta.rdf.github_loc(tag="v1.8.0")) # https://raw.githubusercontent.com/linkml/linkml-model//rdf/meta.ttl ``` ```python print(meta.python.github_loc(release=ReleaseTag.LATEST, branch="main")) # https://raw.githubusercontent.com/linkml/linkml-model/main/meta.py ``` ```python print(meta.jsonld.github_loc(release=ReleaseTag.CURRENT)) # https://raw.githubusercontent.com/linkml/linkml-model//jsonld/meta.context.jsonld ``` -------------------------------- ### Slot Metadata Annotation in LinkML Source: https://context7.com/linkml/linkml-model/llms.txt Demonstrates how to annotate a slot with various metadata fields including range, description, title, aliases, mappings, see_also, examples, status, created_by, keywords, and subset. ```yaml slots: disease: range: DiseaseClass description: The disease associated with this sample title: Disease aliases: - condition - pathology structured_aliases: - literal_form: Krankheit predicate: RELATED_SYNONYM # German exact_mappings: - schema:MedicalCondition - NCIT:C2991 close_mappings: - HP:0000118 see_also: - https://www.ncbi.nlm.nih.gov/mesh/D004194 examples: - value: MONDO:0004992 description: "cancer" status: linkml:ReleaseStatus#Released created_by: orcid:0000-0001-2345-6789 keywords: - biomedical - clinical in_subset: - SpecificationSubset ``` -------------------------------- ### Serve Documentation Locally Source: https://github.com/linkml/linkml-model/blob/main/CONTRIBUTING.md Use this command to serve the generated documentation locally for testing. This allows you to preview the documentation site before deployment. ```bash make serve ``` -------------------------------- ### Generate Documentation Source: https://github.com/linkml/linkml-model/blob/main/CONTRIBUTING.md Run this command to generate the documentation for the LinkML model. The output is staged in the target/docs directory. ```bash make gen-doc ``` -------------------------------- ### Browsing and Generating from LinkML Metamodel Schemas Source: https://context7.com/linkml/linkml-model/llms.txt Demonstrates commands for listing LinkML metamodel YAML source files, generating Python code, and generating JSON Schema from the metamodel. ```bash # Browse all YAML source schemas ls linkml_model/model/schema/ # annotations.yaml array.yaml datasets.yaml extended_types.yaml # extensions.yaml mappings.yaml meta.yaml types.yaml # units.yaml validation.yaml # Use linkml tools to generate Python from the YAML source gen-python linkml_model/model/schema/meta.yaml > meta.py # Generate JSON Schema from the metamodel gen-json-schema linkml_model/model/schema/meta.yaml > meta.schema.json # Validate a schema against the metamodel linkml-validate -s linkml_model/model/schema/meta.yaml my-schema.yaml ``` -------------------------------- ### Class Instance Structure (Mermaid) Source: https://github.com/linkml/linkml-model/blob/main/linkml_model/model/docs/specification/02instances.md Illustrates the composition of an InstanceOfClass, showing its relationship with the Assignment structure and the ClassDefinitionName. ```mermaid classDiagram Instance <|-- InstanceOfClass InstanceOfClass "1" --> "1..*" Assignment Assignment "1" --> Instance class InstanceOfClass { +ClassDefinitionName type +Assignment assignments } class Assignment { +SlotDefinitionName slot +Instance value } ``` -------------------------------- ### Generate URLs and Paths for LinkML Sources Source: https://context7.com/linkml/linkml-model/llms.txt Demonstrates using standalone functions to generate URLs for LinkML sources in different formats, such as OWL or RDF, and local paths for JSON schema artifacts. ```python print(URL_FOR(Source.META, Format.OWL)) # https://w3id.org/linkml/meta.owl.ttl ``` ```python print(LOCAL_PATH_FOR(Source.ANNOTATIONS, Format.JSON_SCHEMA)) # /path/to/linkml_model/jsonschema/annotations.schema.json ``` ```python print(GITHUB_IO_PATH_FOR(Source.MAPPINGS, Format.RDF)) # https://linkml.github.io/linkml-model/rdf/mappings.ttl ``` -------------------------------- ### Instance Structure (Mermaid) Source: https://github.com/linkml/linkml-model/blob/main/linkml_model/model/docs/specification/02instances.md Visualizes the hierarchical relationship between different types of LinkML instances, including classes, atomic instances, and collections. ```mermaid classDiagram Instance <|-- InstanceOfClass Instance <|-- AtomicInstance AtomicInstance <|-- InstanceOfReference AtomicInstance <|-- InstanceOfType AtomicInstance <|-- InstanceOfEnum Instance <|-- CollectionInstance Instance <-- None ``` -------------------------------- ### Python Example for DesignatedType Check Source: https://github.com/linkml/linkml-model/blob/main/linkml_model/model/docs/specification/05validation.md Illustrates a scenario where a DesignatedType check passes due to the value being present in the normalized set of permissible types for a string range. ```python ClassDefinition( name="Business", is_a=ClassDefinition&Organization, ) ClassDefinition( name="Organization", attributes=[ SlotDefinition(name="type", range=TypeDefinition&string), ... ``` ``` -------------------------------- ### Listing LinkML Metamodel YAML Source Files Source: https://context7.com/linkml/linkml-model/llms.txt Provides a list of the YAML files that constitute the LinkML metamodel, organized by module. ```text | File | Content | |---|---| | `meta.yaml` | Core metamodel: `SchemaDefinition`, `ClassDefinition`, `SlotDefinition`, `TypeDefinition`, `EnumDefinition`, all expressions, rules | | `types.yaml` | Built-in LinkML scalar types (`string`, `integer`, `float`, `boolean`, `uri`, `uriorcurie`, `date`, `datetime`, etc.) | | `mappings.yaml` | Mapping slots (`exact_mappings`, `close_mappings`, `narrow_mappings`, `broad_mappings`, `related_mappings`, deprecation replacements) | | `annotations.yaml` | `Annotatable` mixin and `Annotation` class (OWL annotation semantics) | | `extensions.yaml` | `Extensible` mixin and `Extension` class (arbitrary tag/value metadata) | | `units.yaml` | `UnitOfMeasure` class for attaching units to slot values | | `array.yaml` | `ArrayExpression` and `DimensionExpression` for array/tensor constraints | | `datasets.yaml` | `DataPackage`, `DataSet` for describing collections of data | | `validation.yaml` | `ValidationReport`, `ValidationResult` for capturing validation output | ``` -------------------------------- ### Creating and Printing LinkML Extensions in Python Source: https://context7.com/linkml/linkml-model/llms.txt Demonstrates how to create `Extension` and `Annotation` objects in Python. Extensions are tag/value pairs for non-model information, while Annotations are OWL-style with CURIE tags. ```python from linkml_model import Extension, Extensible, Annotation, Annotatable from linkml_model.extensions import ExtensionTag # Create an extension with a URI tag and arbitrary value ext = Extension( tag="https://example.org/my-extension", value={"some_key": "some_value"}, ) print(ext.tag) # https://example.org/my-extension print(ext.value) # {'some_key': 'some_value'} # Annotation (OWL-style): tag is a CURIE, value can be nested ann = Annotation( tag="skos:note", value="This is a note about this element", ) print(ann.tag) # skos:note ``` -------------------------------- ### Using Annotations and Extensions in YAML Schema Source: https://context7.com/linkml/linkml-model/llms.txt Shows how to attach custom metadata to schema elements using `annotations` (for OWL-style notes) and `extensions` (for arbitrary key-value data) directly in a YAML schema. ```yaml # Using annotations in a YAML schema element slots: my_slot: range: string annotations: skos:note: "This slot has a SKOS note attached as an OWL annotation" extensions: https://myns.org/custom-ext: value: arbitrary_metadata ``` -------------------------------- ### Using LinkML Built-in Enumerations Source: https://context7.com/linkml/linkml-model/llms.txt Illustrates how to use LinkML's built-in enumerations such as PvFormulaOptions and AliasPredicateEnum for controlling metamodel semantics and defining structured aliases. ```python from linkml_model.meta import ( PvFormulaOptions, PresenceEnum, RelationalRoleEnum, AliasPredicateEnum, ObligationLevelEnum, ) # PvFormulaOptions: how enum codes are populated from an external code set print(list(PvFormulaOptions)) # [PvFormulaOptions.CODE, .CURIE, .URI, .FHIR_CODING] ``` ```python from linkml_model import EnumDefinition my_enum = EnumDefinition( name="SerumCholesterol", code_set="http://hl7.org/fhir/ValueSet/serum-cholesterol", code_set_version="1.0.0", pv_formula=PvFormulaOptions.CODE, ) print(my_enum.pv_formula) # PvFormulaOptions.CODE ``` ```python from linkml_model.meta import StructuredAlias alias = StructuredAlias( literal_form="homo sapiens", predicate=AliasPredicateEnum.EXACT_SYNONYM, ) print(alias.predicate) # AliasPredicateEnum.EXACT_SYNONYM ``` -------------------------------- ### Element URI and Model URI Mapping Source: https://github.com/linkml/linkml-model/blob/main/linkml_model/model/docs/specification/04derived-schemas.md Illustrates the mapping rules for generating Element URIs and Model URIs for different LinkML definition types. ```python : ``` ```python : ``` ```python ModelURI(Enum) + "." + Safe(e.text) ``` -------------------------------- ### Build ClassDefinition Programmatically in Python Source: https://context7.com/linkml/linkml-model/llms.txt Programmatically construct a ClassDefinition for 'Person' and add it to a SchemaDefinition. Demonstrates basic class creation and schema population. ```python from linkml_model import ClassDefinition, SlotDefinition, SchemaDefinition # Build programmatically person_cls = ClassDefinition( name="Person", description="A person", is_a="NamedThing", slots=["id", "name", "age"], ) schema = SchemaDefinition( id="https://example.org/s", name="s", classes={"Person": person_cls}, ) print(person_cls.name) # Person print(person_cls.is_a) # NamedThing print(list(schema.classes)) # ['Person'] ``` -------------------------------- ### Python Configuration for Rewrite Rule Testing Source: https://github.com/linkml/linkml-model/blob/main/tests/test_rewrite_rules/httpd/README.md Uncomment and modify these lines in test_rewrite_rules.py to enable testing. Adjust the server port if it differs from the default. ```python # DEFAULT_SERVER = "http://localhost:8091/" # SKIP_REWRITE_RULES = False ``` -------------------------------- ### Construct Minimal Schema Definition in Python Source: https://context7.com/linkml/linkml-model/llms.txt Use SchemaDefinition to create a basic LinkML schema programmatically. Inspect required fields like name, id, and default_range. ```python from linkml_model import SchemaDefinition, ClassDefinition, SlotDefinition # Construct a minimal schema in Python schema = SchemaDefinition( id="https://example.org/my-schema", name="my-schema", description="A minimal person schema", license="https://creativecommons.org/publicdomain/zero/1.0/", version="1.0.0", default_prefix="ex", default_range="string", ) # Inspect required fields assert schema.name == "my-schema" assert str(schema.id) == "https://example.org/my-schema" assert schema.default_range == "string" print(schema.name) # my-schema print(schema.version) # 1.0.0 ``` -------------------------------- ### Tagging Slots with LinkML Schema Subsets Source: https://context7.com/linkml/linkml-model/llms.txt Shows how to assign a slot to specific LinkML schema subsets using the 'in_subset' attribute in a SlotDefinition. ```python from linkml_model import SchemaDefinition, SlotDefinition # Tag a slot as belonging to specific subsets slot = SlotDefinition( name="id", identifier=True, required=True, in_subset=["MinimalSubset", "BasicSubset", "SpecificationSubset"], ) print(slot.in_subset) # ['MinimalSubset', 'BasicSubset', 'SpecificationSubset'] ``` -------------------------------- ### Atomic Instance Structure (Mermaid) Source: https://github.com/linkml/linkml-model/blob/main/linkml_model/model/docs/specification/02instances.md Depicts the relationships between AtomicInstance and its subtypes (InstanceOfReference, InstanceOfType, InstanceOfEnum), along with their associated value and type definitions. ```mermaid classDiagram Instance <|-- AtomicInstance AtomicInstance <|-- InstanceOfReference AtomicInstance <|-- InstanceOfType AtomicInstance <|-- InstanceOfEnum class Instance { } class AtomicInstance { +AtomicValue value } class InstanceOfReference { +ClassDefinitionName type } class InstanceOfType { +TypeDefinitionName type } class InstanceOfEnum { +EnumDefinitionName type } ``` -------------------------------- ### ClassDefinition Instance Identity Logic Source: https://github.com/linkml/linkml-model/blob/main/linkml_model/model/docs/specification/02instances.md Compares two ClassDefinition instances based on class name and matching slot assignments. Assignments with a 'None' value are ignored before comparison. ```pseudocode if i == () and j == () and all(a_i in Assignments_i if any(a_j in Assignments_j if a_i == a_j)) and all(a_j in Assignments_j if any(a_i in Assignments_i if a_i == a_j)) then i == j ``` -------------------------------- ### Mermaid UML Diagram for TypeDefinition Source: https://github.com/linkml/linkml-model/blob/main/linkml_model/model/docs/specification/03schemas.md This diagram illustrates the relationships between TypeDefinition, TypeExpression, and AnonymousTypeExpression in LinkML, showing inheritance and association for various type expression operators. ```mermaid classDiagram class TypeExpression { +TypeDefinitionName range } TypeExpression "*" --> AnonymousTypeExpression: any_of TypeExpression "*" --> AnonymousTypeExpression: exactly_one_of TypeExpression "*" --> AnonymousTypeExpression: none_of TypeExpression "*" --> AnonymousTypeExpression: all_of AnonymousTypeExpression --|> TypeExpression TypeDefinition --|> TypeExpression class TypeDefinition { +TypeDefinitionName name +TypeDefinitionName typeof +TypeDefinitionName[] mixins +Uri uri +String base +String repr } TypeDefinition --|> TypeExpression: mixin TypeDefinition --|> Element: is_a ``` -------------------------------- ### SlotDefinition UML Diagram Source: https://github.com/linkml/linkml-model/blob/main/linkml_model/model/docs/specification/03schemas.md A UML diagram illustrating the structure and relationships of SlotDefinition and related classes within LinkML. ```mermaid classDiagram class SlotExpression { +SlotDefinitionName range } SlotExpression "1" --> "*" AnonymousSlotExpression: any_of SlotExpression "1" --> "*" AnonymousSlotExpression: exactly_one_of SlotExpression "1" --> "*" AnonymousSlotExpression: none_of SlotExpression "1" --> "*" AnonymousSlotExpression: all_of class SlotDefinition { +SlotDefinitionName name +boolean identifier +boolean key +boolean abstract +boolean mixin +boolean designates_type +SlotDefinitionName is_a +SlotDefinitionName[] mixins +ClassDefinitionName range +Decimal minimum_value +Decimal maximum_value +String equals_expression +String pattern +String string_serialization +boolean symmetric +boolean asymmetric +boolean reflexive +boolean irreflexive +boolean locally_reflexive +boolean transitive +SlotDefinition transitive_form_of +SlotDefinition reflexive_transitive_form_of +SlotDefinition inverse } SlotDefinition --|> SlotExpression: mixin SlotDefinition --|> Element: is_a SlotDefinition "0..1" --> SlotDefinition: is_a SlotDefinition "*" --> SlotDefinition: mixins ``` -------------------------------- ### Mermaid Class Diagram for Person Source: https://github.com/linkml/linkml-model/blob/main/linkml_model/model/docs/specification/03schemas.md Visual representation of the Person class and its relationships using Mermaid syntax. Useful for understanding schema structure. ```mermaid classDiagram Person "0" --> "*" Person: knows class Person { +String id +String name +Float height +Date date_of_birth +JobCode occupation } ``` -------------------------------- ### LinkML Validation Procedure Pseudocode Source: https://github.com/linkml/linkml-model/blob/main/linkml_model/model/docs/specification/05validation.md This pseudocode outlines the core logic for validating an instance 'i' against a schema 'm' for a target type 't'. It involves deriving the schema, defining a slot for the target type, and iterating through checks. ```pseudocode Validate(i, m, t): mD = DeriveSchema(m) s = new SlotDefinition(range=t) for check in Checks: if (s,i) matches check: yield check if i == (a1, ..., an): for s' = i' in a1, ..., an: Validate(i', mD, DerivedSlot(s', )) ``` -------------------------------- ### Core Schema Definition (YAML) Source: https://github.com/linkml/linkml-model/blob/main/linkml_model/model/docs/specification/04derived-schemas.md Defines a 'NamedThing' class with id and name attributes, used as a base for other schema elements. ```yaml id: https://w3id.org/linkml/examples/core name: person-core prefixes: person: https://w3id.org/linkml/examples/person linkml: https://w3id.org/linkml/ default_prefix: person imports: - linkml:types classes: NamedThing: attributes: id: range: string identifier: true name: range: string ... ``` -------------------------------- ### Mermaid Diagram: ClassDefinition Source: https://github.com/linkml/linkml-model/blob/main/linkml_model/model/docs/specification/03schemas.md Visual representation of the ClassDefinition hierarchy and relationships within the LinkML metamodel. ```mermaid classDiagram ClassExpression "1" --> "*" AnonymousClassExpression: any_of ClassExpression "1" --> "*" AnonymousClassExpression: exactly_one_of ClassExpression "1" --> "*" AnonymousClassExpression: none_of ClassExpression "1" --> "*" AnonymousClassExpression: all_of ClassDefinition --|> ClassExpression: mixin ClassDefinition --|> Element: is_a AnonymousClassExpression --|> ClassExpression class ClassDefinition { +ClassDefinitionName name +boolean abstract +boolean mixin } ClassDefinition "*" --> "*" SlotDefinition: slots ClassDefinition "1" --> "*" SlotDefinition: slot_usage ClassDefinition "1" --> "*" SlotDefinition: attributes ClassDefinition "*"--> "0..1" ClassDefinition: is_a ClassDefinition "1" --> "*" ClassDefinition: mixins ClassDefinition "1" --> "*" AnonymousClassExpression: classification_rules ClassDefinition "1" --> "*" ClassRule: rules ```