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