1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use crate::owl::{Axiom, Declaration, IRIBuilder, IRI};
#[cfg(feature = "wasm")]
#[wasm_bindgen::prelude::wasm_bindgen]
#[derive(Debug, Serialize, Deserialize)]
pub struct Ontology {
pub(crate) iri: IRI,
pub(crate) imports: HashMap<String, IRI>,
pub(crate) owl: crate::owl::Ontology,
}
#[cfg(not(feature = "wasm"))]
#[derive(Debug, Serialize, Deserialize)]
pub struct Ontology {
pub(crate) iri: IRI,
pub(crate) imports: HashMap<String, IRI>,
pub(crate) owl: crate::owl::Ontology,
}
impl Ontology {
pub fn new(iri: IRI) -> Self {
Self {
iri,
imports: Default::default(),
owl: crate::owl::Ontology::new(vec![], vec![]),
}
}
pub fn imports(&self) -> &HashMap<String, IRI> {
&self.imports
}
pub fn push_import(&mut self, name: &str, iri: IRI) -> Option<IRI> {
self.imports.insert(name.into(), iri)
}
pub fn iri_builder(&self) -> IRIBuilder {
IRIBuilder::construct(self.iri.clone(), &self.imports)
}
pub fn declarations(&self) -> &Vec<Declaration> {
&self.owl.declarations
}
pub fn axioms(&self) -> &Vec<Axiom> {
&self.owl.axioms
}
}
impl Ontology {
pub fn set_owl(&mut self, owl: crate::owl::Ontology) {
self.owl = owl
}
pub fn push_axiom(&mut self, axiom: Axiom) {
self.owl.axioms.push(axiom)
}
pub fn push_declaration(&mut self, declaration: Declaration) {
self.owl.declarations.push(declaration)
}
}
impl From<(IRI, crate::owl::Ontology)> for Ontology {
fn from((iri, owl): (IRI, crate::owl::Ontology)) -> Self {
Self {
iri,
imports: Default::default(),
owl,
}
}
}