Skip to content

Commit 99dec7a

Browse files
authored
Merge pull request #6 from gtfierro/new-io
New architecture with extensible IO
2 parents 3088910 + 857fcfb commit 99dec7a

File tree

18 files changed

+1980
-1613
lines changed

18 files changed

+1980
-1613
lines changed

Cargo.lock

Lines changed: 516 additions & 318 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ members = [
77
resolver = "2"
88

99
[workspace.package]
10-
version = "0.1.10"
10+
version = "0.2.0-a1"
1111
authors = ["Gabe Fierro <[email protected]>"]
1212
license = "BSD-3-Clause"
1313
edition = "2021"
@@ -35,7 +35,7 @@ clap = { version = "4.4.18", features = ["derive"] }
3535
derive_builder = "0.20"
3636
oxigraph = "0.4.4"
3737

38-
ontoenv = { version = "0.1.10", path = "lib" }
38+
ontoenv = { version = "0.2.0-a1", path = "lib" }
3939

4040
[profile.profiling]
4141
inherits = "release"

cli/src/main.rs

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use anyhow::Result;
22
use clap::{Parser, Subcommand};
3+
use ontoenv::api::{OntoEnv, ResolveTarget};
34
use ontoenv::config::{Config, EnvironmentConfig};
45
use ontoenv::ontology::{GraphIdentifier, OntologyLocation};
56
use ontoenv::util::write_dataset_to_file;
6-
use ontoenv::OntoEnv;
7-
use oxigraph::model::{NamedNode, NamedNodeRef};
7+
use oxigraph::model::NamedNode;
88
use serde_json;
99
use std::env::current_dir;
1010
use std::fs::File;
@@ -49,15 +49,18 @@ enum Commands {
4949
/// Glob patterns for which files to exclude, defaults to []
5050
#[clap(long, short, num_args = 1..)]
5151
excludes: Vec<String>,
52-
/// Recreate the environment if it already exists
52+
/// Overwrite the environment if it already exists
5353
#[clap(long, short, default_value = "false")]
54-
recreate: bool,
54+
overwrite: bool,
5555
/// A JSON file containing a list of ontologies to add to the environment
5656
#[clap(long = "list", short = 'l')]
5757
ontology_list_file: Option<String>,
5858
/// Do not search for ontologies in the search directories
5959
#[clap(long = "no-search", short = 'n', action)]
6060
no_search: bool,
61+
/// Use a temporary directory for the environment
62+
#[clap(long, short, action)]
63+
temporary: bool,
6164
},
6265
/// Prints the version of the ontoenv binary
6366
Version,
@@ -137,9 +140,10 @@ fn main() -> Result<()> {
137140
offline,
138141
includes,
139142
excludes,
140-
recreate,
143+
overwrite,
141144
ontology_list_file,
142145
no_search,
146+
temporary,
143147
} => {
144148
// if search_directories is empty, use the current directory
145149
let config = Config::new(
@@ -152,15 +156,16 @@ fn main() -> Result<()> {
152156
offline,
153157
policy,
154158
no_search,
159+
temporary,
155160
)?;
156-
let mut env = OntoEnv::new(config, recreate)?;
161+
let mut env = OntoEnv::init(config, overwrite)?;
157162

158163
// if an ontology config file is provided, load it and add the ontologies
159164
if let Some(file) = ontology_list_file {
160165
let file = File::open(file)?;
161166
let config: EnvironmentConfig = serde_json::from_reader(file)?;
162167
for ont in config.ontologies {
163-
env.add(ont.location)?;
168+
env.add(ont.location, true)?;
164169
}
165170
}
166171

@@ -176,16 +181,16 @@ fn main() -> Result<()> {
176181
}
177182
Commands::Status => {
178183
// load env from .ontoenv/ontoenv.json
179-
let path = current_dir()?.join(".ontoenv/ontoenv.json");
180-
let env = OntoEnv::from_file(&path, true)?;
184+
let path = current_dir()?;
185+
let env = OntoEnv::load_from_directory(path)?;
181186
let status = env.status()?;
182187
// pretty print the status
183188
println!("{}", status);
184189
}
185190
Commands::Refresh => {
186191
// load env from .ontoenv/ontoenv.json
187-
let path = current_dir()?.join(".ontoenv/ontoenv.json");
188-
let mut env = OntoEnv::from_file(&path, false)?;
192+
let path = current_dir()?;
193+
let mut env = OntoEnv::load_from_directory(path)?;
189194
env.update()?;
190195
env.save_to_directory()?;
191196
}
@@ -196,23 +201,24 @@ fn main() -> Result<()> {
196201
destination,
197202
} => {
198203
// load env from .ontoenv/ontoenv.json
199-
let path = current_dir()?.join(".ontoenv/ontoenv.json");
204+
let path = current_dir()?;
200205
// if the path doesn't exist, raise an error
201206
if !path.exists() {
202207
return Err(anyhow::anyhow!(
203208
"OntoEnv not found. Run `ontoenv init` to create a new OntoEnv."
204209
));
205210
}
206-
let env = OntoEnv::from_file(&path, true)?;
211+
let env = OntoEnv::load_from_directory(path)?;
207212

208213
// make ontology an IRI
209214
let iri = NamedNode::new(ontology).map_err(|e| anyhow::anyhow!(e.to_string()))?;
210215

211-
let ont = env
212-
.get_ontology_by_name(iri.as_ref())
216+
let graphid = env
217+
.resolve(ResolveTarget::Graph(iri.clone()))
213218
.ok_or(anyhow::anyhow!(format!("Ontology {} not found", iri)))?;
214-
let closure = env.get_dependency_closure(ont.id())?;
215-
let (graph, _successful, failed_imports) = env.get_union_graph(&closure, rewrite_sh_prefixes, remove_owl_imports)?;
219+
let closure = env.get_dependency_closure(&graphid)?;
220+
let (graph, _successful, failed_imports) =
221+
env.get_union_graph(&closure, rewrite_sh_prefixes, remove_owl_imports)?;
216222
if let Some(failed_imports) = failed_imports {
217223
for imp in failed_imports {
218224
eprintln!("{}", imp);
@@ -227,22 +233,22 @@ fn main() -> Result<()> {
227233
}
228234
Commands::Add { url, file } => {
229235
// load env from .ontoenv/ontoenv.json
230-
let path = current_dir()?.join(".ontoenv/ontoenv.json");
231-
let mut env = OntoEnv::from_file(&path, false)?;
236+
let path = current_dir()?;
237+
let mut env = OntoEnv::load_from_directory(path)?;
232238

233239
let location: OntologyLocation = match (url, file) {
234240
(Some(url), None) => OntologyLocation::Url(url),
235241
(None, Some(file)) => OntologyLocation::File(PathBuf::from(file)),
236242
_ => return Err(anyhow::anyhow!("Must specify either --url or --file")),
237243
};
238244

239-
env.add(location)?;
245+
env.add(location, true)?;
240246
env.save_to_directory()?;
241247
}
242248
Commands::ListOntologies => {
243249
// load env from .ontoenv/ontoenv.json
244-
let path = current_dir()?.join(".ontoenv/ontoenv.json");
245-
let env = OntoEnv::from_file(&path, true)?;
250+
let path = current_dir()?;
251+
let env = OntoEnv::load_from_directory(path)?;
246252
// print list of ontology URLs from env.onologies.values() sorted alphabetically
247253
let mut ontologies: Vec<&GraphIdentifier> = env.ontologies().keys().collect();
248254
ontologies.sort_by(|a, b| a.name().cmp(&b.name()));
@@ -253,8 +259,8 @@ fn main() -> Result<()> {
253259
}
254260
Commands::ListLocations => {
255261
// load env from .ontoenv/ontoenv.json
256-
let path = current_dir()?.join(".ontoenv/ontoenv.json");
257-
let env = OntoEnv::from_file(&path, true)?;
262+
let path = current_dir()?;
263+
let env = OntoEnv::load_from_directory(path)?;
258264
let mut ontologies: Vec<&GraphIdentifier> = env.ontologies().keys().collect();
259265
ontologies.sort_by(|a, b| a.location().as_str().cmp(b.location().as_str()));
260266
for ont in ontologies {
@@ -263,21 +269,20 @@ fn main() -> Result<()> {
263269
}
264270
Commands::Dump { contains } => {
265271
// load env from .ontoenv/ontoenv.json
266-
let path = current_dir()?.join(".ontoenv/ontoenv.json");
267-
let env = OntoEnv::from_file(&path, true)?;
272+
let path = current_dir()?;
273+
let env = OntoEnv::load_from_directory(path)?;
268274
env.dump(contains.as_deref());
269275
}
270276
Commands::DepGraph { roots, output } => {
271277
// load env from .ontoenv/ontoenv.json
272-
let path = current_dir()?.join(".ontoenv/ontoenv.json");
273-
let env = OntoEnv::from_file(&path, true)?;
278+
let path = current_dir()?;
279+
let env = OntoEnv::load_from_directory(path)?;
274280
let dot = if let Some(roots) = roots {
275281
let roots: Vec<GraphIdentifier> = roots
276282
.iter()
277283
.map(|iri| {
278-
env.get_ontology_by_name(NamedNodeRef::new(iri).unwrap())
284+
env.resolve(ResolveTarget::Graph(NamedNode::new(iri).unwrap()))
279285
.unwrap()
280-
.id()
281286
.clone()
282287
})
283288
.collect();
@@ -301,8 +306,8 @@ fn main() -> Result<()> {
301306
}
302307
Commands::Dependents { ontologies } => {
303308
// load env from .ontoenv/ontoenv.json
304-
let path = current_dir()?.join(".ontoenv/ontoenv.json");
305-
let env = OntoEnv::from_file(&path, true)?;
309+
let path = current_dir()?;
310+
let env = OntoEnv::load_from_directory(path)?;
306311
for ont in ontologies {
307312
let iri = NamedNode::new(ont).map_err(|e| anyhow::anyhow!(e.to_string()))?;
308313
let dependents = env.get_dependents(&iri)?;
@@ -314,8 +319,8 @@ fn main() -> Result<()> {
314319
}
315320
Commands::Doctor => {
316321
// load env from .ontoenv/ontoenv.json
317-
let path = current_dir()?.join(".ontoenv/ontoenv.json");
318-
let env = OntoEnv::from_file(&path, true)?;
322+
let path = current_dir()?;
323+
let env = OntoEnv::load_from_directory(path)?;
319324
env.doctor();
320325
}
321326
Commands::Reset => {

0 commit comments

Comments
 (0)