use iri_rfc3987::Iri;
use crate::{OwlLiteral, StructuralModelError};
const KIND_ANONYMOUS_INDIVIDUAL: &str = "anonymous individual";
#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
pub struct Annotation {
property: Iri<String>,
value: AnnotationValue,
}
impl Annotation {
#[must_use]
pub fn new(property: Iri<String>, value: AnnotationValue) -> Self {
Self { property, value }
}
#[must_use]
pub fn property(&self) -> &Iri<String> {
&self.property
}
#[must_use]
pub fn value(&self) -> &AnnotationValue {
&self.value
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
pub enum AnnotationValue {
Iri(Iri<String>),
AnonymousIndividual(String),
Literal(OwlLiteral),
}
impl AnnotationValue {
pub fn anonymous_individual(label: impl Into<String>) -> Result<Self, StructuralModelError> {
let label = label.into();
if label.is_empty() {
return Err(StructuralModelError::Empty {
kind: KIND_ANONYMOUS_INDIVIDUAL,
});
}
Ok(Self::AnonymousIndividual(label))
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
pub enum AnnotationSubject {
Iri(Iri<String>),
AnonymousIndividual(String),
}
#[derive(Debug, Clone, Default, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
pub struct AxiomAnnotations {
annotations: Vec<Annotation>,
}
impl AxiomAnnotations {
#[must_use]
pub fn empty() -> Self {
Self::default()
}
#[must_use]
pub fn new(annotations: Vec<Annotation>) -> Self {
Self { annotations }
}
#[must_use]
pub fn as_slice(&self) -> &[Annotation] {
&self.annotations
}
#[must_use]
pub fn len(&self) -> usize {
self.annotations.len()
}
#[must_use]
pub fn is_empty(&self) -> bool {
self.annotations.is_empty()
}
}