Skip to content

Commit db664c6

Browse files
fix: Fix doc tests by marking shell examples and adding Rust usage example
Co-authored-by: aider (gemini/gemini-2.5-pro) <[email protected]>
1 parent 6c5462f commit db664c6

File tree

1 file changed

+60
-3
lines changed

1 file changed

+60
-3
lines changed

README.md

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ It saves this in a local [Oxigraph](https://github.com/oxigraph/oxigraph) databa
4646

4747
Begin by initializing an `ontoenv` workspace in a directory containing some ontology files (Turtle files, etc).
4848

49-
```
49+
```sh
5050
ontoenv init
5151
```
5252

5353
This may take a couple minutes. `ontoenv` searches for all local files defining ontologies, identifies their dependencies, and then recursively pulls in those dependencies, *their* dependencies, and so on. It is possible to adjust which directories `ontoenv` searches for, which files it traverses, and whether it pulls ontologies from the web.
5454

55-
```
55+
```sh
5656
$ ontoenv init -h
5757
Create a new ontology environment
5858

@@ -95,7 +95,7 @@ We refer to the resulting "unified graph" as the *imports closure*.
9595
`ontoenv closure <root ontology name>` computes the imports closure and places it into an `output.ttl` file (or a location of your choice).
9696
There are a several flags one can provide for this process
9797
98-
```
98+
```sh
9999
$ Compute the owl:imports closure of an ontology and write it to a file
100100
101101
Usage: ontoenv closure [OPTIONS] <ONTOLOGY> [DESTINATION]
@@ -166,3 +166,60 @@ for graphname in ds.graphs():
166166
## Rust Library
167167
168168
[Docs](https://docs.rs/crate/ontoenv)
169+
170+
### Usage
171+
172+
Here is a basic example of how to use the `ontoenv` Rust library. This example will:
173+
1. Create a temporary directory.
174+
2. Write a simple ontology to a file in that directory.
175+
3. Configure and initialize `ontoenv` to use this directory.
176+
4. Verify that the ontology has been loaded correctly.
177+
178+
```rust
179+
use ontoenv::config::Config;
180+
use ontoenv::api::OntoEnv;
181+
use std::path::PathBuf;
182+
use std::fs;
183+
use std::io::Write;
184+
185+
# fn main() -> anyhow::Result<()> {
186+
// Set up a temporary directory for the example
187+
let test_dir = PathBuf::from("target/doc_test_temp_readme");
188+
if test_dir.exists() {
189+
fs::remove_dir_all(&test_dir)?;
190+
}
191+
fs::create_dir_all(&test_dir)?;
192+
let root = test_dir.canonicalize()?;
193+
194+
// Create a dummy ontology file
195+
let ontology_path = root.join("my_ontology.ttl");
196+
let mut file = fs::File::create(&ontology_path)?;
197+
writeln!(file, r#"
198+
@prefix owl: <http://www.w3.org/2002/07/owl#> .
199+
@prefix : <http://example.com/my_ontology#> .
200+
201+
<http://example.com/my_ontology> a owl:Ontology .
202+
"#)?;
203+
204+
// Configure ontoenv
205+
let config = Config::builder()
206+
.root(root.clone())
207+
.locations(vec![root.clone()])
208+
.temporary(true) // Use a temporary environment
209+
.build()?;
210+
211+
// Initialize the environment
212+
let mut env = OntoEnv::init(config, false)?;
213+
env.update()?;
214+
215+
// Check that our ontology was loaded
216+
let ontologies = env.ontologies();
217+
assert_eq!(ontologies.len(), 1);
218+
let ont_name = ontologies.keys().next().unwrap().name();
219+
assert_eq!(ont_name.as_str(), "http://example.com/my_ontology");
220+
221+
// Clean up
222+
fs::remove_dir_all(&test_dir)?;
223+
# Ok(())
224+
# }
225+
```

0 commit comments

Comments
 (0)