use crate::{
entities::{Class, DataProperty, Individual, ObjectProperty},
fmt::DisplayPretty,
literals::Literal,
ranges::DataRange,
values::UnlimitedNatural,
};
use strum::{EnumIs, EnumTryAs};
#[cfg(not(feature = "std"))]
use alloc::{boxed::Box, vec::Vec};
#[derive(Clone, Debug, PartialEq, EnumIs, EnumTryAs)]
pub enum ObjectPropertyExpression {
ObjectProperty(ObjectProperty),
InverseObjectProperty(InverseObjectProperty),
}
#[derive(Clone, Debug, PartialEq)]
pub struct InverseObjectProperty {
object_property: ObjectProperty,
}
#[derive(Clone, Debug, PartialEq, EnumIs, EnumTryAs)]
pub enum DataPropertyExpression {
DataProperty(DataProperty),
}
#[derive(Clone, Debug, PartialEq, EnumIs, EnumTryAs)]
pub enum ClassExpression {
ObjectIntersectionOf(ObjectIntersectionOf),
ObjectUnionOf(ObjectUnionOf),
ObjectComplementOf(ObjectComplementOf),
ObjectOneOf(ObjectOneOf),
Class(Class),
ObjectSomeValuesFrom(ObjectSomeValuesFrom),
ObjectAllValuesFrom(ObjectAllValuesFrom),
ObjectHasValue(ObjectHasValue),
ObjectHasSelf(ObjectHasSelf),
ObjectMinCardinality(ObjectMinCardinality),
ObjectMaxCardinality(ObjectMaxCardinality),
ObjectExactCardinality(ObjectExactCardinality),
DataSomeValuesFrom(DataSomeValuesFrom),
DataAllValuesFrom(DataAllValuesFrom),
DataHasValue(DataHasValue),
DataMinCardinality(DataMinCardinality),
DataMaxCardinality(DataMaxCardinality),
DataExactCardinality(DataExactCardinality),
}
#[derive(Clone, Debug, PartialEq)]
pub struct ObjectIntersectionOf {
class_expressions: Vec<ClassExpression>, }
#[derive(Clone, Debug, PartialEq)]
pub struct ObjectUnionOf {
class_expressions: Vec<ClassExpression>, }
#[derive(Clone, Debug, PartialEq)]
pub struct ObjectComplementOf {
class_expression: Box<ClassExpression>,
}
#[derive(Clone, Debug, PartialEq)]
pub struct ObjectOneOf {
individuals: Vec<Individual>,
}
#[derive(Clone, Debug, PartialEq)]
pub struct ObjectSomeValuesFrom {
object_property_expression: ObjectPropertyExpression,
class_expression: Box<ClassExpression>,
}
#[derive(Clone, Debug, PartialEq)]
pub struct ObjectAllValuesFrom {
object_property_expression: ObjectPropertyExpression,
class_expression: Box<ClassExpression>,
}
#[derive(Clone, Debug, PartialEq)]
pub struct ObjectHasValue {
object_property_expression: ObjectPropertyExpression,
individual: Individual,
}
#[derive(Clone, Debug, PartialEq)]
pub struct ObjectHasSelf {
object_property_expression: ObjectPropertyExpression,
}
pub trait ObjectPropertyCardinalityRestriction {
fn cardinality(&self) -> UnlimitedNatural;
fn object_property_expression(&self) -> &ObjectPropertyExpression;
fn class_expression(&self) -> Option<&Box<ClassExpression>>;
}
#[derive(Clone, Debug, PartialEq)]
pub struct ObjectMinCardinality {
cardinality: UnlimitedNatural,
object_property_expression: ObjectPropertyExpression,
class_expression: Option<Box<ClassExpression>>,
}
#[derive(Clone, Debug, PartialEq)]
pub struct ObjectMaxCardinality {
cardinality: UnlimitedNatural,
object_property_expression: ObjectPropertyExpression,
class_expression: Option<Box<ClassExpression>>,
}
#[derive(Clone, Debug, PartialEq)]
pub struct ObjectExactCardinality {
cardinality: UnlimitedNatural,
object_property_expression: ObjectPropertyExpression,
class_expression: Option<Box<ClassExpression>>,
}
#[derive(Clone, Debug, PartialEq)]
pub struct DataSomeValuesFrom {
data_range: DataRange,
data_property_expressions: Vec<DataPropertyExpression>, }
#[derive(Clone, Debug, PartialEq)]
pub struct DataAllValuesFrom {
data_range: DataRange,
data_property_expressions: Vec<DataPropertyExpression>, }
#[derive(Clone, Debug, PartialEq)]
pub struct DataHasValue {
data_property_expression: DataPropertyExpression,
literal: Literal,
}
pub trait DataPropertyCardinalityRestriction {
fn cardinality(&self) -> UnlimitedNatural;
fn data_property_expression(&self) -> &DataPropertyExpression;
fn data_range(&self) -> Option<&DataRange>;
}
#[derive(Clone, Debug, PartialEq)]
pub struct DataMinCardinality {
cardinality: UnlimitedNatural,
data_range: Option<DataRange>,
data_property_expression: DataPropertyExpression,
}
#[derive(Clone, Debug, PartialEq)]
pub struct DataMaxCardinality {
cardinality: UnlimitedNatural,
data_range: Option<DataRange>,
data_property_expression: DataPropertyExpression,
}
#[derive(Clone, Debug, PartialEq)]
pub struct DataExactCardinality {
cardinality: UnlimitedNatural,
data_range: Option<DataRange>,
data_property_expression: DataPropertyExpression,
}
impl_display_pretty!(ObjectPropertyExpression enum ObjectProperty, InverseObjectProperty);
impl_display_pretty!(InverseObjectProperty(object_property));
impl InverseObjectProperty {
pub fn new(object_property: ObjectProperty) -> Self {
Self { object_property }
}
pub fn object_property(&self) -> &ObjectProperty {
&self.object_property
}
}
impl_display_pretty!(DataPropertyExpression enum DataProperty);
impl_display_pretty!(
ClassExpression enum ObjectIntersectionOf,
ObjectUnionOf,
ObjectComplementOf,
ObjectOneOf,
Class,
ObjectSomeValuesFrom,
ObjectAllValuesFrom,
ObjectHasValue,
ObjectHasSelf,
ObjectMinCardinality,
ObjectMaxCardinality,
ObjectExactCardinality,
DataSomeValuesFrom,
DataAllValuesFrom,
DataHasValue,
DataMinCardinality,
DataMaxCardinality,
DataExactCardinality
);
impl_from_for_variant!(ClassExpression, ObjectIntersectionOf);
impl_from_for_variant!(ClassExpression, ObjectUnionOf);
impl_from_for_variant!(ClassExpression, ObjectComplementOf);
impl_from_for_variant!(ClassExpression, ObjectOneOf);
impl_from_for_variant!(ClassExpression, Class);
impl_from_for_variant!(ClassExpression, ObjectSomeValuesFrom);
impl_from_for_variant!(ClassExpression, ObjectAllValuesFrom);
impl_from_for_variant!(ClassExpression, ObjectHasValue);
impl_from_for_variant!(ClassExpression, ObjectHasSelf);
impl_from_for_variant!(ClassExpression, ObjectMinCardinality);
impl_from_for_variant!(ClassExpression, ObjectMaxCardinality);
impl_from_for_variant!(ClassExpression, ObjectExactCardinality);
impl_from_for_variant!(ClassExpression, DataSomeValuesFrom);
impl_from_for_variant!(ClassExpression, DataAllValuesFrom);
impl_from_for_variant!(ClassExpression, DataHasValue);
impl_from_for_variant!(ClassExpression, DataMinCardinality);
impl_from_for_variant!(ClassExpression, DataMaxCardinality);
impl_from_for_variant!(ClassExpression, DataExactCardinality);
impl_display_pretty!(ObjectIntersectionOf( @list class_expressions ));
impl ObjectIntersectionOf {
pub fn new<I: IntoIterator<Item = ClassExpression>>(expressions: I) -> Self {
Self {
class_expressions: expressions.into_iter().collect(),
}
}
pub fn class_expressions(&self) -> impl Iterator<Item = &ClassExpression> {
self.class_expressions.iter()
}
}
impl_display_pretty!(ObjectUnionOf( @list class_expressions ));
impl ObjectUnionOf {
pub fn new<I: IntoIterator<Item = ClassExpression>>(expressions: I) -> Self {
Self {
class_expressions: expressions.into_iter().collect(),
}
}
pub fn class_expressions(&self) -> impl Iterator<Item = &ClassExpression> {
self.class_expressions.iter()
}
}
impl_display_pretty!(ObjectComplementOf(class_expression));
impl ObjectComplementOf {
pub fn new(class_expression: ClassExpression) -> Self {
Self {
class_expression: Box::new(class_expression),
}
}
pub fn class_expression(&self) -> &ClassExpression {
&self.class_expression
}
}
impl_display_pretty!(ObjectOneOf( @list individuals ));
impl ObjectOneOf {
pub fn new<I: IntoIterator<Item = Individual>>(individuals: I) -> Self {
Self {
individuals: individuals.into_iter().collect(),
}
}
pub fn individuals(&self) -> impl Iterator<Item = &Individual> {
self.individuals.iter()
}
}
impl_display_pretty!(ObjectSomeValuesFrom(
object_property_expression,
class_expression
));
impl ObjectSomeValuesFrom {
pub fn new(ope: ObjectPropertyExpression, ce: ClassExpression) -> Self {
Self {
object_property_expression: ope,
class_expression: Box::new(ce),
}
}
pub fn object_property_expression(&self) -> &ObjectPropertyExpression {
&self.object_property_expression
}
pub fn class_expression(&self) -> &ClassExpression {
&self.class_expression
}
}
impl_display_pretty!(ObjectAllValuesFrom(
object_property_expression,
class_expression
));
impl ObjectAllValuesFrom {
pub fn new(ope: ObjectPropertyExpression, ce: ClassExpression) -> Self {
Self {
object_property_expression: ope,
class_expression: Box::new(ce),
}
}
pub fn object_property_expression(&self) -> &ObjectPropertyExpression {
&self.object_property_expression
}
pub fn class_expression(&self) -> &ClassExpression {
&self.class_expression
}
}
impl_display_pretty!(ObjectHasValue(object_property_expression, individual));
impl ObjectHasValue {
pub fn new(ope: ObjectPropertyExpression, individual: Individual) -> Self {
Self {
object_property_expression: ope,
individual,
}
}
pub fn object_property_expression(&self) -> &ObjectPropertyExpression {
&self.object_property_expression
}
pub fn individual(&self) -> &Individual {
&self.individual
}
}
impl_display_pretty!(ObjectHasSelf(object_property_expression));
impl ObjectHasSelf {
pub fn new(ope: ObjectPropertyExpression) -> Self {
Self {
object_property_expression: ope,
}
}
pub fn object_property_expression(&self) -> &ObjectPropertyExpression {
&self.object_property_expression
}
}
impl_display_pretty!(ObjectMinCardinality( @display cardinality, object_property_expression, @optional class_expression ));
impl ObjectPropertyCardinalityRestriction for ObjectMinCardinality {
fn cardinality(&self) -> UnlimitedNatural {
self.cardinality
}
fn object_property_expression(&self) -> &ObjectPropertyExpression {
&self.object_property_expression
}
fn class_expression(&self) -> Option<&Box<ClassExpression>> {
self.class_expression.as_ref()
}
}
impl ObjectMinCardinality {
pub fn new(
cardinality: u32,
object_property_expression: ObjectPropertyExpression,
class_expression: Option<ClassExpression>,
) -> Self {
Self {
cardinality: UnlimitedNatural::Limited(cardinality as u128),
object_property_expression,
class_expression: class_expression.map(Box::new),
}
}
}
impl_display_pretty!(ObjectMaxCardinality( @display cardinality, object_property_expression, @optional class_expression ));
impl ObjectPropertyCardinalityRestriction for ObjectMaxCardinality {
fn cardinality(&self) -> UnlimitedNatural {
self.cardinality
}
fn object_property_expression(&self) -> &ObjectPropertyExpression {
&self.object_property_expression
}
fn class_expression(&self) -> Option<&Box<ClassExpression>> {
self.class_expression.as_ref()
}
}
impl ObjectMaxCardinality {
pub fn new(
cardinality: u32,
object_property_expression: ObjectPropertyExpression,
class_expression: Option<ClassExpression>,
) -> Self {
Self {
cardinality: UnlimitedNatural::Limited(cardinality as u128),
object_property_expression,
class_expression: class_expression.map(Box::new),
}
}
}
impl_display_pretty!(ObjectExactCardinality( @display cardinality, object_property_expression, @optional class_expression ));
impl ObjectPropertyCardinalityRestriction for ObjectExactCardinality {
fn cardinality(&self) -> UnlimitedNatural {
self.cardinality
}
fn object_property_expression(&self) -> &ObjectPropertyExpression {
&self.object_property_expression
}
fn class_expression(&self) -> Option<&Box<ClassExpression>> {
self.class_expression.as_ref()
}
}
impl ObjectExactCardinality {
pub fn new(
cardinality: u32,
object_property_expression: ObjectPropertyExpression,
class_expression: Option<ClassExpression>,
) -> Self {
Self {
cardinality: UnlimitedNatural::Limited(cardinality as u128),
object_property_expression,
class_expression: class_expression.map(Box::new),
}
}
}
impl_display_pretty!(DataSomeValuesFrom( @list data_property_expressions, data_range ));
impl DataSomeValuesFrom {
pub fn new<I: IntoIterator<Item = DataPropertyExpression>>(dpes: I, dr: DataRange) -> Self {
Self {
data_property_expressions: dpes.into_iter().collect(),
data_range: dr,
}
}
pub fn data_range(&self) -> &DataRange {
&self.data_range
}
pub fn data_property_expressions(&self) -> impl Iterator<Item = &DataPropertyExpression> {
self.data_property_expressions.iter()
}
}
impl_display_pretty!(DataAllValuesFrom( @list data_property_expressions, data_range ));
impl DataAllValuesFrom {
pub fn new<I: IntoIterator<Item = DataPropertyExpression>>(dpes: I, dr: DataRange) -> Self {
Self {
data_property_expressions: dpes.into_iter().collect(),
data_range: dr,
}
}
pub fn data_range(&self) -> &DataRange {
&self.data_range
}
pub fn data_property_expressions(&self) -> impl Iterator<Item = &DataPropertyExpression> {
self.data_property_expressions.iter()
}
}
impl_display_pretty!(DataHasValue(data_property_expression, literal));
impl DataHasValue {
pub fn new(dpe: DataPropertyExpression, literal: Literal) -> Self {
Self {
data_property_expression: dpe,
literal,
}
}
pub fn literal(&self) -> &Literal {
&self.literal
}
pub fn data_property_expression(&self) -> &DataPropertyExpression {
&self.data_property_expression
}
}
impl_display_pretty!(
DataMinCardinality( data_property_expression, @optional data_range, @display cardinality )
);
impl DataPropertyCardinalityRestriction for DataMinCardinality {
fn cardinality(&self) -> UnlimitedNatural {
self.cardinality
}
fn data_property_expression(&self) -> &DataPropertyExpression {
&self.data_property_expression
}
fn data_range(&self) -> Option<&DataRange> {
self.data_range.as_ref()
}
}
impl DataMinCardinality {
pub fn new(n: u32, dpe: DataPropertyExpression, dr: Option<DataRange>) -> Self {
Self {
cardinality: UnlimitedNatural::Limited(n as u128),
data_property_expression: dpe,
data_range: dr,
}
}
}
impl_display_pretty!(
DataMaxCardinality( data_property_expression, @optional data_range, @display cardinality )
);
impl DataPropertyCardinalityRestriction for DataMaxCardinality {
fn cardinality(&self) -> UnlimitedNatural {
self.cardinality
}
fn data_property_expression(&self) -> &DataPropertyExpression {
&self.data_property_expression
}
fn data_range(&self) -> Option<&DataRange> {
self.data_range.as_ref()
}
}
impl DataMaxCardinality {
pub fn new(n: u32, dpe: DataPropertyExpression, dr: Option<DataRange>) -> Self {
Self {
cardinality: UnlimitedNatural::Limited(n as u128),
data_property_expression: dpe,
data_range: dr,
}
}
}
impl_display_pretty!(
DataExactCardinality( data_property_expression, @optional data_range, @display cardinality )
);
impl DataPropertyCardinalityRestriction for DataExactCardinality {
fn cardinality(&self) -> UnlimitedNatural {
self.cardinality
}
fn data_property_expression(&self) -> &DataPropertyExpression {
&self.data_property_expression
}
fn data_range(&self) -> Option<&DataRange> {
self.data_range.as_ref()
}
}
impl DataExactCardinality {
pub fn new(n: u32, dpe: DataPropertyExpression, dr: Option<DataRange>) -> Self {
Self {
cardinality: UnlimitedNatural::Limited(n as u128),
data_property_expression: dpe,
data_range: dr,
}
}
}