Expand description
Core RDF data model types and implementations
Stability: ✅ Stable - These APIs are production-ready and will maintain backward compatibility.
This module provides the fundamental RDF concepts following the RDF 1.2 specification, with performance optimizations and OxiRS-specific enhancements.
§Overview
The RDF (Resource Description Framework) data model represents information as triples: Subject - Predicate - Object. This module provides Rust types for all RDF terms and structures, enabling type-safe manipulation of RDF data.
§Core Types
§Terms (Basic Building Blocks)
NamedNode- An IRI (Internationalized Resource Identifier), the primary way to identify resourcesBlankNode- An anonymous node without a global identifierLiteral- A data value with optional language tag or datatypeVariable- A SPARQL query variable (used in query patterns)
§Composite Types
Triple- A statement with subject, predicate, and objectQuad- A triple with an optional named graphGraphName- Identifies the graph containing a quad (named or default)
§Union Types
Subject- Can be a NamedNode, BlankNode, or VariablePredicate- Can be a NamedNode or VariableObject- Can be a NamedNode, BlankNode, Literal, or VariableTerm- Any RDF term (superset of all above)
§Examples
§Creating RDF Terms
use oxirs_core::model::*;
// Create a Named Node (IRI)
let alice = NamedNode::new("http://example.org/alice")?;
// Create a Blank Node
let blank = BlankNode::new("b1")?;
// Create Literals
let plain_literal = Literal::new("Hello, World!");
let typed_literal = Literal::new_typed("42", NamedNode::new("http://www.w3.org/2001/XMLSchema#integer")?);
let lang_literal = Literal::new_lang("Bonjour", "fr")?;
// Create a Variable (for SPARQL patterns)
let var = Variable::new("name")?;§Creating Triples
use oxirs_core::model::*;
// Create terms
let alice = NamedNode::new("http://example.org/alice")?;
let knows = NamedNode::new("http://xmlns.com/foaf/0.1/knows")?;
let bob = NamedNode::new("http://example.org/bob")?;
// Create a triple: "Alice knows Bob"
let triple = Triple::new(alice, knows, bob);
// Access components
println!("Subject: {}", triple.subject());
println!("Predicate: {}", triple.predicate());
println!("Object: {}", triple.object());§Creating Quads (Named Graphs)
use oxirs_core::model::*;
// Create terms
let alice = NamedNode::new("http://example.org/alice")?;
let name = NamedNode::new("http://xmlns.com/foaf/0.1/name")?;
let alice_lit = Literal::new("Alice");
// Create a named graph
let graph = GraphName::NamedNode(NamedNode::new("http://example.org/graph1")?);
// Create a quad in the named graph
let quad = Quad::new(alice, name, alice_lit, graph);
println!("Quad in graph: {}", quad.graph_name());§Working with Literals
use oxirs_core::model::*;
// Plain literal
let plain = Literal::new("Hello");
assert_eq!(plain.value(), "Hello");
// Language-tagged literal (for internationalization)
let french = Literal::new_lang("Bonjour", "fr")?;
assert_eq!(french.value(), "Bonjour");
assert_eq!(french.language(), Some("fr"));
// Typed literal (with XSD datatype)
let number = Literal::new_typed(
"42",
NamedNode::new("http://www.w3.org/2001/XMLSchema#integer")?
);
assert_eq!(number.value(), "42");§Pattern Matching with Variables
use oxirs_core::model::*;
// Create a query pattern: "?person foaf:name ?name"
let person_var = Variable::new("person")?;
let name_var = Variable::new("name")?;
let name_pred = NamedNode::new("http://xmlns.com/foaf/0.1/name")?;
let pattern = Triple::new(person_var, name_pred, name_var);
// This pattern can be used in SPARQL queries
println!("Pattern: {:?}", pattern);§Type Conversions
All term types implement Into<> for their union types:
use oxirs_core::model::*;
let node = NamedNode::new("http://example.org/resource")?;
// Automatic conversion to union types
let subject: Subject = node.clone().into();
let predicate: Predicate = node.clone().into();
let object: Object = node.clone().into();
let term: Term = node.into();§Performance Optimizations
This module includes several performance optimizations:
- String interning via
optimized_termsfor reduced memory usage - Zero-copy operations where possible
- Efficient hashing for use in hash-based collections
- Ordered comparisons for BTree-based indexes
§RDF 1.2 Features
- RDF-star support via
starmodule for quoted triples - Generalized RDF datasets with named graph support
- Extended literal datatypes including language-tagged strings
§Related Modules
crate::parser- Parse RDF from various formatscrate::serializer- Serialize RDF to various formatscrate::rdf_store- Store and query RDF datacrate::query- SPARQL query execution
Re-exports§
pub use quad::GraphName;pub use term::Object;pub use term::Predicate;pub use term::Subject;pub use term::Term;pub use term::Variable;pub use dataset::*;pub use graph::*;pub use iri::*;pub use literal::*;pub use node::*;pub use optimized_terms::*;pub use pattern::*;pub use quad::*;pub use star::*;pub use term::*;pub use triple::*;
Modules§
- dataset
- RDF Dataset implementation
- graph
- RDF Graph implementation
- iri
- IRI and Named Node implementations for RDF
- literal
- RDF Literal implementation
- namespace_
registry - RDF Namespace Registry for CURIE prefix management.
- node
- Common node types used across RDF/XML and JSON-LD
- optimized_
terms - pattern
- Pattern matching for RDF triples
- property_
path_ evaluator - SPARQL 1.1 Property Path Evaluation
- quad
- RDF Quad implementation
- sparql_
binding_ set - SPARQL Binding Set operations for MINUS and EXISTS evaluation.
- sparql_
optimizer - SPARQL query plan optimizer with rewrite rules.
- star
- RDF-star (RDF*) support for statement annotations
- term
- Core RDF term types and implementations
- triple
- RDF Triple implementation
- triple_
term - SPARQL 1.2 Triple Term support
Traits§
- Graph
Name Term - A trait for terms that can be used in graph names
- Object
Term - A trait for terms that can be used as objects in RDF triples
- Predicate
Term - A trait for terms that can be used as predicates in RDF triples
- RdfTerm
- A trait for all RDF terms
- Subject
Term - A trait for terms that can be used as subjects in RDF triples