Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Model: the entity classes

The model is the set of Python classes in lode.models that describe what LODE finds in a document. The reader creates them, the artefact holds them and the viewer reads them. They are plain Python: no RDF parsing and no rendering.

Every class follows the same rules: one setter and one getter per field, multi-valued fields are lists, and the inverse of a link is set for you. This notebook inspects the classes and shows each rule on a small ontology.

Methods to inspect the model

MethodWhat it gives
lode.models.__all__The names of the classes of the model.
cls.__subclasses__()The children of a class: the hierarchy.
inspect.getdoc(cls)What a class is, from its docstring.
vars(cls())The fields of a class, with their empty values.
entity.get_<field>()The getter of a field.
dir(cls)The setters of a class (set_<field>), which the mapper names.
repr(entity)The class and the identifier of an entity.

Examples

One for each way of the table.

lode.models.__all__

25 classes
['Resource', 'Property', 'Relation', 'Annotation', 'Attribute', 'Literal', 'Concept', 'Datatype', 'Restriction', 'TruthFunction', 'OneOf', 'PropertyConceptRestriction', 'Value', 'Quantifier', 'Cardinality', 'Model', 'Individual', 'Statement', 'Container', 'Collection', 'DatatypeRestriction', 'Variable', 'Atom', 'Rule', 'PropertySelfRestriction']

cls.__subclasses__() and inspect.getdoc(cls)

Almost everything extends Resource. Literal does not: it is a value, not a resource. The tree is built from the classes, so it cannot go out of date.

Resource                       An RDF resource, with its annotations (labels, notes, ...) and links to other resources.
  Property                     Represents an RDF Property
    Relation                   Represents an RDF Object Property
    Annotation                 An annotation property: it carries documentation, not logical meaning.
    Attribute                  A datatype property: it relates a resource to literals.
  Concept                      An OWL class or a SKOS concept.
    Datatype                   A datatype: the kind of value a literal can have.
    Restriction                Base of the anonymous classes built by restrictions and logical operators.
      TruthFunction            A class expression combining concepts with a logical operator (and, or, not).
      OneOf                    A class defined by listing its members (owl:oneOf).
      PropertyConceptRestriction Base of the restrictions that apply a property to a concept (quantifiers, cardinalities).
        Quantifier             A quantified restriction of a property on a concept.
        Cardinality            A restriction on how many values a property can take on a concept.
      Value                    A restriction requiring a property to take one specific resource as value (owl:hasValue).
      DatatypeRestriction      A datatype narrowed by XSD facet/value pairs, such as numeric bounds.
      PropertySelfRestriction  A restriction on the individuals related to themselves by a property (owl:hasSelf).
  Model                        An ontology or vocabulary: versioning, compatibility, imports and namespaces.
  Individual                   Represents an individual instance of a class (owl:NamedIndividual).
  Statement                    An RDF triple (subject, predicate, object) described as a resource, so it can be documented.
  Container                    RDF Container (Bag, Seq, Alt, List)
  Collection                   A SKOS collection: a labelled group of concepts or other collections.
  Variable                     A SWRL variable, used as an argument of an atom.
  Atom                         A SWRL atom: a predicate applied to a list of arguments.
  Rule                         A SWRL rule: when every antecedent atom holds, the consequent atoms hold.

Literal is a Resource: False

vars(cls())

The fields of a class. Cardinalities are written as comments next to each field in the class.

36 fields
['has_identifier', 'is_deprecated', 'has_comment', 'has_label', 'has_preferred_label', 'has_alternative_label', 'has_hidden_label', 'has_notation', 'has_note', 'has_change_note', 'has_definition', 'has_editorial_note', 'has_example', 'has_history_note', 'has_scope_note', 'see_also', 'is_defined_by', 'has_version_info', 'also_defined_as', 'has_type', 'is_included_in', 'is_in_range_of', 'is_sub_concept_of', 'is_super_concept_of', 'is_disjoint_with', 'is_equivalent_to', 'is_related_to', 'has_broad_match', 'has_narrow_match', 'has_related_match', 'has_exact_match', 'has_close_match', 'is_top_concept_of', 'has_key', 'individuals_with_this_type', 'is_in_domain_of']

entity.get_<field>()

The entities below come from a small ontology. A getter returns a copy of a list, so callers cannot alter the model by accident.

['Cat']
[Concept('http://example.org/zoo#Animal')]

The setters, with dir(cls)

The reader fills the model only through the setters, named in the YAML mapper. Setting a link also sets its inverse:

36 setters, for example ['set_also_defined_as', 'set_has_alternative_label', 'set_has_broad_match']
[Concept('http://example.org/zoo#Cat')]

repr(entity)

The class and the identifier, never the relations, which would recurse.

Concept('http://example.org/zoo#Cat')

How LODE uses it

The reader creates the entities as instances of these classes and stores them in the artefact. The viewer reads them to build what the templates render.

Writing your own model classes

This page only inspects the classes that ship with LODE. A profile that needs its own can name them in its reader.yaml as module:Name, with their setters and getters. To write it, go to Extending LODE, the mapper.