inference-engine 0.1.0-alpha.13

Native Rust RDF inference engine with a shared command-line interface
Documentation
---
title: Command line
permalink: /cli/
nav_order: 3
grapharch:
  subject: urn:inference-engine:docs:cli
---
# Infer facts from RDF files

The `inference-engine` command reads one or more RDF files, runs a selected rule
profile and writes the asserted and inferred facts together. It uses the same
Rust executor as the library, including when installed through Python or npm.

```sh
inference-engine --profile rdfs-subclass schema.ttl facts.ttl > expanded.nq
```

For example, `schema.ttl` might say every Dog is an Animal, while `facts.ttl`
says Fido is a Dog. The output includes those assertions and the inferred fact
that Fido is an Animal.

## Install or run from source

Install a published alpha through Python or npm:

```sh
uv tool install --prerelease allow inference-engine
npm install --global inference-engine@alpha
```

These are alternative installers for the same command. The Python and npm
packages carry a native Rust module; neither runs a separate reasoning engine.
For Cargo, select an alpha version from the [releases](https://github.com/legra-ai/inference-engine/releases)
and run `cargo install inference-engine --locked --version VERSION`.

From a source checkout:

```sh
cargo run --locked -- --profile rdfs-subclass schema.ttl facts.ttl
cargo install --path . --locked
```

The `cli` Cargo feature is enabled by default. Library-only consumers can disable
default features to omit the command's parsing and storage dependencies.

## Select a profile

The profile is mandatory:

| Profile | Execution |
| --- | --- |
| `rdfs-subclass` | Subclass chains and inherited class membership. |
| `rdfs-core` | The fourteen shared RDF/RDFS structural clauses. |

Both are restricted profiles. They do not perform full RDFS 1.2 entailment or
complete consistency checking. Full `rdfs`, OWL-RL, general Datalog and SHACL
execution selectors are not available through this command yet; unsupported
selectors fail instead of choosing a smaller profile. See
[Alpha capabilities](alpha-scope.md) and [RDF/RDFS profiles](rdfs-subclass.md).

## Read files or stdin

Inputs may mix Turtle (`.ttl`), TriG (`.trig`), N-Triples (`.nt`) and N-Quads (`.nq`).
The extension selects the parser unless `--input-format` explicitly overrides it.
Relative IRIs in files resolve against that file's absolute file IRI, unless its
own RDF declarations set a base. Stdin has no implicit base IRI.

```sh
cat facts.ttl | inference-engine --profile rdfs-subclass --input-format ttl -
```

Use `-` at most once. Directories, gzip and other RDF syntaxes are not accepted
by this first command-line slice.

Blank-node labels are scoped separately for each input document. The same label
in two files does not identify the same node. Labels may change on output;
output order is not a canonicalization guarantee.

## Graph boundaries

Ordinary Turtle and N-Triples inputs share the default graph, so a schema file
and a data file can contribute to the same inference run.

Named graphs are preserved and reasoned over separately. An assertion in one
named graph does not supply a premise in another graph, and an inferred quad
keeps the graph in which it was derived. The default graph is separate from
named graphs too. There is no implicit union-dataset inference mode.

## Choose the output

Stdout defaults to N-Quads. Progress, the selected profile's exclusions and errors
go to stderr, so stdout can feed another RDF tool.

```sh
inference-engine --profile rdfs-subclass schema.ttl facts.ttl -o expanded.nq
inference-engine --profile rdfs-subclass schema.ttl facts.ttl --emit inferred -o inferred.nt
inference-engine --profile rdfs-subclass data.trig --output-format trig
```

`--emit all` is the default; `inferred` and `asserted` select just one contribution.
Duplicate facts are emitted once per graph, and an assertion wins an identical
inferred fact. Output format follows the destination extension or an explicit
`--output-format nt|nq|ttl|trig`. Turtle output uses the N-Triples-compatible form.
N-Triples and Turtle cannot preserve named graphs, so the command rejects them
when selected output contains named graphs. Use N-Quads or TriG for a dataset.

## Generalized internal facts

Some rules can derive tuples outside standard RDF syntax. For example,
`rdfs-core` can give a literal a type, producing a tuple with a literal subject.
Such tuples are retained during inference because later rules may need them.

By default, the command fails before emitting RDF if the requested output
contains a tuple that standard RDF cannot represent. To explicitly request
only the standard-RDF projection of the completed closure:

```sh
inference-engine --profile rdfs-core --rdf-only schema.ttl facts.ttl -o expanded.nq
```

The command reports how many generalized tuples were omitted. This projection
happens after reasoning; it does not discard premises while rules are running.

## Failure and resource limits

Parsing, inference and serialization finish in isolated disk scratch before
stdout receives data. A file destination is staged in the same directory and
atomically replaced only after those phases succeed. A malformed late input,
unsupported profile, storage failure or exhausted reasoning/serialization budget
therefore cannot publish a partial closure or truncate an existing result.
Output must not replace an input file. Errors while writing to stdout still
return a nonzero status; an interrupted output stream cannot be rolled back.

The command uses indexed, disk-backed scratch with immutable round snapshots.
It does not collect the graph or closure in memory. Its database cache is capped
at 64 MiB and write batches are bounded. Input bytes, serialized terms and
nesting have separate caps. The parser owns per-document syntax buffers and
prefix metadata; a read-byte cap is not a process memory limit. `--scratch-dir` selects the parent for temporary working storage.

Defaults are 128 rounds per graph, one million inferred tuples across all graphs,
ten million aggregate work steps, 1 GiB each for scratch/output/total input,
64 MiB per document, 1 MiB per serialized term and depth 64 for triple terms.
Use `--help` for the corresponding `--max-*` options. Exceeding a cap is an error,
not a truncated successful result. `--quiet` suppresses successful-run statistics;
errors and an actual projection-omission count remain visible.