graflo.architecture.schema.hierarchy¶
Class and relation hierarchies: what subclass_of and subproperty_of entail.
Vertex.subclass_of asserts rdfs:subClassOf and Edge.subproperty_of
asserts rdfs:subPropertyOf. Both are logical assertions, not descriptions:
this module checks that a schema's hierarchy is consistent and answers what it
entails. Nothing is inherited — a subclass gets no property, identity or storage
from its parent — and nothing at ingestion or query time reads either list.
Consistency (:func:check_hierarchy, run by CoreSchema.finish_init):
- a local parent is declared, is not the element itself, and the local hierarchy is acyclic;
- an edge's endpoints are subsumed by its parent edge's endpoints, in either orientation when the parent is undirected, since a subproperty relates only pairs its parent relates;
- an undirected edge has an undirected parent, for the same reason.
:func:check_hierarchy_iris (run by Schema.finish_init, which holds the
metadata) refuses a local element named by IRI — one fact must have one form —
and an IRI written with a declared namespace prefix as its scheme.
Attributes¶
K = TypeVar('K', bound=Hashable)
module-attribute
¶
__all__ = ['Hierarchy', 'NewSubsumptions', 'check_hierarchy', 'check_hierarchy_iris', 'localize_refs', 'new_subsumptions', 'rewrite_edge_refs', 'rewrite_vertex_refs', 'spliced_superclasses', 'spliced_superproperties', 'vertex_iri']
module-attribute
¶
Classes¶
Hierarchy
¶
What a schema's subclass_of and subproperty_of entail.
A read-only view, built once over the vertices and edges it is given; it
assumes they passed :func:check_hierarchy. Subsumption is reflexive and
transitive. External parents (IRIs) are reached through the local chain: a
vertex under a local parent that is under foaf:Agent is under it too.
Source code in graflo/architecture/schema/hierarchy.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
Methods:¶
__init__(vertices, edges)
¶
Source code in graflo/architecture/schema/hierarchy.py
external_superclasses(name)
¶
IRIs of the external classes name is entailed to be a subclass of.
Source code in graflo/architecture/schema/hierarchy.py
external_superproperties(edge_id)
¶
IRIs of the external properties edge_id is entailed to be under.
Source code in graflo/architecture/schema/hierarchy.py
is_subclass(child, parent)
¶
Whether child ⊑ parent; every vertex is a subclass of itself.
is_subproperty(child, parent)
¶
Whether child ⊑ parent; every edge is a subproperty of itself.
of(core)
classmethod
¶
subclass_pairs()
¶
Every entailed (child, parent) pair between two local vertices.
subclasses(name, *, transitive=True)
¶
Local subclasses of vertex name, nearest first.
Source code in graflo/architecture/schema/hierarchy.py
subproperties(edge_id, *, transitive=True)
¶
Local subproperties of edge edge_id, nearest first.
Source code in graflo/architecture/schema/hierarchy.py
subproperty_pairs()
¶
Every entailed (child, parent) pair between two local edges.
superclasses(name, *, transitive=True)
¶
Local superclasses of vertex name, nearest first.
Source code in graflo/architecture/schema/hierarchy.py
superproperties(edge_id, *, transitive=True)
¶
Local superproperties of edge edge_id, nearest first.
Source code in graflo/architecture/schema/hierarchy.py
NewSubsumptions
¶
Bases: ConfigBaseModel
Subsumptions a candidate schema entails between elements of a base that the base does not.
Source code in graflo/architecture/schema/hierarchy.py
Functions:¶
check_hierarchy(vertex_config, edge_config)
¶
Refuse an inconsistent class or relation hierarchy.
Raises:
| Type | Description |
|---|---|
ValueError
|
An undeclared or self parent, a cycle, an edge whose endpoints its parent does not subsume, or an undirected edge under a directed one. |
Source code in graflo/architecture/schema/hierarchy.py
check_hierarchy_iris(metadata, core)
¶
Refuse a local parent named by IRI, and an IRI written with a declared prefix.
Raises:
| Type | Description |
|---|---|
ValueError
|
An |
Source code in graflo/architecture/schema/hierarchy.py
localize_refs(metadata, vertices, edges)
¶
vertices and edges, each {iri} parent that denotes one of them made local.
For a fold of two schemas, where a parent one side named by IRI now lives in
the result. A changed model is a copy. :func:check_hierarchy_iris refuses
what this rewrites.
Source code in graflo/architecture/schema/hierarchy.py
new_subsumptions(base, candidate)
¶
What candidate entails between base's own elements that base does not.
The conservativity check: a change that adds a narrower concept is conservative; one that makes two existing concepts subsume each other, or one subsume another, is not, whatever it was meant to add.
Source code in graflo/architecture/schema/hierarchy.py
rewrite_edge_refs(edges, *, vertex_map=None, edge_map=None)
¶
edges, each local superproperty following renamed and merged elements.
edge_map maps old edge ids to new ones; an id it does not name follows vertex_map on its endpoints. A reference that now names its own edge, or repeats another, is dropped. A changed edge is a copy; the rest are the given models.
Source code in graflo/architecture/schema/hierarchy.py
rewrite_vertex_refs(vertices, vertex_map)
¶
vertices, each local superclass following vertex_map (old → new name).
A superclass that now names its own vertex — two vertices folded into one — is dropped, as is a duplicate. A changed vertex is a copy; the rest are the given models.
Source code in graflo/architecture/schema/hierarchy.py
spliced_superclasses(vertices, removed)
¶
New subclass_of for each surviving vertex that names a removed one.
A removed class is spliced out of the hierarchy: its subclasses take over its parents, local and external, so every subsumption between the survivors still holds. The result does not depend on the order in which classes are removed.
Source code in graflo/architecture/schema/hierarchy.py
spliced_superproperties(edges, removed)
¶
New subproperty_of for each surviving edge that names a removed one.
The edge counterpart of :func:spliced_superclasses. Endpoint subsumption
and directedness hold for the spliced parents by transitivity.
Source code in graflo/architecture/schema/hierarchy.py
vertex_iri(metadata, vertex)
¶
The IRI a vertex type denotes: its semantics.iri, else the one the schema mints.
A schema mints {base_iri}{name}; without a base_iri an ungrounded
vertex has no IRI.