ntriple
A parser that parses a single RDF statement, in RDF N-Triples format.
It is written in Rust and uses rust-peg
for parsing the triple to an object structure. Literals are decomposed into
their RDF lexical form and language or data type.
The purpose of this library is to process triples in a streaming way, so it doesn't build
an RDF Graph.
If you are looking for libraries that do, take a look at
rust-ntriples or rome.
Example:
extern crate ntriple;
use ntriple::parser::triple_line;
use ntriple::{Subject, Predicate, Object};
fn main() {
let input = "_:subject <http://example.org/predicate> \"\\u30AAオブジェクト\".";
let parse_result = triple_line(&input);
match parse_result {
Ok(triple_option) => {
match triple_option {
Some(triple) => { match triple.subject {
Subject::BNode(subject) => println!("Subject: blank node: {}", subject),
_ => println!("Weird, a blank node is expected here.")
};
match triple.predicate {
Predicate::IriRef(iri) => println!("Predicate: {}", iri)
};
match triple.object {
Object::Lit(literal) => println!("Object: literal: {} ", literal.data),
_ => println!("Weird, a literal is expected here.")
}
},
None => { println!("Skipped [{}]", input); }
};
},
Err(error) => println!("{}\n{}", input, error),
};
}