OxiRS Rule Engine
Status: v0.4.0 - Released 2026-07-19
⨠Production Release: Production-ready with API stability guarantees and comprehensive testing.
A high-performance, comprehensive reasoning engine for Semantic Web applications, implementing forward chaining, backward chaining, RETE networks, RDFS, OWL RL, and SWRL rule processing.
Features
š Core Reasoning Engines
- Forward Chaining - Efficient data-driven inference with pattern matching and built-in predicates
- Backward Chaining - Goal-driven proof search with cycle detection and caching
- RETE Network - High-performance pattern matching for real-time rule execution
šÆ Standards Compliance
- RDFS Reasoning - Complete RDFS entailment rules (rdfs2, rdfs3, rdfs5, rdfs7, rdfs9, rdfs11)
- OWL RL Support - Class/property equivalence, characteristics, identity reasoning
- SWRL Integration - Semantic Web Rule Language with extensive built-in predicates
ā” Performance Features
- Incremental Updates - Efficient handling of dynamic knowledge base changes
- Pattern Indexing - Optimized rule and fact lookup with caching
- Memory Optimization - Efficient data structures for large-scale reasoning
- Statistics & Monitoring - Comprehensive performance metrics and tracing
Installation
Add to your Cargo.toml:
# Experimental feature
[]
= "0.3.2"
Quick Start
use ;
#
Architecture
Core Components
RuleEngine- Main interface unifying all reasoning strategiesForwardChainEngine- Data-driven inference with fixpoint calculationBackwardChainEngine- Goal-driven proof search with memoizationReteNetwork- High-performance pattern matching networkRdfsReasoner- RDFS schema reasoning and entailmentOwlReasoner- OWL RL profile reasoningSwrlEngine- SWRL rule processing with built-in functions
Data Structures
// Core data types
Reasoning Strategies
Forward Chaining
Ideal for:
- Batch processing of large datasets
- Materializing all possible inferences
- Data integration and ETL processes
let derived = engine.forward_chain?;
println!;
Backward Chaining
Ideal for:
- Query-driven reasoning
- Interactive applications
- Proof explanation and validation
let goal = Triple ;
let provable = engine.backward_chain?;
println!;
RETE Network
Ideal for:
- Real-time rule processing
- Incremental updates
- High-throughput applications
use ReteNetwork;
let mut rete = new;
rete.add_rule?;
let results = rete.forward_chain?;
Built-in Predicates
Comparison Operations
equal(?x, ?y)- Equality testingnotEqual(?x, ?y)- Inequality testinglessThan(?x, ?y)- Numeric comparisongreaterThan(?x, ?y)- Numeric comparison
Mathematical Operations
add(?x, ?y, ?result)- Additionsubtract(?x, ?y, ?result)- Subtractionmultiply(?x, ?y, ?result)- Multiplication
String Operations
stringConcat(?s1, ?s2, ?result)- String concatenationstringLength(?string, ?length)- String length
Utility Predicates
bound(?var)- Variable binding checkunbound(?var)- Variable unbound check
RDFS Reasoning
Automatic inference of:
- Class hierarchies (
rdfs:subClassOf) - Property hierarchies (
rdfs:subPropertyOf) - Domain and range constraints (
rdfs:domain,rdfs:range) - Type membership (
rdf:type)
use RdfsReasoner;
use ;
let mut rdfs = new;
let schema_and_data = vec!;
let inferred = rdfs.infer?;
// `inferred` includes the entailed triple: alice rdf:type Agent
OWL RL Reasoning
Support for:
- Property characteristics (functional, transitive, symmetric)
- Class equivalence and disjointness
- Individual identity (
owl:sameAs,owl:differentFrom) - Basic property restrictions
use ;
use ;
let mut owl = new;
owl.context
.set_property_characteristic;
let facts = vec!;
let inferred = owl.infer?;
// `inferred` includes the entailed triple: alice hasParent charlie
SWRL Rules
Support for complex rule definitions:
// Person(?p) ā§ hasAge(?p, ?age) ā§ greaterThan(?age, 18) ā Adult(?p)
let swrl_rule = SwrlRule ;
Performance Characteristics
Scalability
- Forward Chaining: O(n³) worst case, optimized for sparse rules
- Backward Chaining: O(2^n) worst case, pruned with cycle detection
- RETE Network: O(1) for fact insertion, O(n) for rule addition
Memory Usage
- Efficient fact storage with deduplication
- Rule indexing for fast pattern matching
- Configurable caching strategies
Benchmarks
- 1M+ triples: <60 seconds for full materialization
- 10K+ rules: <10 seconds for compilation
- Memory usage: <8GB for 1M triple datasets
Integration
With oxirs-core
use ;
let mut engine = new;
// Convert an oxirs-core triple's subject/predicate/object strings into a rule fact
engine.add_fact;
With SPARQL
// Use reasoning results in SPARQL queries
let inferred_facts = engine.get_facts;
// Add to SPARQL dataset for querying
Testing
Run the comprehensive test suite:
# Run all tests
# Run specific reasoning tests
# Run performance benchmarks
Test Coverage
- 2,242 tests passing (100% success rate)
- Unit tests for all reasoning algorithms
- Integration tests with real-world datasets
- Performance regression tests
Configuration
use RuleEngine;
let mut engine = new;
// Caching is enabled by default; toggle explicitly if needed
engine.enable_cache;
// Limit backward-chaining recursion depth (default: 100)
engine.set_backward_chain_max_depth;
if let Some = engine.get_cache_statistics
Error Handling
Comprehensive error types with detailed context:
// `RuleEngine` reasoning methods return `anyhow::Result<T>`
match engine.forward_chain
Logging and Monitoring
Built-in tracing support:
use ;
// Enable tracing
init;
// Reasoning operations automatically logged
let derived = engine.forward_chain?;
// Logs (via tracing): "Forward chaining completed: N facts derived"
Contributing
- Follow Rust 2021 edition best practices
- Maintain >95% test coverage
- Use
cargo clippyandcargo fmt - Add comprehensive documentation
- Include performance benchmarks
License
Licensed under the Apache License, Version 2.0.
Status
š Production Release (v0.4.0) ā 2026-07-19
Highlights:
- ā Forward/backward chaining over persisted datasets with automatic inference snapshots
- ā RETE network optimized with SciRS2 metrics and tracing hooks
- ā Integrated with federation-aware SPARQL workflows for rule-driven post-processing
- ā 2,242 tests passing plus CLI end-to-end coverage
- š§ Advanced distributed reasoning (planned for future release)