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