OxiRS TTL - RDF Turtle Family Parser & Serializer
Status: Production Release (v0.1.0) - January 2026
✨ Production-Ready: API-stable with comprehensive testing (461 tests), W3C compliance, and performance optimizations.
High-performance parsers and serializers for RDF formats in the Turtle family including Turtle, N-Triples, TriG, N-Quads, and N3. Ported from Oxigraph's oxttl crate with extensive enhancements for OxiRS.
Features
Supported Formats
| Format | Extension | Parsing | Serialization | Named Graphs | Description |
|---|---|---|---|---|---|
| Turtle | .ttl |
✅ | ✅ | ❌ | Full Turtle 1.1 with prefixes, collections, and abbreviated syntax |
| N-Triples | .nt |
✅ | ✅ | ❌ | Simple line-based triple format |
| TriG | .trig |
✅ | ✅ | ✅ | Turtle extension with named graphs |
| N-Quads | .nq |
✅ | ✅ | ✅ | N-Triples extension with named graphs |
| N3 | .n3 |
🚧 | ❌ | ✅ | Experimental: Variables and formulas |
RDF 1.2 Support 🆕
Quoted Triples (RDF-star):
@prefix ex: <http://example.org/> .
# Quoted triple as subject
<< ex:alice ex:knows ex:bob >> ex:certainty 0.9 .
# Nested quoted triples
<< << ex:alice ex:knows ex:bob >> ex:source ex:socialNetwork >> ex:timestamp "2025-11-23" .
Directional Language Tags:
ex:greeting "Hello"@en--ltr . # Left-to-right
ex:greeting "مرحبا"@ar--rtl . # Right-to-left
Enable with feature flag:
[]
= { = "0.1.0", = ["rdf-12"] }
Advanced Features
- ✅ Streaming Support - Memory-efficient parsing of multi-GB files
- ✅ Async I/O - Tokio-based async parsing (feature:
async-tokio) - ✅ Parallel Processing - Multi-threaded parsing with rayon (feature:
parallel) - ✅ Error Recovery - Lenient mode continues parsing after errors
- ✅ Incremental Parsing - Parse as bytes arrive with checkpointing
- ✅ Format Auto-Detection - Automatic format detection from extension/MIME/content
- ✅ W3C Compliance - 97% pass rate on official W3C Turtle test suite
- ✅ Performance Optimizations - SIMD lexing, zero-copy parsing, lazy IRI resolution
- ✅ Serialization Optimizations - Predicate grouping, object lists, blank node inlining, collection syntax
Installation
Add to your Cargo.toml:
[]
= "0.1.0"
# With all features
= { = "0.1.0", = ["async-tokio", "parallel", "rdf-12"] }
Quick Start
Basic Turtle Parsing
use TurtleParser;
use Cursor;
let turtle_data = r#"
@prefix ex: <http://example.org/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
ex:alice foaf:name "Alice" ;
foaf:knows ex:bob, ex:charlie .
"#;
let parser = new;
for result in parser.for_reader
# Ok::
Automatic Format Detection
use FormatDetector;
use File;
// Detect format from file extension
let format = detect_from_path?;
println!;
// Auto-detect from content
let content = read_to_string?;
let detection = detect_from_content;
println!;
N-Triples Parsing
use NTriplesParser;
use Cursor;
let ntriples_data = r#"
<http://example.org/alice> <http://xmlns.com/foaf/0.1/name> "Alice" .
<http://example.org/alice> <http://xmlns.com/foaf/0.1/knows> <http://example.org/bob> .
"#;
let parser = new;
for result in parser.for_reader
TriG Parsing (Named Graphs)
use TriGParser;
use Cursor;
let trig_data = r#"
@prefix ex: <http://example.org/> .
ex:graph1 {
ex:alice ex:knows ex:bob .
}
ex:graph2 {
ex:charlie ex:knows ex:dave .
}
"#;
let parser = new;
for result in parser.for_reader
Advanced Usage
Streaming for Large Files
Memory-efficient parsing of multi-gigabyte RDF files:
use ;
use File;
// Configure streaming with 10K triple batches
let config = default
.with_batch_size
.with_progress_callback;
let file = open?;
let parser = with_config;
let mut total = 0;
for batch in parser.batches
println!;
Async I/O with Tokio
Non-blocking async parsing (requires async-tokio feature):
use AsyncTurtleParser;
use File;
async
Parallel Processing
Multi-threaded parsing for large files (requires parallel feature):
use ParallelStreamingParser;
use File;
let file = open?;
let parser = new?; // 4 threads
let triples = parser.collect_all?;
println!;
Error Recovery (Lenient Mode)
Continue parsing despite syntax errors:
use TurtleParser;
let turtle_with_errors = r#"
@prefix ex: <http://example.org/> .
ex:good ex:pred "value" .
ex:bad ex:pred "unclosed string
ex:also_good ex:pred "value2" .
"#;
// Lenient mode collects errors but continues parsing
let parser = new_lenient;
match parser.parse_document
Incremental Parsing
Parse as bytes arrive (useful for network streams):
use ;
let mut parser = new;
// Feed data as it arrives
parser.push_data?;
parser.push_data?;
parser.push_eof;
// Parse complete statements
let triples = parser.parse_available?;
println!;
assert_eq!;
Serialization with Pretty Printing
use TurtleSerializer;
use ;
use ;
let triples = vec!;
// Configure pretty printing
let config = default
.with_pretty
.with_use_prefixes
.with_indent;
let serializer = with_config;
let mut output = Vecnew;
serializer.serialize?;
println!;
Optimized Serialization
Compact output with predicate grouping, object lists, and collection syntax:
use TurtleSerializer;
// Predicate grouping: ex:alice ex:name "Alice" ; ex:age 30 .
// Object lists: ex:alice ex:knows ex:bob, ex:charlie .
// Blank nodes: [ ex:prop "value" ; ex:other "data" ]
// Collections: ex:list (ex:item1 ex:item2 ex:item3) .
let serializer = new;
let turtle = serializer.serialize_optimized?;
// ~76% more compact than verbose representation
println!;
Performance Profiling
Track parsing performance with built-in profiler:
use TtlProfiler;
use File;
let mut profiler = new;
let file = open?;
profiler.start_parse;
let triples = parse_with_profiler?;
profiler.end_parse;
// Get detailed statistics
let stats = profiler.get_stats;
println!;
Serialization Optimizations
OxiRS-TTL provides highly optimized Turtle serialization:
Predicate Grouping
Same subject with multiple predicates uses semicolon syntax:
# Before (verbose)
ex:alice ex:name "Alice" .
ex:alice ex:age 30 .
ex:alice ex:city "Wonderland" .
# After (optimized)
ex:alice ex:name "Alice" ;
ex:age 30 ;
ex:city "Wonderland" .
Object Lists
Same subject and predicate with multiple objects uses comma syntax:
# Before (verbose)
ex:alice ex:knows ex:bob .
ex:alice ex:knows ex:charlie .
ex:alice ex:knows ex:dave .
# After (optimized)
ex:alice ex:knows ex:bob, ex:charlie, ex:dave .
Blank Node Inlining
Anonymous blank nodes use compact property list syntax:
# Before (verbose)
_:b1 ex:city "Wonderland" .
_:b1 ex:country "Fantasy" .
ex:alice ex:location _:b1 .
# After (optimized)
ex:alice ex:location [ ex:city "Wonderland" ; ex:country "Fantasy" ] .
Collection Syntax
RDF collections use compact parenthesis syntax:
# Before (verbose - 7 triples)
_:b1 rdf:first ex:item1 .
_:b1 rdf:rest _:b2 .
_:b2 rdf:first ex:item2 .
_:b2 rdf:rest _:b3 .
_:b3 rdf:first ex:item3 .
_:b3 rdf:rest rdf:nil .
ex:list ex:items _:b1 .
# After (optimized - 1 triple)
ex:list ex:items (ex:item1 ex:item2 ex:item3) .
Performance
Benchmarks
Measured on Apple M1 with typical RDF datasets:
| Format | Parse Speed | Serialize Speed | Features |
|---|---|---|---|
| Turtle | 250-300K triples/s | 180-200K triples/s | SIMD lexing, zero-copy |
| N-Triples | 400-500K triples/s | 350-400K triples/s | Line-based, optimized |
| TriG | 200-250K triples/s | 160-180K triples/s | Multi-graph support |
| N-Quads | 350-450K triples/s | 300-350K triples/s | Quad format |
Performance Features
- SIMD Lexing: Uses
memchrfor 2-4x faster byte scanning - Zero-Copy Parsing: Minimizes string allocations with
Cow<str> - String Interning: Deduplicates common IRIs (RDF namespaces)
- Lazy IRI Resolution: Defers IRI normalization until needed
- Buffer Pooling: Reuses parsing buffers in streaming mode
- Parallel Processing: Multi-threaded parsing for large files
Testing & Compliance
Test Coverage
- 461 tests passing (437 integration + 24 doc tests)
- Property-based testing with proptest
- Memory leak tests for production safety
- Performance regression tests for baseline tracking
- Fuzzing infrastructure for parser robustness
W3C Compliance
| Test Suite | Pass Rate | Status |
|---|---|---|
| W3C Turtle Test Suite | 97% (33/34) | ✅ Excellent |
| W3C TriG Test Suite | 94% (33/35) | ✅ Excellent |
| RDF 1.2 Features | 100% (19/19) | ✅ Complete |
Integration with OxiRS
With oxirs-core
use Dataset;
use TurtleParser;
use Cursor;
let turtle_data = r#"
@prefix ex: <http://example.org/> .
ex:subject ex:predicate "object" .
"#;
let parser = new;
let triples = parser.parse_document?;
let mut dataset = new;
for triple in triples
Error Handling
use ;
match parser.parse_document
Configuration
Streaming Configuration
use StreamingConfig;
let config = default
.with_batch_size // Triples per batch
.with_buffer_size // 64KB read buffer
.with_progress_reporting // Enable progress callbacks
.with_error_recovery; // Lenient mode
Serialization Configuration
use SerializationConfig;
let config = default
.with_pretty // Pretty printing
.with_indent // 2-space indentation
.with_use_prefixes // Abbreviate with prefixes
.with_max_line_length // Wrap at 80 chars
.with_base_iri; // Base IRI for relative IRIs
Status
v0.1.0 Release (January 2026) ✅
Core Features (100% Complete):
- ✅ Turtle, TriG, N-Triples, N-Quads parsing & serialization
- ✅ RDF 1.2: Quoted triples + directional language tags
- ✅ Streaming, async I/O, parallel processing
- ✅ Error recovery with lenient mode
- ✅ Incremental parsing with checkpointing
- ✅ Format auto-detection
- ✅ W3C compliance testing (97% pass rate)
- ✅ Performance optimizations (SIMD, zero-copy, lazy IRI)
- ✅ Serialization optimizations (predicate grouping, collections)
- ✅ Fuzzing infrastructure
- ✅ Memory leak testing
- ✅ Comprehensive documentation (24 doc tests)
Advanced Features (v0.1.0):
- ✅ RFC 3987 IRI validation
- ✅ RFC 3986 IRI resolution
- ✅ N3 types & built-in registry (40+ predicates)
- ✅ Profiling & performance metrics
- ✅ Sample data infrastructure
Future Work:
- 🚧 Full N3 formula parsing
- 🚧 N3 reasoning primitives
- 🚧 RDF 1.2 official compliance tests
Contributing
This is a foundational module for OxiRS. Contributions welcome!
Development
# Run tests
# Run benchmarks
# Check for warnings (no warnings policy)
# Format code
# Run fuzzing (requires cargo-fuzz)
&&
Documentation
Guides and Tutorials
- Documentation Hub - Complete documentation index
- Streaming Tutorial - Memory-efficient large file processing
- Async Usage Guide - Non-blocking I/O with Tokio
- Performance Tuning Guide - Optimization techniques
API Reference
- API Documentation - Full API reference
- Module docs: streaming.rs - Streaming API examples
- Module docs: profiling.rs - Performance tracking
Specifications
- W3C Turtle Spec - Turtle 1.1 specification
- W3C TriG Spec - TriG specification
- RDF 1.2 Spec - RDF 1.2 concepts
License
MIT OR Apache-2.0
See Also
- oxirs-core - RDF data model and core types
- oxirs-star - RDF-star extended format support
- oxirs-arq - SPARQL query engine
- Oxigraph - Original inspiration