[−][src]Crate rio_turtle
Implementation of N-Triples, N-Quads, Turtle and TriG parsers.
All the provided parsers work in streaming from a BufRead
implementation.
They do not rely on any dependencies outside of Rust standard library.
The parsers are not protected against memory overflows.
For example if the parsed content contains a literal string of 16GB, 16GB of memory will be allocated.
How to read a file foo.ttl
and count the number of rdf:type
triples:
use rio_turtle::{TurtleParser, TurtleError}; use rio_api::parser::TriplesParser; use rio_api::model::NamedNode; use std::io::BufReader; use std::fs::File; let rdf_type = NamedNode { iri: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" }; let mut count = 0; TurtleParser::new(BufReader::new(File::open("foo.ttl").unwrap()), "file:foo.ttl").unwrap().parse_all(&mut |t| { if t.predicate == rdf_type { count += 1; } Ok(()) as Result<(), TurtleError> }).unwrap();
Replace TurtleParser
by NTriplesParser
, NQuadsParser
or TriGParser
to read a N-Triples, N-Quads or TriG file instead.
NTriplesParser
and NQuadsParser
do not use the second argument of the new
function that is the IRI of the file.
Structs
NQuadsFormatter | A N-Quads formatter. |
NQuadsParser | A N-Quads streaming parser. |
NTriplesFormatter | A Canonical N-Triples formatter. |
NTriplesParser | A N-Triples streaming parser. |
TriGFormatter | A TriG formatter. |
TriGParser | A TriG streaming parser. |
TurtleError | Error that might be returned during parsing. |
TurtleFormatter | A Turtle formatter. |
TurtleParser | A Turtle streaming parser. |