owl_structural_model/
annotation.rs1use iri_rfc3987::Iri;
4
5use crate::{BlankNodeId, OwlLiteral};
6
7#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
9pub struct Annotation<L = OwlLiteral, B = BlankNodeId> {
10 property: Iri<String>,
11 value: AnnotationValue<L, B>,
12}
13
14impl<L, B> Annotation<L, B> {
15 #[must_use]
17 pub fn new(property: Iri<String>, value: AnnotationValue<L, B>) -> Self {
18 Self { property, value }
19 }
20
21 #[must_use]
23 pub fn property(&self) -> &Iri<String> {
24 &self.property
25 }
26
27 #[must_use]
29 pub fn value(&self) -> &AnnotationValue<L, B> {
30 &self.value
31 }
32}
33
34#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
36pub enum AnnotationValue<L = OwlLiteral, B = BlankNodeId> {
37 Iri(Iri<String>),
39 AnonymousIndividual(B),
41 Literal(L),
43}
44
45impl<L, B> AnnotationValue<L, B> {
46 #[must_use]
48 pub fn anonymous_individual(identity: B) -> Self {
49 Self::AnonymousIndividual(identity)
50 }
51}
52
53#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
55pub enum AnnotationSubject<B = BlankNodeId> {
56 Iri(Iri<String>),
58 AnonymousIndividual(B),
60}
61
62#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
64pub struct AxiomAnnotations<L = OwlLiteral, B = BlankNodeId> {
65 annotations: Vec<Annotation<L, B>>,
67}
68
69impl<L, B> AxiomAnnotations<L, B> {
70 #[must_use]
72 pub fn empty() -> Self {
73 Self::default()
74 }
75
76 #[must_use]
78 pub fn new(annotations: Vec<Annotation<L, B>>) -> Self {
79 Self { annotations }
80 }
81
82 #[must_use]
84 pub fn as_slice(&self) -> &[Annotation<L, B>] {
85 &self.annotations
86 }
87
88 #[must_use]
90 pub fn len(&self) -> usize {
91 self.annotations.len()
92 }
93
94 #[must_use]
96 pub fn is_empty(&self) -> bool {
97 self.annotations.is_empty()
98 }
99}
100
101impl<L, B> Default for AxiomAnnotations<L, B> {
102 fn default() -> Self {
103 Self {
104 annotations: Vec::new(),
105 }
106 }
107}