-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathhorned_profile.rs
More file actions
169 lines (151 loc) · 6.13 KB
/
Copy pathhorned_profile.rs
File metadata and controls
169 lines (151 loc) · 6.13 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
use clap::App;
use clap::Arg;
use clap::ArgMatches;
use horned_bin::{config::parser_config, parse_path};
use horned_owl::error::HornedError;
use horned_profile::{Profile, ProfileReport, Violation};
use std::collections::BTreeMap;
use std::path::Path;
#[allow(dead_code)]
fn main() -> Result<(), HornedError> {
let matches = app("horned-profile").get_matches();
matcher(&matches)
}
pub(crate) fn app(name: &str) -> App<'static> {
App::new(name)
.version(horned_bin::version_string())
.about("Reports which OWL 2 profile(s) (EL/QL/RL/DL) an ontology conforms to")
.author("Phillip Lord")
.arg(
Arg::with_name("INPUT")
.help("Sets the input file to use")
.required(true)
.index(1),
)
.arg(
Arg::with_name("profile")
.long("profile")
.takes_value(true)
.default_value("all")
.help("Which profile to check: dl, el, ql, rl, or all (default)"),
)
.arg(Arg::with_name("short").long("short").help(
"Only print which profile(s) the ontology conforms to, \
without a violation breakdown",
))
}
pub(crate) fn matcher(matches: &ArgMatches) -> Result<(), HornedError> {
let input = matches
.value_of("INPUT")
.ok_or_else(horned_bin::error::error_missing_input)?;
let o = parse_path(Path::new(input), parser_config(matches))?
.decompose()
.0;
let profiles = match matches.value_of("profile").unwrap_or("all") {
"all" => vec![Profile::OWL2DL, Profile::EL, Profile::QL, Profile::RL],
other => vec![parse_profile(other)?],
};
let short = matches.is_present("short");
for p in profiles {
let report = horned_profile::check(&o, p);
if short {
print_short(profile_name(p), &report);
} else {
print_report(profile_name(p), &report);
}
}
Ok(())
}
fn print_short<A: horned_owl::model::ForIRI>(name: &str, report: &ProfileReport<A>) {
println!(
"{name}: {}",
if report.is_conformant() {
"conformant"
} else {
"not conformant"
}
);
}
fn print_report<A: horned_owl::model::ForIRI>(name: &str, report: &ProfileReport<A>) {
if report.is_conformant() {
println!("{name}: conformant");
return;
}
println!("{name}: {} violation(s)", report.violations().len());
let mut counts: BTreeMap<&'static str, usize> = BTreeMap::new();
for v in report.violations() {
*counts.entry(violation_kind(v)).or_insert(0) += 1;
}
for (kind, count) in counts {
println!(" {kind}: {count}");
}
}
fn parse_profile(s: &str) -> Result<Profile, HornedError> {
match s {
"dl" => Ok(Profile::OWL2DL),
"el" => Ok(Profile::EL),
"ql" => Ok(Profile::QL),
"rl" => Ok(Profile::RL),
other => Err(HornedError::CommandError(format!(
"Unknown profile '{other}': expected one of dl, el, ql, rl, all"
))),
}
}
fn profile_name(p: Profile) -> &'static str {
match p {
Profile::OWL2DL => "OWL 2 DL",
Profile::EL => "OWL 2 EL",
Profile::QL => "OWL 2 QL",
Profile::RL => "OWL 2 RL",
}
}
/// The `Violation` variant's name, for grouping a report's violations by kind.
fn violation_kind<A: horned_owl::model::ForIRI>(v: &Violation<A>) -> &'static str {
match v {
Violation::UseOfNonAtomicClassExpression { .. } => "UseOfNonAtomicClassExpression",
Violation::UseOfNonSubClassExpression { .. } => "UseOfNonSubClassExpression",
Violation::UseOfNonSuperClassExpression { .. } => "UseOfNonSuperClassExpression",
Violation::UseOfIllegalClassExpression { .. } => "UseOfIllegalClassExpression",
Violation::UseOfClassExpressionWithTooFewOperands { .. } => {
"UseOfClassExpressionWithTooFewOperands"
}
Violation::UseOfDataRangeWithTooFewOperands { .. } => "UseOfDataRangeWithTooFewOperands",
Violation::UseOfBuiltinDatatypeInDatatypeDefinition { .. } => {
"UseOfBuiltinDatatypeInDatatypeDefinition"
}
Violation::UseOfNonSimplePropertyInObjectHasSelf { .. } => {
"UseOfNonSimplePropertyInObjectHasSelf"
}
Violation::UseOfNonSimplePropertyInCardinalityRestriction { .. } => {
"UseOfNonSimplePropertyInCardinalityRestriction"
}
Violation::UseOfNonSimplePropertyInDisjointPropertiesAxiom { .. } => {
"UseOfNonSimplePropertyInDisjointPropertiesAxiom"
}
Violation::UseOfNonSimplePropertyInIrreflexivePropertyAxiom { .. } => {
"UseOfNonSimplePropertyInIrreflexivePropertyAxiom"
}
Violation::UseOfNonSimplePropertyInAsymmetricPropertyAxiom { .. } => {
"UseOfNonSimplePropertyInAsymmetricPropertyAxiom"
}
Violation::UseOfNonSimplePropertyInFunctionalPropertyAxiom { .. } => {
"UseOfNonSimplePropertyInFunctionalPropertyAxiom"
}
Violation::UseOfNonSimplePropertyInInverseFunctionalPropertyAxiom { .. } => {
"UseOfNonSimplePropertyInInverseFunctionalPropertyAxiom"
}
Violation::UseOfPropertyInChainCausingCycle { .. } => "UseOfPropertyInChainCausingCycle",
Violation::UseOfUndeclaredClass { .. } => "UseOfUndeclaredClass",
Violation::UseOfUndeclaredObjectProperty { .. } => "UseOfUndeclaredObjectProperty",
Violation::UseOfUndeclaredDataProperty { .. } => "UseOfUndeclaredDataProperty",
Violation::UseOfUndeclaredAnnotationProperty { .. } => "UseOfUndeclaredAnnotationProperty",
Violation::UseOfUndeclaredDatatype { .. } => "UseOfUndeclaredDatatype",
Violation::UseOfIllegalPunning { .. } => "UseOfIllegalPunning",
Violation::UseOfReservedVocabulary { .. } => "UseOfReservedVocabulary",
Violation::UseOfDataOneOfWithMultipleLiterals { .. } => {
"UseOfDataOneOfWithMultipleLiterals"
}
Violation::UseOfObjectPropertyInverse { .. } => "UseOfObjectPropertyInverse",
Violation::UseOfIllegalAxiomKind { .. } => "UseOfIllegalAxiomKind",
}
}