-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathhorned_convert.rs
More file actions
66 lines (57 loc) · 1.88 KB
/
Copy pathhorned_convert.rs
File metadata and controls
66 lines (57 loc) · 1.88 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
use clap::App;
use clap::Arg;
use clap::ArgMatches;
use horned_bin::{config::parser_config, parse_path, write};
use horned_owl::error::HornedError;
use horned_owl::ontology::component_mapped::RcComponentMappedOntology;
use std::{fs::File, io::stdout, path::Path};
#[allow(dead_code)]
fn main() -> Result<(), HornedError> {
let matches = app("horned-convert").get_matches();
matcher(&matches)
}
pub(crate) fn app(name: &str) -> App<'static> {
App::new(name)
.version(horned_bin::version_string())
.about("Convert an OWL Ontology between formats")
.author("Phillip Lord")
.arg(
Arg::with_name("INPUT")
.help("Sets the input file to use")
.required(true)
.index(1),
)
.arg(
Arg::with_name("to")
.long("to")
.takes_value(true)
.required(true)
.help(
"The format to convert to: owx, ofn, omn, obo, owl, \
or any RDF syntax oxrdfio supports (ttl, nt, nq, trig, jsonld, n3)",
),
)
.arg(
Arg::with_name("to-file")
.long("to-file")
.takes_value(true)
.help("Write the converted output to this file instead of stdout"),
)
}
pub(crate) fn matcher(matches: &ArgMatches) -> Result<(), HornedError> {
let input = matches.value_of("INPUT").unwrap();
let to = matches.value_of("to").unwrap();
let res = parse_path(Path::new(input), parser_config(matches))?;
let amo: RcComponentMappedOntology = res.into();
match matches.value_of("to-file") {
Some(to_file) => {
write(to, File::create(to_file)?, &amo)?;
}
None => {
write(to, stdout(), &amo)?;
// Finish off nicely
println!();
}
}
Ok(())
}