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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
use crate::ontology::set::SetOntology;
use curie::PrefixMapping;
use failure::Error;
use std::{fs::File, io::BufReader, path::Path};
pub fn parse_path(path: &Path) -> Result<(SetOntology, PrefixMapping), Error> {
let file = File::open(&path)?;
let mut bufreader = BufReader::new(file);
Ok(match path.extension().map(|s| s.to_str()).flatten() {
Some("owx") => super::io::owx::reader::read(&mut bufreader)?,
Some("owl") => super::io::rdf::reader::read(&mut bufreader)
.map(|(o, m)| (
o.into(),
m
))?,
a @ _ => {
eprintln!("Do not know how to parse file with extension: {:?}", a);
todo!()
},
})
}
pub mod naming {
use crate::model::AxiomKind;
use crate::model::AxiomKind::*;
pub fn name(axk: &AxiomKind) -> &'static str {
match axk {
OntologyAnnotation => "Ontology Annotation",
Import => "Import",
DeclareClass => "Declare Class",
DeclareObjectProperty => "Declare Object Property",
DeclareAnnotationProperty => "Declare Annotation Property",
DeclareDataProperty => "Declare Data Property",
DeclareNamedIndividual => "Declare Named Individual",
DeclareDatatype => "Declare Datatype",
SubClassOf => "Sub-Class Of",
EquivalentClasses => "Equivalent Classes",
DisjointClasses => "Disjoint Classes",
DisjointUnion => "Disjoint Union",
SubObjectPropertyOf => "Sub Object Property Of",
EquivalentObjectProperties => "Equivalent Object Properties",
DisjointObjectProperties => "Disjoint Object Properties",
InverseObjectProperties => "Inverse Object Properties",
ObjectPropertyDomain => "Object Property Domain",
ObjectPropertyRange => "Object Property Range",
FunctionalObjectProperty => "Functional Object Property",
InverseFunctionalObjectProperty => "Inverse Functional Object Property",
ReflexiveObjectProperty => "Reflexive Object Property",
IrreflexiveObjectProperty => "Irreflexive Object Property",
SymmetricObjectProperty => "Symmetric Object Property",
AsymmetricObjectProperty => "Assymmetric Object Property",
TransitiveObjectProperty => "Transitive Object Property",
SubDataPropertyOf => "Sub Data Property Of",
EquivalentDataProperties => "Equivalent Data Properties",
DisjointDataProperties => "Disjoint Data Properties",
DataPropertyDomain => "Data Property Domain",
DataPropertyRange => "Data Property Range",
FunctionalDataProperty => "Functional Data Property",
DatatypeDefinition => "Datatype Definition",
HasKey => "Has Key",
SameIndividual => "Same Individual",
DifferentIndividuals => "Different Individuals",
ClassAssertion => "Class Assertion",
ObjectPropertyAssertion => "Object Property Assertion",
NegativeObjectPropertyAssertion => "Negative Object Property Assertion",
DataPropertyAssertion => "Data Property Assertion",
NegativeDataPropertyAssertion => "Negative Data Property Assertion",
AnnotationAssertion => "Annotation Assertion",
SubAnnotationPropertyOf => "Sub Annotation Property Of",
AnnotationPropertyDomain => "Annotation Property Domain",
AnnotationPropertyRange => "Annotation Property Range",
}
}
}
pub mod summary {
use crate::{model::AxiomKind, ontology::axiom_mapped::AxiomMappedOntology};
use indexmap::map::IndexMap;
#[derive(Debug)]
pub struct SummaryStatistics {
pub logical_axiom: usize,
pub annotation_axiom: usize,
pub axiom_type: IndexMap<AxiomKind, usize>,
}
impl SummaryStatistics {
pub fn with_axiom_types(&self) -> impl Iterator<Item = (&AxiomKind, &usize)> + '_ {
self.axiom_type.iter().filter(|&(_, v)| v > &0)
}
}
pub fn summarize<O: Into<AxiomMappedOntology>>(ont: O) -> SummaryStatistics
where
O: ,
{
let ont: AxiomMappedOntology = ont.into();
SummaryStatistics {
logical_axiom: ont.i().iter().count(),
annotation_axiom: ont
.i()
.iter()
.map(|aa| aa.ann.iter().count())
.sum::<usize>(),
axiom_type: axiom_types(ont),
}
}
fn axiom_types<O: Into<AxiomMappedOntology>>(ont: O) -> IndexMap<AxiomKind, usize> {
let ont: AxiomMappedOntology = ont.into();
let mut im = IndexMap::new();
for ax in AxiomKind::all_kinds() {
im.insert(ax, ont.i().axiom(ax).count());
}
im
}
}