Skip to content

graflo.architecture.evolution.aspects.members

Which parts of a schema an aspect added: its own types, its relations, and the types it was lifted onto.

Derived from the schema, not recorded on it. Each relation an aspect lifts has a fixed shape -- a relation name, its two ends, and the IRI it is grounded in -- built by the aspect's vocabulary. A relation counts as the aspect's when it has exactly the shape the vocabulary would build for its ends, and a type when the vocabulary builds it (SourceRecord, Agent) or names it after a type it specialises (<Type>State, <Type>Observation). The IRI alone is not enough: a domain type or relation may be grounded in a PROV term too.

Only aspects that add types and relations have members. access and sync add reserved fields, which a caller reads from the fields themselves.

Attributes

__all__ = ['AspectEdge', 'AspectMembers', 'aspect_members'] module-attribute

Classes

AspectEdge

Bases: ConfigBaseModel

One relation an aspect lifted, by its ends and name.

Source code in graflo/architecture/evolution/aspects/members.py
class AspectEdge(ConfigBaseModel):
    """One relation an aspect lifted, by its ends and name."""

    source: str
    relation: str
    target: str
    aspect: str

Attributes

aspect instance-attribute
relation instance-attribute
source instance-attribute
target instance-attribute

AspectMembers

Bases: ConfigBaseModel

What a schema owes to its aspects.

Attributes:

Name Type Description
types dict[str, str]

Each type an aspect defines, and that aspect.

edges list[AspectEdge]

Each relation an aspect lifted.

lifted_onto dict[str, list[str]]

Each other type an aspect was lifted onto, and those aspects in name order.

Source code in graflo/architecture/evolution/aspects/members.py
class AspectMembers(ConfigBaseModel):
    """What a schema owes to its aspects.

    Attributes:
        types: Each type an aspect defines, and that aspect.
        edges: Each relation an aspect lifted.
        lifted_onto: Each other type an aspect was lifted onto, and those
            aspects in name order.
    """

    types: dict[str, str] = PydanticField(default_factory=dict)
    edges: list[AspectEdge] = PydanticField(default_factory=list)
    lifted_onto: dict[str, list[str]] = PydanticField(default_factory=dict)

Attributes

edges = PydanticField(default_factory=list) class-attribute instance-attribute
lifted_onto = PydanticField(default_factory=dict) class-attribute instance-attribute
types = PydanticField(default_factory=dict) class-attribute instance-attribute

Functions:

aspect_members(schema)

The types and relations schema owes to the provenance and state aspects.

Parameters:

Name Type Description Default
schema Schema

A schema, lifted or not.

required

Returns:

Type Description
AspectMembers

The aspects' own types, the relations they lifted, and the other types

AspectMembers

each was lifted onto. All empty for a schema no aspect was lifted onto.

Source code in graflo/architecture/evolution/aspects/members.py
def aspect_members(schema: Schema) -> AspectMembers:
    """The types and relations *schema* owes to the provenance and state aspects.

    Args:
        schema: A schema, lifted or not.

    Returns:
        The aspects' own types, the relations they lifted, and the other types
        each was lifted onto. All empty for a schema no aspect was lifted onto.
    """
    core = schema.core_schema
    vertices = {v.name: v for v in core.vertex_config.vertices}
    types: dict[str, str] = {}
    for built in (source_record_vertex(), agent_vertex(), assertion_vertex()):
        found = vertices.get(built.name)
        if found is not None and _iri(found) == _iri(built):
            types[built.name] = PROVENANCE

    edges: list[AspectEdge] = []
    onto: dict[str, set[str]] = {}
    for edge in core.edge_config.edges:
        lifted = _lifted(edge)
        if lifted is None or edge.relation is None:
            continue
        aspect, own, domain = lifted
        edges.append(
            AspectEdge(
                source=edge.source,
                relation=edge.relation,
                target=edge.target,
                aspect=aspect,
            )
        )
        if own is not None and own in vertices:
            types.setdefault(own, aspect)
        if aspect == PROVENANCE and AGENT in vertices and edge.target == AGENT:
            types.setdefault(AGENT, aspect)
        if domain is not None and types.get(domain) != aspect:
            onto.setdefault(domain, set()).add(aspect)
    return AspectMembers(
        types=types,
        edges=edges,
        lifted_onto={name: sorted(aspects) for name, aspects in sorted(onto.items())},
    )