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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
//! # OxiRS Turtle - RDF Format Parser
//!
//! [](https://github.com/cool-japan/oxirs/releases)
//! [](https://docs.rs/oxirs-ttl)
//!
//! **Status**: Production Release (v0.2.4)
//! **Stability**: Production-ready with 461 passing tests and 97% W3C compliance.
//!
//! High-performance parsing and serialization for RDF formats in the Turtle family.
//! Supports Turtle, TriG, N-Triples, N-Quads, and N3 with streaming and error recovery.
//!
//! Ported from Oxigraph's oxttl crate with adaptations for OxiRS.
//!
//! # Features
//!
//! - **Streaming support**: Process large files with minimal memory usage
//! - **Error recovery**: Continue parsing despite syntax errors
//! - **Async I/O**: Optional Tokio async support
//! - **Parallel processing**: Process files in parallel chunks
//! - **RDF 1.2 support**: Quoted triples and directional language tags
//! - **Incremental parsing**: Parse as bytes arrive with checkpointing
//!
//! # Quick Start
//!
//! ## Basic Turtle Parsing
//!
//! ```rust
//! use oxirs_ttl::{turtle::TurtleParser, Parser};
//! use std::io::Cursor;
//!
//! let turtle_data = r#"
//! @prefix ex: <http://example.org/> .
//! ex:subject ex:predicate "object" .
//! "#;
//!
//! let parser = TurtleParser::new();
//! for result in parser.for_reader(Cursor::new(turtle_data)) {
//! let triple = result?;
//! println!("{}", triple);
//! }
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! ## Error Recovery with Lenient Mode
//!
//! ```rust
//! use oxirs_ttl::turtle::TurtleParser;
//!
//! let turtle_with_errors = r#"
//! @prefix ex: <http://example.org/> .
//! ex:good ex:pred "value" .
//! ex:also_good ex:pred "value2" .
//! "#;
//!
//! // Lenient mode continues parsing after errors
//! let parser = TurtleParser::new_lenient();
//! let triples = parser.parse_document(turtle_with_errors)?;
//! println!("Parsed {} triples", triples.len());
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! ## Streaming Large Files
//!
//! ```rust
//! use oxirs_ttl::{StreamingParser, StreamingConfig};
//! use std::io::Cursor;
//!
//! let config = StreamingConfig::default()
//! .with_batch_size(10000); // Process 10K triples per batch
//!
//! let data = Cursor::new(b"<http://s> <http://p> <http://o> .");
//! let parser = StreamingParser::with_config(data, config);
//! let mut total = 0;
//!
//! for batch in parser.batches() {
//! let triples = batch?;
//! total += triples.len();
//! println!("Processed batch of {} triples", triples.len());
//! }
//! println!("Total: {} triples", total);
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! ## Incremental Parsing
//!
//! ```rust
//! use oxirs_ttl::{IncrementalParser, ParseState};
//!
//! let mut parser = IncrementalParser::new();
//!
//! // Feed data as it arrives
//! parser.push_data(b"@prefix ex: <http://example.org/> .\n")?;
//! parser.push_data(b"ex:s ex:p \"object\" .\n")?;
//! parser.push_eof();
//!
//! // Parse available complete statements
//! let triples = parser.parse_available()?;
//! println!("Parsed {} triples", triples.len());
//!
//! assert_eq!(parser.state(), ParseState::Complete);
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! ## Serialization with Pretty Printing
//!
//! ```rust
//! use oxirs_ttl::turtle::TurtleSerializer;
//! use oxirs_ttl::toolkit::{Serializer, SerializationConfig};
//! use oxirs_core::model::{NamedNode, Triple};
//!
//! let triple = Triple::new(
//! NamedNode::new("http://example.org/subject")?,
//! NamedNode::new("http://example.org/predicate")?,
//! NamedNode::new("http://example.org/object")?
//! );
//!
//! // Create config with pretty printing
//! let config = SerializationConfig::default()
//! .with_pretty(true)
//! .with_use_prefixes(true);
//!
//! let serializer = TurtleSerializer::with_config(config);
//!
//! let mut output = Vec::new();
//! serializer.serialize(&vec![triple], &mut output)?;
//!
//! let turtle_string = String::from_utf8(output)?;
//! println!("{}", turtle_string);
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
// Re-export the main format APIs
// Re-export common types
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
/// Turtle pretty printer with prefix analysis.
/// @base / @prefix IRI resolution for Turtle/TriG (v1.1.0 round 6)
/// Incremental/streaming Turtle parser for large files (v1.1.0 round 7)
/// Namespace/prefix management for Turtle and SPARQL serialization (v1.1.0 round 8)
/// Turtle/TriG document syntax validation (v1.1.0 round 9)
/// Prefix/CURIE resolver for Turtle and TriG documents (v1.1.0 round 10)
/// JSON-LD framing: apply a frame template to a node set (v1.1.0 round 11)
/// IRI prefix catalog with CURIE expansion and compression (v1.1.0 round 13)
/// Compact Turtle serialization with subject/predicate grouping (v1.1.0 round 12)
/// N-Triples/N-Quads serialization with proper escaping (v1.1.0 round 11)
/// Basic RDFa 1.1 Lite parser: property/typeof/resource/about/prefix attributes,
/// literal extraction, rel/rev links, context inheritance (v1.1.0 round 13)
/// N-Triples and N-Quads streaming parser: IRI/blank-node/literal tokens,
/// comment/blank line skip, typed literals, language tags, Unicode escapes (v1.1.0 round 14)
pub use ;
pub use ;
/// JSON-LD compaction: converts expanded JSON-LD to compact form using a context (v1.1.0 round 15)
/// TriG named-graph Turtle parser: @prefix/PREFIX declarations, GRAPH blocks,
/// default-graph triples, prefix expansion, graph_sizes, named_graphs (v1.1.0 round 16)