owl_structural_model/
annotation.rs1use iri_rfc3987::Iri;
4
5use crate::{OwlLiteral, StructuralModelError};
6
7const KIND_ANONYMOUS_INDIVIDUAL: &str = "anonymous individual";
8
9#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
11pub struct Annotation {
12 property: Iri<String>,
13 value: AnnotationValue,
14}
15
16impl Annotation {
17 #[must_use]
19 pub fn new(property: Iri<String>, value: AnnotationValue) -> Self {
20 Self { property, value }
21 }
22
23 #[must_use]
25 pub fn property(&self) -> &Iri<String> {
26 &self.property
27 }
28
29 #[must_use]
31 pub fn value(&self) -> &AnnotationValue {
32 &self.value
33 }
34}
35
36#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
38pub enum AnnotationValue {
39 Iri(Iri<String>),
41 AnonymousIndividual(String),
43 Literal(OwlLiteral),
45}
46
47impl AnnotationValue {
48 pub fn anonymous_individual(label: impl Into<String>) -> Result<Self, StructuralModelError> {
54 let label = label.into();
55 if label.is_empty() {
56 return Err(StructuralModelError::Empty {
57 kind: KIND_ANONYMOUS_INDIVIDUAL,
58 });
59 }
60 Ok(Self::AnonymousIndividual(label))
61 }
62}
63
64#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
66pub enum AnnotationSubject {
67 Iri(Iri<String>),
69 AnonymousIndividual(String),
71}
72
73#[derive(Debug, Clone, Default, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
75pub struct AxiomAnnotations {
76 annotations: Vec<Annotation>,
78}
79
80impl AxiomAnnotations {
81 #[must_use]
83 pub fn empty() -> Self {
84 Self::default()
85 }
86
87 #[must_use]
89 pub fn new(annotations: Vec<Annotation>) -> Self {
90 Self { annotations }
91 }
92
93 #[must_use]
95 pub fn as_slice(&self) -> &[Annotation] {
96 &self.annotations
97 }
98
99 #[must_use]
101 pub fn len(&self) -> usize {
102 self.annotations.len()
103 }
104
105 #[must_use]
107 pub fn is_empty(&self) -> bool {
108 self.annotations.is_empty()
109 }
110}