1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
//! 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](https://www.w3.org/TR/rdf12-concepts/),
//! 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 resources
//! - **[`BlankNode`]** - An anonymous node without a global identifier
//! - **[`Literal`]** - A data value with optional language tag or datatype
//! - **[`Variable`]** - A SPARQL query variable (used in query patterns)
//!
//! ### Composite Types
//!
//! - **[`Triple`]** - A statement with subject, predicate, and object
//! - **[`Quad`]** - A triple with an optional named graph
//! - **[`GraphName`]** - Identifies the graph containing a quad (named or default)
//!
//! ### Union Types
//!
//! - **[`Subject`]** - Can be a NamedNode, BlankNode, or Variable
//! - **[`Predicate`]** - Can be a NamedNode or Variable
//! - **[`Object`]** - Can be a NamedNode, BlankNode, Literal, or Variable
//! - **[`Term`]** - Any RDF term (superset of all above)
//!
//! ## Examples
//!
//! ### Creating RDF Terms
//!
//! ```rust
//! use oxirs_core::model::*;
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // 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")?;
//! # Ok(())
//! # }
//! ```
//!
//! ### Creating Triples
//!
//! ```rust
//! use oxirs_core::model::*;
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // 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());
//! # Ok(())
//! # }
//! ```
//!
//! ### Creating Quads (Named Graphs)
//!
//! ```rust
//! use oxirs_core::model::*;
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // 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());
//! # Ok(())
//! # }
//! ```
//!
//! ### Working with Literals
//!
//! ```rust
//! use oxirs_core::model::*;
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // 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");
//! # Ok(())
//! # }
//! ```
//!
//! ### Pattern Matching with Variables
//!
//! ```rust
//! use oxirs_core::model::*;
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // 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);
//! # Ok(())
//! # }
//! ```
//!
//! ## Type Conversions
//!
//! All term types implement `Into<>` for their union types:
//!
//! ```rust
//! use oxirs_core::model::*;
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! 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();
//! # Ok(())
//! # }
//! ```
//!
//! ## Performance Optimizations
//!
//! This module includes several performance optimizations:
//!
//! - **String interning** via [`optimized_terms`] for 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 [`star`] module 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 formats
//! - [`crate::serializer`] - Serialize RDF to various formats
//! - [`crate::rdf_store`] - Store and query RDF data
//! - [`crate::query`] - SPARQL query execution
// CURIE prefix ↔ IRI namespace registry (v1.2.0)
// Oxigraph-inspired performance optimizations
// SPARQL query plan optimizer with rewrite passes (v1.1.0)
// SPARQL binding set algebra: MINUS, EXISTS, JOIN, PROJECT (v1.2.0)
// Re-export core types
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *; // Oxigraph-inspired optimizations
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
// Explicit re-exports of union types for external modules
pub use GraphName;
pub use ;
/// A trait for all RDF terms
/// A trait for terms that can be used as subjects in RDF triples
/// A trait for terms that can be used as predicates in RDF triples
/// A trait for terms that can be used as objects in RDF triples
/// A trait for terms that can be used in graph names