Crate rio_turtle

source ·
Expand description

Implementation of N-Triples, N-Quads, Turtle and TriG parsers.

This library is going to be deprecated. oxttl is currently in development to replace it.

RDF-star syntaxes are also supported, i.e. Turtle-star, TriG-star, N-Triples-star and N-Quads-star.

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 16 GB, 16 GB 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;
use oxiri::Iri;

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")?), Some(Iri::parse("file:foo.ttl".to_owned()).unwrap())).parse_all(&mut |t| {
    if t.predicate == rdf_type {
        count += 1;
    }
    Ok(()) as Result<(), TurtleError>
})?;

Replace TurtleParser by NTriplesParser, NQuadsParser or TriGParser to read an 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§