Skip to main content

owl_structural_model/
class_boolean.rs

1//! Constructors for Boolean class expressions and object restrictions.
2use crate::{
3    ClassExpression, Individual, OWL_NOTHING, OWL_THING, ObjectPropertyExpression, OperandSet,
4    StructuralModelError,
5};
6use iri_rfc3987::Iri;
7
8impl<L, B> ClassExpression<L, B> {
9    /// Create a named class.
10    #[must_use]
11    pub fn named(iri: Iri<String>) -> Self {
12        Self::Named(iri)
13    }
14    /// Create owl:Thing as a named class.
15    #[must_use]
16    pub fn thing() -> Self {
17        Self::named(Self::builtin(OWL_THING))
18    }
19    /// Create owl:Nothing as a named class.
20    #[must_use]
21    pub fn nothing() -> Self {
22        Self::named(Self::builtin(OWL_NOTHING))
23    }
24    /// Return whether this expression is the named universal class.
25    #[must_use]
26    pub fn is_thing(&self) -> bool {
27        matches!(self, Self::Named(iri) if iri.as_str() == OWL_THING)
28    }
29    /// Return whether this expression is the named empty class.
30    #[must_use]
31    pub fn is_nothing(&self) -> bool {
32        matches!(self, Self::Named(iri) if iri.as_str() == OWL_NOTHING)
33    }
34    pub(crate) fn builtin(value: &'static str) -> Iri<String> {
35        Iri::parse(value)
36            .expect("built-in OWL/RDF IRI is valid")
37            .into()
38    }
39    /// Create an unordered intersection.
40    /// # Errors
41    /// Rejects fewer than two source occurrences.
42    pub fn object_intersection_of(operands: Vec<Self>) -> Result<Self, StructuralModelError> {
43        Ok(Self::ObjectIntersectionOf(OperandSet::try_new(operands)?))
44    }
45    /// Create an unordered union.
46    /// # Errors
47    /// Rejects fewer than two source occurrences.
48    pub fn object_union_of(operands: Vec<Self>) -> Result<Self, StructuralModelError> {
49        Ok(Self::ObjectUnionOf(OperandSet::try_new(operands)?))
50    }
51    /// Create a complement expression.
52    #[must_use]
53    pub fn object_complement_of(operand: Self) -> Self {
54        Self::ObjectComplementOf(Box::new(operand))
55    }
56    /// Create a nonempty enumeration of individuals.
57    /// # Errors
58    /// Rejects an empty enumeration.
59    pub fn object_one_of(individuals: Vec<Individual<B>>) -> Result<Self, StructuralModelError> {
60        Ok(Self::ObjectOneOf(OperandSet::try_new(individuals)?))
61    }
62    /// Create an object some-values restriction.
63    #[must_use]
64    pub fn object_some_values_from(property: ObjectPropertyExpression, filler: Self) -> Self {
65        Self::ObjectSomeValuesFrom {
66            property,
67            filler: Box::new(filler),
68        }
69    }
70    /// Create an object all-values restriction.
71    #[must_use]
72    pub fn object_all_values_from(property: ObjectPropertyExpression, filler: Self) -> Self {
73        Self::ObjectAllValuesFrom {
74            property,
75            filler: Box::new(filler),
76        }
77    }
78    /// Create an object value restriction.
79    #[must_use]
80    pub fn object_has_value(property: ObjectPropertyExpression, individual: Individual<B>) -> Self {
81        Self::ObjectHasValue {
82            property,
83            individual,
84        }
85    }
86    /// Create a self restriction.
87    #[must_use]
88    pub fn object_has_self(property: ObjectPropertyExpression) -> Self {
89        Self::ObjectHasSelf { property }
90    }
91}