use crate::category::Category;
use crate::category::entity::Entity;
use crate::category::relationship::Relationship;
use super::being::Being;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct OntologicalRelation {
pub from: Being,
pub to: Being,
pub kind: RelationKind,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum RelationKind {
Identity,
ParticipatesIn,
InheresIn,
Constitutes,
PartOf,
Composed,
}
impl OntologicalRelation {
fn new(from: Being, to: Being, kind: RelationKind) -> Self {
Self { from, to, kind }
}
}
impl Relationship for OntologicalRelation {
type Object = Being;
fn source(&self) -> Being {
self.from
}
fn target(&self) -> Being {
self.to
}
}
pub struct DolceCategory;
impl Category for DolceCategory {
type Object = Being;
type Morphism = OntologicalRelation;
fn identity(obj: &Being) -> OntologicalRelation {
OntologicalRelation::new(*obj, *obj, RelationKind::Identity)
}
fn compose(f: &OntologicalRelation, g: &OntologicalRelation) -> Option<OntologicalRelation> {
if f.to != g.from {
return None;
}
if f.kind == RelationKind::Identity {
return Some(g.clone());
}
if g.kind == RelationKind::Identity {
return Some(f.clone());
}
Some(OntologicalRelation::new(
f.from,
g.to,
RelationKind::Composed,
))
}
fn morphisms() -> Vec<OntologicalRelation> {
use Being::*;
use RelationKind::*;
let mut m = Vec::new();
for b in Being::variants() {
m.push(OntologicalRelation::new(b, b, Identity));
}
for endurant in [PhysicalEndurant, SocialObject, MentalObject, AbstractObject] {
for perdurant in [Event, Process] {
m.push(OntologicalRelation::new(
endurant,
perdurant,
ParticipatesIn,
));
}
}
for bearer in [PhysicalEndurant, SocialObject, MentalObject, AbstractObject] {
m.push(OntologicalRelation::new(Quality, bearer, InheresIn));
}
m.push(OntologicalRelation::new(
PhysicalEndurant,
SocialObject,
Constitutes,
));
m.push(OntologicalRelation::new(Event, Process, PartOf));
for perdurant in [Event, Process] {
m.push(OntologicalRelation::new(Quality, perdurant, Composed));
}
for perdurant in [Event, Process] {
m.push(OntologicalRelation::new(
PhysicalEndurant,
perdurant,
Composed,
));
}
m
}
}