Rust API reference¶
OntoCore exposes a Rust library through the ontocore façade crate and individual ontocore-* implementation crates.
Stability¶
| Surface | Status |
|---|---|
ontocore::Workspace |
Stable since v0.10 — preferred high-level API |
ontocore::catalog::IndexBuilder |
Stable for custom pipelines |
LSP JSON (ontocore/* methods) |
Pre-1.0 — may change between minor releases |
| SQL virtual table columns | Pre-1.0 — pin versions in production |
Pin dependencies in Cargo.toml:
[dependencies]
ontocore = "0.13"
For CI and reproducible builds: cargo install ontocore-cli --locked --version 0.13.0.
docs.rs¶
Generated API documentation is published on docs.rs:
| Crate | docs.rs |
|---|---|
ontocore |
docs.rs/ontocore |
ontocore-core |
docs.rs/ontocore-core |
ontocore-parser |
docs.rs/ontocore-parser |
ontocore-catalog |
docs.rs/ontocore-catalog |
ontocore-diagnostics |
docs.rs/ontocore-diagnostics |
ontocore-query |
docs.rs/ontocore-query |
ontocore-reasoner |
docs.rs/ontocore-reasoner |
ontocore-robot |
docs.rs/ontocore-robot |
ontocore-owl |
docs.rs/ontocore-owl |
ontocore-obo |
docs.rs/ontocore-obo |
ontocore-lsp |
docs.rs/ontocore-lsp |
ontocore-diff |
docs.rs/ontocore-diff |
ontocore-docs |
docs.rs/ontocore-docs |
ontocore-refactor |
docs.rs/ontocore-refactor |
ontocore-plugin |
docs.rs/ontocore-plugin (experimental; Tier D in v0.13) |
ontocore-cli |
docs.rs/ontocore-cli |
Search all crates: crates.io search?q=ontocore.
Book ↔ docs.rs crosswalk¶
Use this book for workflows, limits, and LSP JSON; use docs.rs for Rust type signatures and module layout.
| You need… | Start in the book | Rust API (docs.rs) |
|---|---|---|
| Open and query a workspace | Rust library guide, Workspace engine | Workspace, WorkspaceOptions |
| SQL virtual tables | SQL reference, SQL views | ontocore::query |
| SPARQL | SPARQL reference | Workspace::sparql |
| Turtle patch apply | Patch JSON, Authoring | ontocore::owl |
| OBO patch apply | OBO authoring | ontocore::obo |
| Semantic diff | Semantic diff | ontocore-diff |
| Refactoring | Refactoring guide | ontocore-refactor |
| Docs export | Docs export | ontocore::docs |
| LSP integration | LSP API, LSP overview | ontocore-lsp |
| Custom LSP client | LSP hello world | — |
| Error codes / exit behavior | Errors reference | Crate thiserror types per module |
| Resource limits | Workspace limits | Index builder options in ontocore-catalog |
Recommended entry point: Workspace¶
use ontocore::Workspace;
let ws = Workspace::open("./ontologies")?;
// Catalog stats
let stats = ws.stats();
println!("{} classes", stats.class_count);
// SQL virtual tables
let result = ws.query("SELECT short_name, labels FROM classes")?;
// SPARQL over indexed triples
let sparql = ws.sparql("SELECT ?s ?p ?o WHERE { ?s ?p ?o } LIMIT 10")?;
// Lint diagnostics from indexing
for d in ws.diagnostics() {
println!("{:?}: {}", d.code, d.message);
}
// Entity search by IRI fragment, short name, or label
let hits = ws.search("Person");
WorkspaceOptions¶
use ontocore::{Workspace, WorkspaceOptions};
let ws = Workspace::open_with_options(
WorkspaceOptions::single("./ontology")
.with_disk_cache(true)
.with_scan_roots(vec!["./imports".into()]),
)?;
ws.reindex_incremental()?;
let diff = ws.diff_against_path("./baseline")?;
| Option | Purpose |
|---|---|
single(path) |
Primary workspace root |
with_scan_roots(vec![...]) |
Additional scan roots (primary root is always included) |
with_disk_cache(true) |
Persist parse snapshots under .ontocore/cache/ |
Additional Workspace methods¶
| Method | Purpose |
|---|---|
reindex() / reindex_incremental() |
Full or incremental catalog rebuild |
root() / scan_roots() |
Primary path and effective scan roots |
catalog() |
Direct OntologyCatalog access (advanced) |
import_graph() / import_graph_with(request) |
Graph export for visualization (import, class, property, neighborhood) |
classify(profile) / explain(profile, request) |
Reasoner integration |
reasoner_input() |
Build reasoner snapshot from workspace |
export_docs(options) |
Markdown/HTML documentation export |
discover_plugins() |
Experimental plugin manifest discovery (plugins feature) |
diff(other) / diff_against_path(path) |
Semantic catalog comparison |
Use apply_owl_patches / apply_obo_patches from ontocore::owl and ontocore::obo when importing both patch helpers. Unified errors: ontocore::Error — see examples/error_handling.rs.
Refactoring helpers live in ontocore::refactor (preview_rename_iri, apply_refactor_plan_checked, …). Pass workspace_root from Workspace::root().
Lower-level API¶
When you need buffer overrides, partial rebuilds, or direct catalog access:
use ontocore::catalog::IndexBuilder;
use ontocore::query::query_catalog;
let catalog = IndexBuilder::new().workspace(".").build()?;
let result = query_catalog(&catalog, "SELECT * FROM classes")?;
See Workspace engine for the indexing pipeline and crate map for module boundaries.
Documentation export (docs module)¶
use ontocore::{Workspace, docs::{export_workspace, ExportOptions}};
let ws = Workspace::open("./fixtures")?;
export_workspace(
ws.catalog(),
ExportOptions::markdown("/tmp/onto-docs"),
)?;
See Documentation export guide.
Examples in this repository¶
cargo run -p ontocode --example ontocore_workspace # Workspace API
cargo run -p ontocode --example workspace_operations # classify, graph, docs export
cargo run -p ontocode --example index_and_query # Workspace + SQL query (fixtures/)
cargo run -p ontocode --example error_handling # ontocore::Error handling
cargo run -p ontocode --example semantic_diff # Git/workspace semantic diff (requires git repo)
See Examples index for CLI cookbooks and fixture workflows.
Related guides¶
| Topic | Document |
|---|---|
| Embedding walkthrough | Rust library guide |
| CLI and crates overview | Rust & CLI guide |
| LSP wire format | LSP API |
| SQL virtual tables | SQL reference |
| Error codes | Errors reference |
| Resource limits | Workspace limits |