Struct rio_turtle::NTriplesParser
source ·
[−]pub struct NTriplesParser<R: BufRead> { /* fields omitted */ }
Expand description
A N-Triples and N-Triples-star streaming parser.
It implements the TriplesParser
trait.
Its memory consumption is linear in the size of the longest line of the file. It does not do any allocation during parsing except buffer resizing if a line significantly longer than the previous is encountered.
Count the number of people using the TriplesParser
API:
use rio_turtle::{NTriplesParser, TurtleError};
use rio_api::parser::TriplesParser;
use rio_api::model::NamedNode;
let file = b"<http://example.com/foo> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> .
<http://example.com/foo> <http://schema.org/name> \"Foo\" .
<http://example.com/bar> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> .
<http://example.com/bar> <http://schema.org/name> \"Bar\" .";
let rdf_type = NamedNode { iri: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" };
let schema_person = NamedNode { iri: "http://schema.org/Person" };
let mut count = 0;
NTriplesParser::new(file.as_ref()).parse_all(&mut |t| {
if t.predicate == rdf_type && t.object == schema_person.into() {
count += 1;
}
Ok(()) as Result<(), TurtleError>
})?;
assert_eq!(2, count);
Implementations
Trait Implementations
type Error = <NTriplesParser<B> as TriplesParser>::Error
type Error = <NTriplesParser<B> as TriplesParser>::Error
The type of errors produced by this source.
type Triple = ScopedRioSourceTriple
type Triple = ScopedRioSourceTriple
Determine the type of Triple
s
that this triple source yields.
(see streaming_mode
) Read more
fn try_for_some_triple<F, EF>(
&mut self,
f: &mut F
) -> StreamResult<bool, Self::Error, EF> where
F: FnMut(StreamedTriple<'_, Self::Triple>) -> Result<(), EF>,
EF: Error,
fn try_for_some_triple<F, EF>(
&mut self,
f: &mut F
) -> StreamResult<bool, Self::Error, EF> where
F: FnMut(StreamedTriple<'_, Self::Triple>) -> Result<(), EF>,
EF: Error,
Call f for at least one triple from this triple source, if any. Read more
fn try_for_each_triple<F, E>(
&mut self,
f: F
) -> Result<(), StreamError<Self::Error, E>> where
F: FnMut(StreamedTriple<'_, Self::Triple>) -> Result<(), E>,
E: Error,
fn try_for_each_triple<F, E>(
&mut self,
f: F
) -> Result<(), StreamError<Self::Error, E>> where
F: FnMut(StreamedTriple<'_, Self::Triple>) -> Result<(), E>,
E: Error,
Call f for all triples from this triple source.
fn for_some_triple<F>(&mut self, f: &mut F) -> Result<bool, Self::Error> where
F: FnMut(StreamedTriple<'_, Self::Triple>),
fn for_some_triple<F>(&mut self, f: &mut F) -> Result<bool, Self::Error> where
F: FnMut(StreamedTriple<'_, Self::Triple>),
Call f for at least one triple from this triple source, if any. Read more
fn for_each_triple<F>(&mut self, f: F) -> Result<(), Self::Error> where
F: FnMut(StreamedTriple<'_, Self::Triple>),
fn for_each_triple<F>(&mut self, f: F) -> Result<(), Self::Error> where
F: FnMut(StreamedTriple<'_, Self::Triple>),
Call f for all triples from this triple source.
fn filter_triples<F>(self, filter: F) -> FilterSource<Self, F> where
F: FnMut(&StreamedTriple<'_, Self::Triple>) -> bool,
fn filter_triples<F>(self, filter: F) -> FilterSource<Self, F> where
F: FnMut(&StreamedTriple<'_, Self::Triple>) -> bool,
Creates a triple source which uses a closure to determine if a triple should be yielded.
fn filter_map_triples<F, T>(self, filter_map: F) -> FilterMapSource<Self, F> where
F: FnMut(StreamedTriple<'_, Self::Triple>) -> Option<T>,
fn filter_map_triples<F, T>(self, filter_map: F) -> FilterMapSource<Self, F> where
F: FnMut(StreamedTriple<'_, Self::Triple>) -> Option<T>,
Creates a triple source that both filters and maps.
fn map_triples<F, T>(self, map: F) -> MapSource<Self, F> where
F: FnMut(StreamedTriple<'_, Self::Triple>) -> T,
fn map_triples<F, T>(self, map: F) -> MapSource<Self, F> where
F: FnMut(StreamedTriple<'_, Self::Triple>) -> T,
Takes a closure and creates triple source which yield the result of that closure for each triple.
Returns the bounds on the remaining length of the triple source. Read more
fn collect_triples<G>(
self
) -> Result<G, StreamError<Self::Error, <G as Graph>::Error>> where
G: CollectibleGraph,
fn collect_triples<G>(
self
) -> Result<G, StreamError<Self::Error, <G as Graph>::Error>> where
G: CollectibleGraph,
Collect these triples into a new graph.
fn add_to_graph<G>(
self,
graph: &mut G
) -> Result<usize, StreamError<Self::Error, <G as MutableGraph>::MutationError>> where
G: MutableGraph,
fn add_to_graph<G>(
self,
graph: &mut G
) -> Result<usize, StreamError<Self::Error, <G as MutableGraph>::MutationError>> where
G: MutableGraph,
Insert all triples from this source into the given MutableGraph. Read more
type Error = TurtleError
fn parse_step<E: From<TurtleError>>(
&mut self,
on_triple: &mut impl FnMut(Triple<'_>) -> Result<(), E>
) -> Result<(), E>
fn parse_step<E: From<TurtleError>>(
&mut self,
on_triple: &mut impl FnMut(Triple<'_>) -> Result<(), E>
) -> Result<(), E>
Parses a small chunk of the file and calls on_triple
each time a new triple is read.
(A “small chunk” could be a line for an N-Triples parser.) Read more
Parses the complete file and calls on_triple
each time a new triple is read. Read more