ontocast.onto.identity¶
Ontology identity as types: the id, the IRI, and the pair.
An ontology's identity is minted by code, never written by a model: the model
proposes an ontology_id (and a title and description), and the IRI is
<CURRENT_DOMAIN>/<ontology_id>. Everything that would let two spellings of
one ontology coexist -- a fragment on the IRI, a standard prefix bound to
anything but its standard namespace, an id that collides with the document or
facts namespaces -- is refused here, at construction; an empty fragment is
dropped.
An id is also the prefix an ontology's terms are shown under, so a standard
prefix is a binding, not a name: sosa may name the ontology whose namespace
is http://www.w3.org/ns/sosa/ (W3C SOSA, adopted from its file) and
nothing else, and never an ontology minted here.
Attributes¶
LIBRARY_ONTOLOGY_IDS = frozenset({'cd', 'doc', 'facts', 'oc', 'ontocast'})
module-attribute
¶
MintedOntologyId = Annotated[str, AfterValidator(validate_minted_ontology_id)]
module-attribute
¶
ONTOLOGY_ID_PATTERN = re.compile('^[a-z][a-z0-9_-]{1,31}$')
module-attribute
¶
OntologyId = Annotated[str, AfterValidator(validate_ontology_id)]
module-attribute
¶
OntologyIri = Annotated[str, AfterValidator(validate_ontology_iri)]
module-attribute
¶
STANDARD_PREFIX_NAMESPACES = _standard_prefix_namespaces()
module-attribute
¶
Classes¶
OntologyIdentity
¶
Bases: BaseModel
What names an ontology: its id, its IRI, and how it describes itself.
namespace is where its terms live: an existing ontology's own, else
<iri>#, where a new ontology's terms are minted.
Source code in ontocast/onto/identity.py
Attributes¶
description = Field(default='', max_length=2000)
class-attribute
instance-attribute
¶
iri
instance-attribute
¶
model_config = ConfigDict(frozen=True)
class-attribute
instance-attribute
¶
namespace = Field(default='')
class-attribute
instance-attribute
¶
ontology_id
instance-attribute
¶
title = Field(min_length=1, max_length=200)
class-attribute
instance-attribute
¶
OntologyVersionRecord
¶
Bases: VersionRef
A version a run wrote: created as a root, or updated from its priors.
Source code in ontocast/onto/identity.py
VersionRef
¶
Bases: BaseModel
One stored version of one ontology.
Source code in ontocast/onto/identity.py
Functions:¶
check_prefix_binding(ontology_id, namespace)
¶
Refuse a standard prefix as the id of an ontology outside its namespace.
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Source code in ontocast/onto/identity.py
mint_ontology_iri(current_domain, ontology_id)
¶
The IRI of the ontology ontology_id under current_domain.
Source code in ontocast/onto/identity.py
split_version_iri(version_iri)
¶
(ontology IRI, version key) of a version IRI.
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Source code in ontocast/onto/identity.py
validate_current_domain(value)
¶
The IRI stem ontology and document IRIs are minted under.
Source code in ontocast/onto/identity.py
validate_minted_ontology_id(value)
¶
An id for an ontology minted under CURRENT_DOMAIN: no standard prefix.
A minted ontology's namespace is never a standard one, so a standard prefix would show its terms under a prefix that already means something else.
Source code in ontocast/onto/identity.py
validate_ontology_id(value)
¶
Return value as an ontology id, or raise ValueError.
Only whitespace is stripped and case folded; any other repair would let two
proposals that differ in spelling land on one id. A standard prefix passes
here: whether it may name an ontology depends on the ontology's namespace
(:func:check_prefix_binding).
Source code in ontocast/onto/identity.py
validate_ontology_iri(value)
¶
Return value as a canonical ontology IRI, or raise ValueError.
An absolute http(s) IRI with no fragment: the version graph of each
version is <iri>#<key>, so the IRI itself cannot carry a #. An
empty fragment (…/prov#, common in published vocabularies) names the
same document and is dropped; any other fragment is refused.