axiom.structural_element ======================== .. py:module:: axiom.structural_element .. autoapi-nested-parse:: OWL 2 structural element bases, RDF list fragments, and declaration helpers. Classes ------- .. autoapisummary:: axiom.structural_element.GraphBacked axiom.structural_element.StructuralFragment axiom.structural_element.StructuralElement axiom.structural_element.SeqEntry axiom.structural_element.Seq axiom.structural_element.DeclarationElement Module Contents --------------- .. py:class:: GraphBacked(/, **data: Any) Bases: :py:obj:`pydantic.BaseModel`, :py:obj:`abc.ABC` Universal base for graph-scoped Pydantic models in this package. Each instance MUST have a single required ``context`` (graph identifier). Cross-context structure MUST be expressed only at the triple or quad level, not by composing models defined in another context. Three roles partition models in this hierarchy (DR-031; see package ``AGENTS.md``): - ``StructuralElement`` axiom heads. One OWL 2 structural element per partition. Cross-axiom references MUST use RDF node-level types only; axiom heads MUST NOT compose other ``StructuralElement`` instances. - ``StructuralFragment`` owned scaffolding. May be embedded as a Pydantic field on a single owning ``StructuralElement``; its ``as_triples`` contributes to the owner's partition; MUST share the owner's ``context``. - Node references via package-defined annotated aliases (``N3Resource``, ``N3IRIRef``, ``N3Node``, ``N3ContextIdentifier``). Used for cross-axiom links by identity. Models MUST NOT embed rdflib.Graph, ConjunctiveGraph, SPARQL result objects, or other container/session/handle types. Schema-facing fields MUST use the annotated RDF aliases above rather than raw rdflib node classes; raw rdflib node classes MAY still be used in internal non-schema logic. .. py:attribute:: context :type: axiom.common.ContextIdentifier :value: None .. py:attribute:: model_config Configuration for the model, should be a dictionary conforming to [`ConfigDict`][pydantic.config.ConfigDict]. .. py:class:: StructuralFragment(/, **data: Any) Bases: :py:obj:`GraphBacked`, :py:obj:`abc.ABC` Owned scaffolding for a single ``StructuralElement`` (DR-031). A fragment models a graph fragment that is co-essential to one OWL axiom's RDF mapping (for example an ``rdf:List`` carrying ``owl:intersectionOf`` members). Fragments MAY be embedded as Pydantic fields on a single owning ``StructuralElement``; their ``as_triples`` belong to the owner's partition. A fragment MUST share its owner's ``context``; ``StructuralElement`` enforces this via a centralized validator. Fragments are not partition units on their own and are not OWL axioms. .. py:property:: as_triples :type: collections.abc.Sequence[axiom.common.Triple] :abstractmethod: Triples for this fragment; flow into the owning element's partition. .. py:property:: as_quads :type: collections.abc.Sequence[axiom.common.Quad] each triple from ``as_triples`` with ``context``. :type: Quads for this fragment .. py:class:: StructuralElement(/, **data: Any) Bases: :py:obj:`GraphBacked`, :py:obj:`abc.ABC` Universal base for OWL 2 structural elements (axiom heads; DR-031). Concrete class names SHOULD match the paired structural element's name (e.g. ``NegativeDataPropertyAssertion``). Each concrete subclass MUST correspond to a well-identified OWL 2 structural element; ``as_triples`` (and ``as_quads``) MUST conform to ``owl2-mapping-to-rdf`` and transitive specs. ``as_triples`` MUST NOT recurse into other axiom heads. Owned scaffolding expressed as ``StructuralFragment`` fields contributes triples to this element's partition and MUST share this element's ``context`` (enforced). Cross-axiom references MUST use RDF node-level types only. .. py:property:: name :type: rdflib.IdentifiedNode :abstractmethod: type triple. :type: Canonical identifier for this element; SHOULD be the subject of a rdf .. py:property:: as_triples :type: collections.abc.Sequence[axiom.common.Triple] :abstractmethod: Triples representing this element as RDF; MUST NOT recurse into other axiom heads. .. py:property:: as_quads :type: collections.abc.Sequence[axiom.common.Quad] each triple from as_triples with context as fourth element. :type: Quads for this element .. py:class:: SeqEntry(/, **data: Any) Bases: :py:obj:`pydantic.BaseModel` One RDF list cell: ``cell`` is the list node; ``value`` is the ``rdf:first`` object. The terminal sentinel row uses ``cell == rdf:nil`` and ``value is None``; that row emits no ``rdf:first`` triple in `Seq.as_triples`. Non-sentinel rows MUST supply a ``value`` (the list member, typically an IRI, blank node, or literal). .. py:attribute:: model_config Configuration for the model, should be a dictionary conforming to [`ConfigDict`][pydantic.config.ConfigDict]. .. py:attribute:: cell :type: axiom.common.N3Resource :value: None .. py:attribute:: value :type: axiom.common.N3Node | None :value: None .. py:method:: check_rdf_nil_or_value() -> Self Require ``rdf:nil`` rows to omit ``rdf:first`` and non-terminal rows to supply a value. .. py:class:: Seq(/, **data: Any) Bases: :py:obj:`StructuralFragment` OWL / RDF list helper encoding ``T(SEQ v1 ... vn)`` (finite ``rdf:List``). ``Seq`` is a ``StructuralFragment``: it models owned ``rdf:List`` scaffolding for a single owning ``StructuralElement`` (for example the operand list of ``DataIntersectionOf``). Each member is an RDF term referenced by ``rdf:first`` (no nested axiom instances; DR-031). ``entries`` pairs each list cell node with its ``rdf:first`` value; the last row is the sentinel ``(rdf:nil, None)`` (OWL empty list uses only that row). ``name`` is the list head: ``entries[0].cell``. ``as_triples`` emits list scaffolding only; the owning element's ``as_triples`` is responsible for chaining these triples into its partition. Triples (omit ``rdf:first`` where ``value`` is ``None``):: Ei.cell rdf:first Ei.value . # when Ei.value is not None Ei.cell rdf:rest entries[i+1].cell . # i < len(entries)-1 .. py:attribute:: kind :type: Literal['seq'] :value: 'seq' .. py:attribute:: entries :type: collections.abc.Sequence[SeqEntry] :value: None .. py:property:: name :type: rdflib.IdentifiedNode List head node taken from the first ``SeqEntry`` cell. .. py:property:: as_triples :type: collections.abc.Sequence[axiom.common.Triple] Emit ``rdf:first`` and ``rdf:rest`` triples for this finite ``rdf:List``. .. py:method:: check_list_integrity() -> Self Validate non-empty entries, a terminal ``rdf:nil``, and unique list cells. .. py:method:: from_rdflib(graph: rdflib.Graph, head: rdflib.IdentifiedNode) -> Self :classmethod: Walk ``rdf:first`` / ``rdf:rest`` from ``head`` and build a ``Seq`` in ``graph``'s context. .. py:class:: DeclarationElement(/, **data: Any) Bases: :py:obj:`StructuralElement`, :py:obj:`abc.ABC` OWL 2 declaration axiom head with a fixed ``rdf:type`` for the declared name. .. py:attribute:: name_value :type: axiom.common.N3Resource :value: None .. py:property:: name :type: rdflib.IdentifiedNode Declared entity identifier (alias of ``name_value``). .. py:property:: rdf_type :type: rdflib.IdentifiedNode :abstractmethod: ``rdf:type`` object for the declaration triple. .. py:property:: as_triples :type: collections.abc.Sequence[axiom.common.Triple] Single ``name rdf:type rdf_type`` declaration triple.