axiom.datatype ============== .. py:module:: axiom.datatype .. autoapi-nested-parse:: OWL 2 Data Range and data-property class-expression structural elements. This module models two related families of OWL 2 structural elements plus the owned ``StructuralFragment`` scaffolding their RDF mappings require. Data Range expressions (subclasses of :class:`DataRange`): - :class:`DeclarationDatatype` --- ``Declaration( Datatype( DT ) )``; the fallback when no richer data range can be reconstructed from the graph. - :class:`DataIntersectionOf` --- ``DataIntersectionOf( DR1 ... DRn )``, ``n >= 2``; owns an :class:`~rdflib_reasoning.axiom.structural_element.Seq` fragment. - :class:`DataUnionOf` --- ``DataUnionOf( DR1 ... DRn )``, ``n >= 2``; owns an :class:`~rdflib_reasoning.axiom.structural_element.Seq` fragment. - :class:`DataComplementOf` --- ``DataComplementOf( DR )``; the operand is a cross-axiom node reference. - :class:`DataOneOf` --- ``DataOneOf( lt1 ... ltn )``, ``n >= 1``; owns an :class:`~rdflib_reasoning.axiom.structural_element.Seq` fragment of literals. - :class:`DatatypeRestriction` --- ``DatatypeRestriction( DT F1 lt1 ... Fn ltn )``; owns a :class:`FacetList` fragment carrying both the cons-cell chain and the per-facet ``(_:yi Fi lti)`` triples. Data property class expressions (subclasses of :class:`DataRestriction`): - :class:`DataSomeValuesFrom` --- unary form ``DataSomeValuesFrom( DPE DR )``. - :class:`DataSomeValuesFromNary` --- n-ary form ``DataSomeValuesFrom( DPE1 ... DPEn DR )``, ``n >= 2``; owns an :class:`~rdflib_reasoning.axiom.structural_element.Seq` fragment of property expressions. - :class:`DataAllValuesFrom` --- unary form ``DataAllValuesFrom( DPE DR )``. - :class:`DataAllValuesFromNary` --- n-ary form ``DataAllValuesFrom( DPE1 ... DPEn DR )``, ``n >= 2``; owns an :class:`~rdflib_reasoning.axiom.structural_element.Seq` fragment of property expressions. - :class:`DataHasValue` --- ``DataHasValue( DPE lt )``. - Cardinality forms --- :class:`DataMinCardinality`, :class:`DataMinCardinalityQualified`, :class:`DataMaxCardinality`, :class:`DataMaxCardinalityQualified`, :class:`DataExactCardinality`, :class:`DataExactCardinalityQualified`. Owned scaffolding fragments defined here: - :class:`FacetEntry` and :class:`FacetList` --- the ``rdf:List`` carrier for :class:`DatatypeRestriction`'s facet operand list, including the per-facet anchor triple. :class:`DataRange` and :class:`DataRestriction` are abstract umbrellas: both block direct instantiation, both provide the shared declaration triple (``rdfs:Datatype`` for ``DataRange`` subclasses, ``owl:Restriction`` for ``DataRestriction`` subclasses) via ``as_triples``, and concrete subclasses extend that projection with their own predicate-specific triples. Owned fragments share their owning element's ``context`` and contribute their ``as_triples`` to the owner's RDF partition; cross-axiom operands are RDF node identifiers via the package's annotated aliases. Classes ------- .. autoapisummary:: axiom.datatype.DataRange axiom.datatype.DeclarationDatatype axiom.datatype.DataIntersectionOf axiom.datatype.DataUnionOf axiom.datatype.DataComplementOf axiom.datatype.DataOneOf axiom.datatype.DataRestriction axiom.datatype.DataSomeValuesFrom axiom.datatype.DataSomeValuesFromNary axiom.datatype.DataAllValuesFrom axiom.datatype.DataAllValuesFromNary axiom.datatype.DataHasValue axiom.datatype.DataMinCardinality axiom.datatype.DataMinCardinalityQualified axiom.datatype.DataMaxCardinality axiom.datatype.DataMaxCardinalityQualified axiom.datatype.DataExactCardinality axiom.datatype.DataExactCardinalityQualified axiom.datatype.FacetEntry axiom.datatype.FacetList axiom.datatype.DatatypeRestriction Module Contents --------------- .. py:class:: DataRange(/, **data: Any) Bases: :py:obj:`axiom.structural_element.DeclarationElement`, :py:obj:`abc.ABC` Abstract umbrella for OWL 2 Data Range expressions. Not directly instantiable. Concrete subclasses include ``DeclarationDatatype`` (the fallback when no richer data range can be constructed from the graph) and the richer expressions ``DataIntersectionOf``, ``DataUnionOf``, ``DataComplementOf``, ``DataOneOf``, and ``DatatypeRestriction``. All concrete data ranges declare ``rdf:type rdfs:Datatype`` for ``name``. .. py:property:: rdf_type :type: rdflib.IdentifiedNode ``rdf:type`` object for the declaration triple. .. py:class:: DeclarationDatatype(/, **data: Any) Bases: :py:obj:`DataRange` Element `Declaration( Datatype( DT ) )` of the structural specification. Note that all of our `DataRange` classes share the same properties as a `DeclarationDatatype` instance, but we keep this as a separate axiom so that OWL axioms can partition a graph. _This_ axiom is only constructed if we are lacking the necessary triples to construct a different `DataRange` axiom. .. py:attribute:: kind :type: Literal['DeclarationDatatype'] :value: 'DeclarationDatatype' .. py:class:: DataIntersectionOf(/, **data: Any) Bases: :py:obj:`DataRange` Element ``DataIntersectionOf( DR1 ... DRn )`` of the OWL 2 structural specification. The main RDF node is an anonymous blank node (written ``_:x`` below). OWL 2 structural syntax requires n >= 2 data range operands. Triples:: _:x rdf:type rdfs:Datatype . _:x owl:intersectionOf T(SEQ DR1 ... DRn) . .. py:attribute:: kind :type: Literal['DataIntersectionOf'] :value: 'DataIntersectionOf' .. py:attribute:: intersection_of :type: axiom.structural_element.Seq .. py:property:: as_triples :type: collections.abc.Sequence[axiom.common.Triple] Single ``name rdf:type rdf_type`` declaration triple. .. py:class:: DataUnionOf(/, **data: Any) Bases: :py:obj:`DataRange` Element ``DataUnionOf( DR1 ... DRn )`` of the OWL 2 structural specification. The main RDF node is an anonymous blank node (written ``_:x`` below). OWL 2 structural syntax requires n >= 2 data range operands. Triples:: _:x rdf:type rdfs:Datatype . _:x owl:unionOf T(SEQ DR1 ... DRn) . .. py:attribute:: kind :type: Literal['DataUnionOf'] :value: 'DataUnionOf' .. py:attribute:: union_of :type: axiom.structural_element.Seq .. py:property:: as_triples :type: collections.abc.Sequence[axiom.common.Triple] Single ``name rdf:type rdf_type`` declaration triple. .. py:class:: DataComplementOf(/, **data: Any) Bases: :py:obj:`DataRange` Element ``DataComplementOf( DR )`` of the OWL 2 structural specification. The main RDF node is an anonymous blank node (written ``_:x`` below). ``complement_of`` is the RDF subject of the complemented datatype description (IRI or blank node); ``as_triples`` emits only this axiom's triples (shallow projection per DR-031). Declaration and other triples for ``DR`` belong in a separate axiom instance or graph partition, not inlined here. Triples:: _:x rdf:type rdfs:Datatype . _:x owl:complementOf DR . .. py:attribute:: kind :type: Literal['DataComplementOf'] :value: 'DataComplementOf' .. py:attribute:: complement_of :type: axiom.common.N3Resource .. py:property:: as_triples :type: collections.abc.Sequence[axiom.common.Triple] Single ``name rdf:type rdf_type`` declaration triple. .. py:class:: DataOneOf(/, **data: Any) Bases: :py:obj:`DataRange` Element ``DataOneOf( lt1 ... ltn )`` of the OWL 2 structural specification. The main RDF node is an anonymous blank node (written ``_:x`` below). ``one_of`` is an owned ``Seq`` fragment carrying the enumerated RDF literals as ``rdf:first`` values; the fragment shares this element's ``context``. OWL 2 structural syntax requires n >= 1 literal operands. Triples:: _:x rdf:type rdfs:Datatype . _:x owl:oneOf T(SEQ lt1 ... ltn) . .. py:attribute:: kind :type: Literal['DataOneOf'] :value: 'DataOneOf' .. py:attribute:: one_of :type: axiom.structural_element.Seq .. py:property:: as_triples :type: collections.abc.Sequence[axiom.common.Triple] Single ``name rdf:type rdf_type`` declaration triple. .. py:class:: DataRestriction(/, **data: Any) Bases: :py:obj:`axiom.structural_element.StructuralElement`, :py:obj:`abc.ABC` Abstract base for OWL 2 class expressions that restrict a data property. Not directly instantiable. Each concrete subclass declares a node of ``rdf:type owl:Restriction`` and pairs ``owl:onProperty`` (or ``owl:onProperties`` for n-ary forms) with a range or value predicate per the OWL 2 RDF mapping. ``name`` is the RDF subject of the restriction node (typically a blank node). .. py:attribute:: name_value :type: axiom.common.N3Resource :value: None .. py:property:: name :type: rdflib.IdentifiedNode Restriction node identifier (alias of ``name_value``). .. py:property:: as_triples :type: collections.abc.Sequence[axiom.common.Triple] Triples representing this element as RDF; MUST NOT recurse into related elements. .. py:class:: DataSomeValuesFrom(/, **data: Any) Bases: :py:obj:`DataRestriction` Element ``DataSomeValuesFrom`` (data existential restriction) in the OWL 2 structural specification. The RDF subject is typically an anonymous blank node (written ``_:x`` below). Triples:: _:x rdf:type owl:Restriction . _:x owl:onProperty DPE . _:x owl:someValuesFrom DR . .. py:attribute:: kind :type: Literal['DataSomeValuesFrom'] :value: 'DataSomeValuesFrom' .. py:attribute:: on_property :type: axiom.common.N3IRIRef .. py:attribute:: some_values_from :type: axiom.common.N3Resource .. py:property:: as_triples :type: collections.abc.Sequence[axiom.common.Triple] Triples representing this element as RDF; MUST NOT recurse into related elements. .. py:class:: DataSomeValuesFromNary(/, **data: Any) Bases: :py:obj:`DataRestriction` Element ``DataSomeValuesFrom( DPE1 ... DPEn DR )``, n >= 2, in the OWL 2 structural specification. The RDF subject is typically an anonymous blank node (written ``_:x`` below). ``on_properties`` is an owned ``Seq`` fragment carrying the data property expressions; the fragment shares this element's ``context``. Triples:: _:x rdf:type owl:Restriction . _:x owl:onProperties T(SEQ DPE1 ... DPEn) . _:x owl:someValuesFrom DR . .. py:attribute:: kind :type: Literal['DataSomeValuesFromNary'] :value: 'DataSomeValuesFromNary' .. py:attribute:: on_properties :type: axiom.structural_element.Seq .. py:attribute:: some_values_from :type: axiom.common.N3Resource .. py:property:: as_triples :type: collections.abc.Sequence[axiom.common.Triple] Triples representing this element as RDF; MUST NOT recurse into related elements. .. py:class:: DataAllValuesFrom(/, **data: Any) Bases: :py:obj:`DataRestriction` Element ``DataAllValuesFrom( DPE DR )`` in the OWL 2 structural specification. The RDF subject is typically an anonymous blank node (written ``_:x`` below). Triples:: _:x rdf:type owl:Restriction . _:x owl:onProperty DPE . _:x owl:allValuesFrom DR . .. py:attribute:: kind :type: Literal['DataAllValuesFrom'] :value: 'DataAllValuesFrom' .. py:attribute:: on_property :type: axiom.common.N3IRIRef .. py:attribute:: all_values_from :type: axiom.common.N3Resource .. py:property:: as_triples :type: collections.abc.Sequence[axiom.common.Triple] Triples representing this element as RDF; MUST NOT recurse into related elements. .. py:class:: DataAllValuesFromNary(/, **data: Any) Bases: :py:obj:`DataRestriction` Element ``DataAllValuesFrom( DPE1 ... DPEn DR )``, n >= 2, in the OWL 2 structural specification. The RDF subject is typically an anonymous blank node (written ``_:x`` below). ``on_properties`` is an owned ``Seq`` fragment carrying the data property expressions; the fragment shares this element's ``context``. Triples:: _:x rdf:type owl:Restriction . _:x owl:onProperties T(SEQ DPE1 ... DPEn) . _:x owl:allValuesFrom DR . .. py:attribute:: kind :type: Literal['DataAllValuesFromNary'] :value: 'DataAllValuesFromNary' .. py:attribute:: on_properties :type: axiom.structural_element.Seq .. py:attribute:: all_values_from :type: axiom.common.N3Resource .. py:property:: as_triples :type: collections.abc.Sequence[axiom.common.Triple] Triples representing this element as RDF; MUST NOT recurse into related elements. .. py:class:: DataHasValue(/, **data: Any) Bases: :py:obj:`DataRestriction` Element ``DataHasValue( DPE lt )`` in the OWL 2 structural specification. The RDF subject is typically an anonymous blank node (written ``_:x`` below). ``has_value`` is a literal. Triples:: _:x rdf:type owl:Restriction . _:x owl:onProperty DPE . _:x owl:hasValue lt . .. py:attribute:: kind :type: Literal['DataHasValue'] :value: 'DataHasValue' .. py:attribute:: on_property :type: axiom.common.N3IRIRef .. py:attribute:: has_value :type: axiom.common.N3Node .. py:property:: as_triples :type: collections.abc.Sequence[axiom.common.Triple] Triples representing this element as RDF; MUST NOT recurse into related elements. .. py:class:: DataMinCardinality(/, **data: Any) Bases: :py:obj:`DataRestriction` Element ``DataMinCardinality( n DPE )`` in the OWL 2 structural specification. Triples:: _:x rdf:type owl:Restriction . _:x owl:onProperty DPE . _:x owl:minCardinality "n"^^xsd:nonNegativeInteger . .. py:attribute:: kind :type: Literal['DataMinCardinality'] :value: 'DataMinCardinality' .. py:attribute:: on_property :type: axiom.common.N3IRIRef .. py:attribute:: min_cardinality :type: axiom.common.N3Node .. py:property:: as_triples :type: collections.abc.Sequence[axiom.common.Triple] Triples representing this element as RDF; MUST NOT recurse into related elements. .. py:class:: DataMinCardinalityQualified(/, **data: Any) Bases: :py:obj:`DataRestriction` Element ``DataMinCardinality( n DPE DR )`` in the OWL 2 structural specification. Triples:: _:x rdf:type owl:Restriction . _:x owl:onProperty DPE . _:x owl:minQualifiedCardinality "n"^^xsd:nonNegativeInteger . _:x owl:onDataRange DR . .. py:attribute:: kind :type: Literal['DataMinCardinalityQualified'] :value: 'DataMinCardinalityQualified' .. py:attribute:: on_property :type: axiom.common.N3IRIRef .. py:attribute:: min_qualified_cardinality :type: axiom.common.N3Node .. py:attribute:: on_data_range :type: axiom.common.N3Resource .. py:property:: as_triples :type: collections.abc.Sequence[axiom.common.Triple] Triples representing this element as RDF; MUST NOT recurse into related elements. .. py:class:: DataMaxCardinality(/, **data: Any) Bases: :py:obj:`DataRestriction` Element ``DataMaxCardinality( n DPE )`` in the OWL 2 structural specification. Triples:: _:x rdf:type owl:Restriction . _:x owl:onProperty DPE . _:x owl:maxCardinality "n"^^xsd:nonNegativeInteger . .. py:attribute:: kind :type: Literal['DataMaxCardinality'] :value: 'DataMaxCardinality' .. py:attribute:: on_property :type: axiom.common.N3IRIRef .. py:attribute:: max_cardinality :type: axiom.common.N3Node .. py:property:: as_triples :type: collections.abc.Sequence[axiom.common.Triple] Triples representing this element as RDF; MUST NOT recurse into related elements. .. py:class:: DataMaxCardinalityQualified(/, **data: Any) Bases: :py:obj:`DataRestriction` Element ``DataMaxCardinality( n DPE DR )`` in the OWL 2 structural specification. Triples:: _:x rdf:type owl:Restriction . _:x owl:onProperty DPE . _:x owl:maxQualifiedCardinality "n"^^xsd:nonNegativeInteger . _:x owl:onDataRange DR . .. py:attribute:: kind :type: Literal['DataMaxCardinalityQualified'] :value: 'DataMaxCardinalityQualified' .. py:attribute:: on_property :type: axiom.common.N3IRIRef .. py:attribute:: max_qualified_cardinality :type: axiom.common.N3Node .. py:attribute:: on_data_range :type: axiom.common.N3Resource .. py:property:: as_triples :type: collections.abc.Sequence[axiom.common.Triple] Triples representing this element as RDF; MUST NOT recurse into related elements. .. py:class:: DataExactCardinality(/, **data: Any) Bases: :py:obj:`DataRestriction` Element ``DataExactCardinality( n DPE )`` in the OWL 2 structural specification. Triples:: _:x rdf:type owl:Restriction . _:x owl:onProperty DPE . _:x owl:cardinality "n"^^xsd:nonNegativeInteger . .. py:attribute:: kind :type: Literal['DataExactCardinality'] :value: 'DataExactCardinality' .. py:attribute:: on_property :type: axiom.common.N3IRIRef .. py:attribute:: cardinality :type: axiom.common.N3Node .. py:property:: as_triples :type: collections.abc.Sequence[axiom.common.Triple] Triples representing this element as RDF; MUST NOT recurse into related elements. .. py:class:: DataExactCardinalityQualified(/, **data: Any) Bases: :py:obj:`DataRestriction` Element ``DataExactCardinality( n DPE DR )`` in the OWL 2 structural specification. Triples:: _:x rdf:type owl:Restriction . _:x owl:onProperty DPE . _:x owl:qualifiedCardinality "n"^^xsd:nonNegativeInteger . _:x owl:onDataRange DR . .. py:attribute:: kind :type: Literal['DataExactCardinalityQualified'] :value: 'DataExactCardinalityQualified' .. py:attribute:: on_property :type: axiom.common.N3IRIRef .. py:attribute:: qualified_cardinality :type: axiom.common.N3Node .. py:attribute:: on_data_range :type: axiom.common.N3Resource .. py:property:: as_triples :type: collections.abc.Sequence[axiom.common.Triple] Triples representing this element as RDF; MUST NOT recurse into related elements. .. py:class:: FacetEntry(/, **data: Any) Bases: :py:obj:`pydantic.BaseModel` One facet row in a ``DatatypeRestriction`` operand list. ``cell`` is the ``rdf:List`` cons-cell node (the ``_:li`` in the OWL 2 mapping). ``anchor`` is the facet anchor node referenced by the cons-cell's ``rdf:first`` (the ``_:yi``). ``facet`` is the facet predicate (for example ``xsd:minInclusive``) and ``value`` is the facet literal. The terminal sentinel row uses ``cell == rdf:nil`` with ``anchor``, ``facet``, and ``value`` all ``None`` and emits no facet or list-membership triple from ``FacetList.as_triples``. Non-sentinel rows MUST supply all three of ``anchor``, ``facet``, and ``value``. .. 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:: anchor :type: axiom.common.N3Resource | None :value: None .. py:attribute:: facet :type: axiom.common.N3IRIRef | None :value: None .. py:attribute:: value :type: axiom.common.N3Node | None :value: None .. py:method:: check_rdf_nil_or_facet_value() -> Self Require ``rdf:nil`` rows to be empty and facet rows to supply anchor, facet, and value. .. py:class:: FacetList(/, **data: Any) Bases: :py:obj:`axiom.structural_element.StructuralFragment` Owned ``rdf:List`` scaffolding for the operand list of ``DatatypeRestriction``. Encodes both the cons-cell chain of facet anchor nodes and each per-facet ``(_:yi Fi lti)`` triple in a single ``as_triples`` projection (all rows belong to the owning ``DatatypeRestriction``'s partition per DR-031). Triples (omit ``rdf:first`` and facet rows where ``cell == rdf:nil``):: Ei.cell rdf:first Ei.anchor . # when row is non-sentinel Ei.anchor Ei.facet Ei.value . # when row is non-sentinel Ei.cell rdf:rest entries[i+1].cell . # i < len(entries)-1 .. py:attribute:: kind :type: Literal['facet_list'] :value: 'facet_list' .. py:attribute:: entries :type: collections.abc.Sequence[FacetEntry] :value: None .. py:property:: name :type: rdflib.IdentifiedNode Facet list head node taken from the first ``FacetEntry`` cell. .. py:property:: as_triples :type: collections.abc.Sequence[axiom.common.Triple] Emit list scaffolding and per-facet constraint triples for ``DatatypeRestriction``. .. py:method:: check_list_integrity() -> Self Validate non-empty entries, a terminal ``rdf:nil``, and unique list cells. .. py:class:: DatatypeRestriction(/, **data: Any) Bases: :py:obj:`DataRange` Element ``DatatypeRestriction( DT F1 lt1 ... Fn ltn )`` in the OWL 2 structural specification. The main RDF node is an anonymous blank node (written ``_:x`` below). ``on_datatype`` is the constrained datatype IRI; ``with_restrictions`` is an owned ``FacetList`` fragment that carries the facet anchor nodes and their per-facet ``(_:yi Fi lti)`` triples. Triples:: _:x rdf:type rdfs:Datatype . _:x owl:onDatatype DT . _:x owl:withRestrictions T(SEQ _:y1 ... _:yn) . _:y1 F1 lt1 . ... _:yn Fn ltn . .. py:attribute:: kind :type: Literal['DatatypeRestriction'] :value: 'DatatypeRestriction' .. py:attribute:: on_datatype :type: axiom.common.N3IRIRef .. py:attribute:: with_restrictions :type: FacetList .. py:property:: as_triples :type: collections.abc.Sequence[axiom.common.Triple] Single ``name rdf:type rdf_type`` declaration triple.