use iri_rfc3987::Iri;
use crate::{Annotation, Axiom, OntologyId, StructuralModelError};
const KIND_ONTOLOGY_PATCH: &str = "ontology patch";
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct OntologyPatch {
target: OntologyId,
operations: Vec<OntologyPatchOperation>,
}
impl OntologyPatch {
pub fn try_new(
target: OntologyId,
operations: Vec<OntologyPatchOperation>,
) -> Result<Self, StructuralModelError> {
if operations.is_empty() {
return Err(StructuralModelError::InvalidFormat {
kind: KIND_ONTOLOGY_PATCH,
value: "0 operations".to_owned(),
message: "requires at least one operation",
});
}
Ok(Self { target, operations })
}
#[must_use]
pub fn target(&self) -> &OntologyId { &self.target }
#[must_use]
pub fn operations(&self) -> &[OntologyPatchOperation] { &self.operations }
}
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum OntologyPatchOperation {
AddImport {
import_iri: Iri<String>,
},
RemoveImport {
import_iri: Iri<String>,
},
AddAnnotation {
annotation: Annotation,
},
RemoveAnnotation {
annotation: Annotation,
},
AddAxiom {
axiom: Axiom,
},
RemoveAxiom {
axiom: Axiom,
},
}