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 { Self { property, value } }
20
21 #[must_use]
23 pub fn property(&self) -> &Iri<String> { &self.property }
24
25 #[must_use]
27 pub fn value(&self) -> &AnnotationValue { &self.value }
28}
29
30#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
32pub enum AnnotationValue {
33 Iri(Iri<String>),
35 AnonymousIndividual(String),
37 Literal(OwlLiteral),
39}
40
41impl AnnotationValue {
42 pub fn anonymous_individual(label: impl Into<String>) -> Result<Self, StructuralModelError> {
48 let label = label.into();
49 if label.is_empty() {
50 return Err(StructuralModelError::Empty { kind: KIND_ANONYMOUS_INDIVIDUAL });
51 }
52 Ok(Self::AnonymousIndividual(label))
53 }
54}
55
56#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
58pub enum AnnotationSubject {
59 Iri(Iri<String>),
61 AnonymousIndividual(String),
63}
64
65#[derive(Debug, Clone, Default, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
67pub struct AxiomAnnotations {
68 annotations: Vec<Annotation>,
70}
71
72impl AxiomAnnotations {
73 #[must_use]
75 pub fn empty() -> Self { Self::default() }
76
77 #[must_use]
79 pub fn new(annotations: Vec<Annotation>) -> Self { Self { annotations } }
80
81 #[must_use]
83 pub fn as_slice(&self) -> &[Annotation] { &self.annotations }
84
85 #[must_use]
87 pub fn len(&self) -> usize { self.annotations.len() }
88
89 #[must_use]
91 pub fn is_empty(&self) -> bool { self.annotations.is_empty() }
92}
93