use iri_rfc3987::Iri;
use crate::{BlankNodeId, OperandSet, OwlLiteral};
#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Annotation<L = OwlLiteral, B = BlankNodeId> {
annotations: AxiomAnnotations<L, B>,
property: Iri<String>,
value: AnnotationValue<L, B>,
}
impl<L, B> Annotation<L, B> {
#[must_use]
pub fn new(property: Iri<String>, value: AnnotationValue<L, B>) -> Self {
Self {
annotations: AxiomAnnotations::empty(),
property,
value,
}
}
#[must_use]
pub fn with_annotations(mut self, annotations: AxiomAnnotations<L, B>) -> Self {
self.annotations = annotations;
self
}
#[must_use]
pub fn annotations(&self) -> &AxiomAnnotations<L, B> {
&self.annotations
}
#[must_use]
pub fn property(&self) -> &Iri<String> {
&self.property
}
#[must_use]
pub fn value(&self) -> &AnnotationValue<L, B> {
&self.value
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
#[serde(deny_unknown_fields)]
pub enum AnnotationValue<L = OwlLiteral, B = BlankNodeId> {
Iri(Iri<String>),
AnonymousIndividual(B),
Literal(L),
}
impl<L, B> AnnotationValue<L, B> {
#[must_use]
pub fn anonymous_individual(identity: B) -> Self {
Self::AnonymousIndividual(identity)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
#[serde(deny_unknown_fields)]
pub enum AnnotationSubject<B = BlankNodeId> {
Iri(Iri<String>),
AnonymousIndividual(B),
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
#[serde(deny_unknown_fields)]
pub struct AxiomAnnotations<L = OwlLiteral, B = BlankNodeId> {
annotations: OperandSet<Annotation<L, B>>,
}
impl<L, B> AxiomAnnotations<L, B> {
#[must_use]
pub fn empty() -> Self {
Self::default()
}
#[must_use]
pub fn new(annotations: Vec<Annotation<L, B>>) -> Self {
Self {
annotations: OperandSet::new(annotations),
}
}
#[must_use]
pub fn as_slice(&self) -> &[Annotation<L, B>] {
self.annotations.as_slice()
}
#[must_use]
pub fn len(&self) -> usize {
self.annotations.len()
}
#[must_use]
pub fn is_empty(&self) -> bool {
self.annotations.is_empty()
}
}
impl<L, B> Default for AxiomAnnotations<L, B> {
fn default() -> Self {
Self {
annotations: OperandSet::new(Vec::new()),
}
}
}