Skip to main content

owl_structural_model/
entity.rs

1//! OWL entity declarations.
2
3use iri_rfc3987::Iri;
4
5/// Kind of OWL entity.
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
7pub enum EntityKind {
8    /// OWL class.
9    Class,
10    /// OWL object property.
11    ObjectProperty,
12    /// OWL data property.
13    DataProperty,
14    /// OWL annotation property.
15    AnnotationProperty,
16    /// OWL named individual.
17    NamedIndividual,
18    /// OWL datatype.
19    Datatype,
20}
21
22/// An OWL entity declaration target.
23#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
24pub struct Entity {
25    kind: EntityKind,
26    iri: Iri<String>,
27}
28
29impl Entity {
30    /// Create an entity with a concrete kind and IRI.
31    #[must_use]
32    pub fn new(kind: EntityKind, iri: Iri<String>) -> Self {
33        Self { kind, iri }
34    }
35
36    /// Create an OWL class entity.
37    #[must_use]
38    pub fn class(iri: Iri<String>) -> Self {
39        Self::new(EntityKind::Class, iri)
40    }
41
42    /// Create an OWL object property entity.
43    #[must_use]
44    pub fn object_property(iri: Iri<String>) -> Self {
45        Self::new(EntityKind::ObjectProperty, iri)
46    }
47
48    /// Create an OWL data property entity.
49    #[must_use]
50    pub fn data_property(iri: Iri<String>) -> Self {
51        Self::new(EntityKind::DataProperty, iri)
52    }
53
54    /// Create an OWL annotation property entity.
55    #[must_use]
56    pub fn annotation_property(iri: Iri<String>) -> Self {
57        Self::new(EntityKind::AnnotationProperty, iri)
58    }
59
60    /// Create an OWL named individual entity.
61    #[must_use]
62    pub fn named_individual(iri: Iri<String>) -> Self {
63        Self::new(EntityKind::NamedIndividual, iri)
64    }
65
66    /// Create an OWL datatype entity.
67    #[must_use]
68    pub fn datatype(iri: Iri<String>) -> Self {
69        Self::new(EntityKind::Datatype, iri)
70    }
71
72    /// Return the entity kind.
73    #[must_use]
74    pub fn kind(&self) -> EntityKind {
75        self.kind
76    }
77
78    /// Return the entity IRI.
79    #[must_use]
80    pub fn iri(&self) -> &Iri<String> {
81        &self.iri
82    }
83}