Skip to main content

owl_structural_model/
property_axiom.rs

1//! Property-axiom construction and uniform axiom annotations.
2
3use iri_rfc3987::Iri;
4
5use crate::{Axiom, AxiomAnnotations, ObjectPropertyExpression, SubObjectPropertyExpression};
6
7impl<L, B> Axiom<L, B> {
8    /// Create an object subproperty or property-chain inclusion without annotations.
9    #[must_use]
10    pub fn sub_object_property_of(
11        sub_property: SubObjectPropertyExpression,
12        super_property: ObjectPropertyExpression,
13    ) -> Self {
14        Self::SubObjectPropertyOf {
15            sub_property,
16            super_property,
17            annotations: AxiomAnnotations::empty(),
18        }
19    }
20
21    /// Create a functional object property axiom without annotations.
22    #[must_use]
23    pub fn functional_object_property(property: ObjectPropertyExpression) -> Self {
24        Self::FunctionalObjectProperty {
25            property,
26            annotations: AxiomAnnotations::empty(),
27        }
28    }
29
30    /// Create a inverse-functional object property axiom without annotations.
31    #[must_use]
32    pub fn inverse_functional_object_property(property: ObjectPropertyExpression) -> Self {
33        Self::InverseFunctionalObjectProperty {
34            property,
35            annotations: AxiomAnnotations::empty(),
36        }
37    }
38
39    /// Create a reflexive object property axiom without annotations.
40    #[must_use]
41    pub fn reflexive_object_property(property: ObjectPropertyExpression) -> Self {
42        Self::ReflexiveObjectProperty {
43            property,
44            annotations: AxiomAnnotations::empty(),
45        }
46    }
47
48    /// Create a irreflexive object property axiom without annotations.
49    #[must_use]
50    pub fn irreflexive_object_property(property: ObjectPropertyExpression) -> Self {
51        Self::IrreflexiveObjectProperty {
52            property,
53            annotations: AxiomAnnotations::empty(),
54        }
55    }
56
57    /// Create a symmetric object property axiom without annotations.
58    #[must_use]
59    pub fn symmetric_object_property(property: ObjectPropertyExpression) -> Self {
60        Self::SymmetricObjectProperty {
61            property,
62            annotations: AxiomAnnotations::empty(),
63        }
64    }
65
66    /// Create a asymmetric object property axiom without annotations.
67    #[must_use]
68    pub fn asymmetric_object_property(property: ObjectPropertyExpression) -> Self {
69        Self::AsymmetricObjectProperty {
70            property,
71            annotations: AxiomAnnotations::empty(),
72        }
73    }
74
75    /// Create a transitive object property axiom without annotations.
76    #[must_use]
77    pub fn transitive_object_property(property: ObjectPropertyExpression) -> Self {
78        Self::TransitiveObjectProperty {
79            property,
80            annotations: AxiomAnnotations::empty(),
81        }
82    }
83
84    /// Create a functional data property axiom without annotations.
85    #[must_use]
86    pub fn functional_data_property(property: Iri<String>) -> Self {
87        Self::FunctionalDataProperty {
88            property,
89            annotations: AxiomAnnotations::empty(),
90        }
91    }
92
93    /// Return this axiom's annotations.
94    #[must_use]
95    pub fn annotations(&self) -> &AxiomAnnotations<L, B> {
96        match self {
97            Self::Declaration { annotations, .. }
98            | Self::SubClassOf { annotations, .. }
99            | Self::EquivalentClasses { annotations, .. }
100            | Self::DisjointClasses { annotations, .. }
101            | Self::ObjectPropertyDomain { annotations, .. }
102            | Self::AnnotationAssertion { annotations, .. }
103            | Self::SubObjectPropertyOf { annotations, .. }
104            | Self::FunctionalObjectProperty { annotations, .. }
105            | Self::InverseFunctionalObjectProperty { annotations, .. }
106            | Self::ReflexiveObjectProperty { annotations, .. }
107            | Self::IrreflexiveObjectProperty { annotations, .. }
108            | Self::SymmetricObjectProperty { annotations, .. }
109            | Self::AsymmetricObjectProperty { annotations, .. }
110            | Self::TransitiveObjectProperty { annotations, .. }
111            | Self::EquivalentObjectProperties { annotations, .. }
112            | Self::DisjointObjectProperties { annotations, .. }
113            | Self::InverseObjectProperties { annotations, .. }
114            | Self::ObjectPropertyRange { annotations, .. }
115            | Self::SubDataPropertyOf { annotations, .. }
116            | Self::EquivalentDataProperties { annotations, .. }
117            | Self::DisjointDataProperties { annotations, .. }
118            | Self::DataPropertyDomain { annotations, .. }
119            | Self::DataPropertyRange { annotations, .. }
120            | Self::DatatypeDefinition { annotations, .. }
121            | Self::HasKey { annotations, .. }
122            | Self::FunctionalDataProperty { annotations, .. } => annotations,
123        }
124    }
125
126    /// Replace this axiom's annotations, preserving its structural operands.
127    #[must_use]
128    pub fn with_annotations(mut self, new_annotations: AxiomAnnotations<L, B>) -> Self {
129        match &mut self {
130            Self::Declaration { annotations, .. }
131            | Self::SubClassOf { annotations, .. }
132            | Self::EquivalentClasses { annotations, .. }
133            | Self::DisjointClasses { annotations, .. }
134            | Self::ObjectPropertyDomain { annotations, .. }
135            | Self::AnnotationAssertion { annotations, .. }
136            | Self::SubObjectPropertyOf { annotations, .. }
137            | Self::FunctionalObjectProperty { annotations, .. }
138            | Self::InverseFunctionalObjectProperty { annotations, .. }
139            | Self::ReflexiveObjectProperty { annotations, .. }
140            | Self::IrreflexiveObjectProperty { annotations, .. }
141            | Self::SymmetricObjectProperty { annotations, .. }
142            | Self::AsymmetricObjectProperty { annotations, .. }
143            | Self::TransitiveObjectProperty { annotations, .. }
144            | Self::EquivalentObjectProperties { annotations, .. }
145            | Self::DisjointObjectProperties { annotations, .. }
146            | Self::InverseObjectProperties { annotations, .. }
147            | Self::ObjectPropertyRange { annotations, .. }
148            | Self::SubDataPropertyOf { annotations, .. }
149            | Self::EquivalentDataProperties { annotations, .. }
150            | Self::DisjointDataProperties { annotations, .. }
151            | Self::DataPropertyDomain { annotations, .. }
152            | Self::DataPropertyRange { annotations, .. }
153            | Self::DatatypeDefinition { annotations, .. }
154            | Self::HasKey { annotations, .. }
155            | Self::FunctionalDataProperty { annotations, .. } => *annotations = new_annotations,
156        }
157        self
158    }
159}