owl_structural_model/
data_range.rs1use iri_rfc3987::Iri;
4
5use crate::{DataRangeKind, OperandSet, OwlLiteral, StructuralModelError};
6
7#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
12#[serde(deny_unknown_fields)]
13pub struct FacetRestriction<L = OwlLiteral> {
14 facet: Iri<String>,
15 value: L,
16}
17
18impl<L> FacetRestriction<L> {
19 #[must_use]
21 pub fn new(facet: Iri<String>, value: L) -> Self {
22 Self { facet, value }
23 }
24
25 #[must_use]
27 pub fn facet(&self) -> &Iri<String> {
28 &self.facet
29 }
30
31 #[must_use]
33 pub fn value(&self) -> &L {
34 &self.value
35 }
36}
37
38#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
40#[serde(deny_unknown_fields)]
41pub enum DataRange<L = OwlLiteral> {
42 Datatype(Iri<String>),
44 DataIntersectionOf(OperandSet<Self, 2>),
47 DataUnionOf(OperandSet<Self, 2>),
50 DataComplementOf(Box<Self>),
52 DataOneOf(OperandSet<L, 1>),
55 DatatypeRestriction {
57 datatype: Iri<String>,
59 restrictions: OperandSet<FacetRestriction<L>, 1>,
62 },
63}
64
65impl<L> DataRange<L> {
66 #[must_use]
68 pub fn datatype(datatype: Iri<String>) -> Self {
69 Self::Datatype(datatype)
70 }
71
72 pub fn data_intersection_of(operands: Vec<Self>) -> Result<Self, StructuralModelError> {
78 Ok(Self::DataIntersectionOf(OperandSet::try_new(operands)?))
79 }
80
81 pub fn data_union_of(operands: Vec<Self>) -> Result<Self, StructuralModelError> {
87 Ok(Self::DataUnionOf(OperandSet::try_new(operands)?))
88 }
89
90 #[must_use]
92 pub fn data_complement_of(operand: Self) -> Self {
93 Self::DataComplementOf(Box::new(operand))
94 }
95
96 pub fn data_one_of(literals: Vec<L>) -> Result<Self, StructuralModelError> {
102 Ok(Self::DataOneOf(OperandSet::try_new(literals)?))
103 }
104
105 pub fn datatype_restriction(
111 datatype: Iri<String>,
112 restrictions: Vec<FacetRestriction<L>>,
113 ) -> Result<Self, StructuralModelError> {
114 Ok(Self::DatatypeRestriction {
115 datatype,
116 restrictions: OperandSet::try_new(restrictions)?,
117 })
118 }
119}
120
121impl<L> DataRange<L> {
122 #[must_use]
124 pub fn kind(&self) -> DataRangeKind {
125 match self {
126 Self::Datatype(_) => DataRangeKind::Datatype,
127 Self::DataIntersectionOf(_) => DataRangeKind::DataIntersectionOf,
128 Self::DataUnionOf(_) => DataRangeKind::DataUnionOf,
129 Self::DataComplementOf(_) => DataRangeKind::DataComplementOf,
130 Self::DataOneOf(_) => DataRangeKind::DataOneOf,
131 Self::DatatypeRestriction { .. } => DataRangeKind::DatatypeRestriction,
132 }
133 }
134}