WebAssembly Guide¶
Browser bindings ship as @ontologos/wasm on npm. Shared logic lives in ontologos-js; the WASM crate is a thin wasm-bindgen wrapper. The .wasm module is also on Wasmer as eddiethedean/ontologos.
Install¶
| Channel | How |
|---|---|
| npm | @ontologos/wasm — JS glue + .wasm |
| Wasmer | wasmer.io/eddiethedean/ontologos — .wasm module 1.1.4 |
| Source | Build with wasm-pack (below) |
Note: The first
@ontologos/wasm@1.1.4npm tarball omittedpkg/(wasm-packpkg/.gitignore). Prefer a source build or Wasmer for the.wasmbinary until a corrected release ships. For Node, useontologoson npm.
Build¶
# Install wasm-pack: https://rustwasm.github.io/wasm-pack/installer/
cd crates/ontologos-wasm
npm install
npm run build # wasm-pack build --target web --out-dir pkg
npm test
The release artifact is large when DL support is included — expect multi‑MB .wasm files. EL/RL-only browser builds may be slimmed in a future release.
Registries¶
On each v*.*.* tag (or via Publish npm / Publish Wasmer workflows), CI publishes:
- npm
@ontologos/wasm— see npmjs.com/package/@ontologos/wasm - Wasmer
eddiethedean/ontologos— seewasmer.toml
The Wasmer package is a wasm-bindgen module (abi = "none"), not a WASI CLI — use it with the JS glue from @ontologos/wasm, not wasmer run alone.
Browser usage¶
import init, { OntologyBuilder, Reasoner } from "@ontologos/wasm";
// Fetch or import the .wasm bytes, then initialize once:
await init({ module_or_path: "/path/to/ontologos_wasm_bg.wasm" });
const builder = new OntologyBuilder();
builder.addClass("http://example.org/Pizza");
builder.addClass("http://example.org/Food");
builder.subclassOf("http://example.org/Pizza", "http://example.org/Food");
const ontology = builder.build();
const reasoner = new Reasoner(ontology, "el");
const report = reasoner.classify();
console.log(report.status, report.subsumption_count);
Bundlers (Vite, webpack, etc.) usually resolve the wasm asset — follow your bundler's wasm-bindgen integration docs.
No filesystem¶
WASM has no file API. Load ontologies from:
Ontology.fromBytes(Uint8Array)— strict parse (default for uploads)Ontology.fromBytesLenient— trusted corpora onlyOntology.fromText(string)/fromTextLenientOntology.fromJson,fromObject, orfromJsonWithLimits/fromObjectWithLimits
Resource limits¶
import { Ontology } from "@ontologos/wasm";
const ontology = Ontology.fromJsonWithLimits(json, 1_048_576);
Recommended browser upload caps: 1–4 MiB JSON or OWL text unless you control memory budgets.
Errors¶
WASM throws Error subclasses with .name and .code set to ParseError, ResourceLimitError, or IncompleteReasoningError:
Threading and performance¶
- Bindings are single-threaded (
Rc<RefCell>). One WASM instance per tab/worker; do not share handles across workers. - DL classification can block the browser main thread. Pass
budgetSecstoReasonerand run heavy DL jobs in a Web Worker with a dedicated WASM instance. - Remote
owl:importsare not fetched in WASM (horned-owlremotefeature disabled forwasm32).
Security¶
See Security — JavaScript bindings. Default byte/text loaders use strict parse limits.
API surface¶
Mirrors Node/Python: Ontology, OntologyBuilder, Reasoner with classify(), checkConsistency(), isEntailed(), query(), and incremental edits.