Skip to main content

owl_structural_model/
class_expression.rs

1//! Complete OWL 2 class expressions with shared caller-owned literal/individual values.
2
3use crate::{Cardinality, ClassExpressionKind, DataRange, Individual, OperandList, OperandSet};
4use iri_rfc3987::Iri;
5
6/// A named object property or inverse of a named object property.
7#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
8#[serde(deny_unknown_fields)]
9pub enum ObjectPropertyExpression {
10    /// A named property.
11    Named(Iri<String>),
12    /// The inverse of a named property, as required by the structural grammar.
13    InverseOf(Iri<String>),
14}
15impl ObjectPropertyExpression {
16    /// Create a named object property expression.
17    #[must_use]
18    pub fn named(iri: Iri<String>) -> Self {
19        Self::Named(iri)
20    }
21    /// Create the inverse of a named object property.
22    #[must_use]
23    pub fn inverse_of(iri: Iri<String>) -> Self {
24        Self::InverseOf(iri)
25    }
26}
27
28/// All 18 OWL 2 class-expression forms.
29#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
30#[serde(deny_unknown_fields)]
31pub enum ClassExpression<L = crate::OwlLiteral, B = crate::BlankNodeId> {
32    /// A named class, including owl:Thing and owl:Nothing.
33    Named(Iri<String>),
34    /// Intersection of at least two source occurrences.
35    ObjectIntersectionOf(OperandSet<Self, 2>),
36    /// Union of at least two source occurrences.
37    ObjectUnionOf(OperandSet<Self, 2>),
38    /// Complement of one class expression.
39    ObjectComplementOf(Box<Self>),
40    /// Enumeration of individuals.
41    ObjectOneOf(OperandSet<Individual<B>, 1>),
42    /// Existential object restriction.
43    ObjectSomeValuesFrom {
44        /// The property operand.
45        property: ObjectPropertyExpression,
46        /// The filler operand.
47        filler: Box<Self>,
48    },
49    /// Universal object restriction.
50    ObjectAllValuesFrom {
51        /// The property operand.
52        property: ObjectPropertyExpression,
53        /// The filler operand.
54        filler: Box<Self>,
55    },
56    /// Object value restriction.
57    ObjectHasValue {
58        /// The property operand.
59        property: ObjectPropertyExpression,
60        /// The individual operand.
61        individual: Individual<B>,
62    },
63    /// Object self restriction.
64    ObjectHasSelf {
65        /// The property operand.
66        property: ObjectPropertyExpression,
67    },
68    /// Minimum object cardinality restriction.
69    ObjectMinCardinality {
70        /// The cardinality operand.
71        cardinality: Cardinality,
72        /// The property operand.
73        property: ObjectPropertyExpression,
74        /// The filler operand.
75        filler: Box<Self>,
76    },
77    /// Maximum object cardinality restriction.
78    ObjectMaxCardinality {
79        /// The cardinality operand.
80        cardinality: Cardinality,
81        /// The property operand.
82        property: ObjectPropertyExpression,
83        /// The filler operand.
84        filler: Box<Self>,
85    },
86    /// Exact object cardinality restriction.
87    ObjectExactCardinality {
88        /// The cardinality operand.
89        cardinality: Cardinality,
90        /// The property operand.
91        property: ObjectPropertyExpression,
92        /// The filler operand.
93        filler: Box<Self>,
94    },
95    /// Some data-value restriction, with ordered property positions.
96    DataSomeValuesFrom {
97        /// The properties operand.
98        properties: OperandList<Iri<String>, 1>,
99        /// The range operand.
100        range: DataRange<L>,
101    },
102    /// All data-value restriction, with ordered property positions.
103    DataAllValuesFrom {
104        /// The properties operand.
105        properties: OperandList<Iri<String>, 1>,
106        /// The range operand.
107        range: DataRange<L>,
108    },
109    /// Data value restriction.
110    DataHasValue {
111        /// The property operand.
112        property: Iri<String>,
113        /// The value operand.
114        value: L,
115    },
116    /// Min data cardinality restriction.
117    DataMinCardinality {
118        /// The cardinality operand.
119        cardinality: Cardinality,
120        /// The property operand.
121        property: Iri<String>,
122        /// The range operand.
123        range: DataRange<L>,
124    },
125    /// Max data cardinality restriction.
126    DataMaxCardinality {
127        /// The cardinality operand.
128        cardinality: Cardinality,
129        /// The property operand.
130        property: Iri<String>,
131        /// The range operand.
132        range: DataRange<L>,
133    },
134    /// Exact data cardinality restriction.
135    DataExactCardinality {
136        /// The cardinality operand.
137        cardinality: Cardinality,
138        /// The property operand.
139        property: Iri<String>,
140        /// The range operand.
141        range: DataRange<L>,
142    },
143}
144
145impl<L, B> ClassExpression<L, B> {
146    /// Return the structural expression kind without evaluating it.
147    #[must_use]
148    pub fn kind(&self) -> ClassExpressionKind {
149        match self {
150            Self::Named(..) => ClassExpressionKind::Named,
151            Self::ObjectIntersectionOf(..) => ClassExpressionKind::ObjectIntersectionOf,
152            Self::ObjectUnionOf(..) => ClassExpressionKind::ObjectUnionOf,
153            Self::ObjectComplementOf(..) => ClassExpressionKind::ObjectComplementOf,
154            Self::ObjectOneOf(..) => ClassExpressionKind::ObjectOneOf,
155            Self::ObjectSomeValuesFrom { .. } => ClassExpressionKind::ObjectSomeValuesFrom,
156            Self::ObjectAllValuesFrom { .. } => ClassExpressionKind::ObjectAllValuesFrom,
157            Self::ObjectHasValue { .. } => ClassExpressionKind::ObjectHasValue,
158            Self::ObjectHasSelf { .. } => ClassExpressionKind::ObjectHasSelf,
159            Self::ObjectMinCardinality { .. } => ClassExpressionKind::ObjectMinCardinality,
160            Self::ObjectMaxCardinality { .. } => ClassExpressionKind::ObjectMaxCardinality,
161            Self::ObjectExactCardinality { .. } => ClassExpressionKind::ObjectExactCardinality,
162            Self::DataSomeValuesFrom { .. } => ClassExpressionKind::DataSomeValuesFrom,
163            Self::DataAllValuesFrom { .. } => ClassExpressionKind::DataAllValuesFrom,
164            Self::DataHasValue { .. } => ClassExpressionKind::DataHasValue,
165            Self::DataMinCardinality { .. } => ClassExpressionKind::DataMinCardinality,
166            Self::DataMaxCardinality { .. } => ClassExpressionKind::DataMaxCardinality,
167            Self::DataExactCardinality { .. } => ClassExpressionKind::DataExactCardinality,
168        }
169    }
170}