Struct rio_turtle::GTriGParser
source ·
[−]pub struct GTriGParser<R: BufRead> { /* fields omitted */ }
Expand description
A TriG streaming parser parsing generalized quads.
Warning: RDF-star is not supported yet.
It implements the GeneralizedQuadsParser
trait.
Using it requires to enable the generalized
feature.
Count the number of people using the QuadsParser
API:
use rio_turtle::{GTriGParser, TurtleError};
use rio_api::parser::GeneralizedQuadsParser;
use rio_api::model::NamedNode;
let file = b"@prefix schema: <http://schema.org/> .
<http://example/> {
<http://example.com/foo> a schema:Person ;
schema:name ?name .
<http://example.com/bar> a schema:Person ;
schema:name ?name .
}";
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;
GTriGParser::new(file.as_ref(), None).parse_all(&mut |t| {
if t.predicate == rdf_type.into() && t.object == schema_person.into() {
count += 1;
}
Ok(()) as Result<(), TurtleError>
})?;
assert_eq!(2, count);
Implementations
Trait Implementations
type Error = TurtleError
fn parse_step<E: From<TurtleError>>(
&mut self,
on_quad: &mut impl FnMut(GeneralizedQuad<'_>) -> Result<(), E>
) -> Result<(), E>
fn parse_step<E: From<TurtleError>>(
&mut self,
on_quad: &mut impl FnMut(GeneralizedQuad<'_>) -> Result<(), E>
) -> Result<(), E>
Parses a small chunk of the file and calls on_quad
each time a new quad is read.
(A “small chunk” could be a line for an N-Quads parser.) Read more
Parses the complete file and calls on_quad
each time a new quad is read. Read more
fn into_iter<T, E, F>(
self,
convert_quad: F
) -> GeneralizedQuadsParserIterator<T, E, F, Self> where
E: From<Self::Error>,
F: FnMut(GeneralizedQuad<'_>) -> Result<T, E>,
fn into_iter<T, E, F>(
self,
convert_quad: F
) -> GeneralizedQuadsParserIterator<T, E, F, Self> where
E: From<Self::Error>,
F: FnMut(GeneralizedQuad<'_>) -> Result<T, E>,
Converts the parser into a Result<T, E>
iterator. Read more
type Error = <GTriGParser<B> as GeneralizedQuadsParser>::Error
type Error = <GTriGParser<B> as GeneralizedQuadsParser>::Error
The type of errors produced by this source.
type Quad = ScopedGeneralizedQuad
type Quad = ScopedGeneralizedQuad
Determine the type of Quad
s
that this quad source yields.
(see streaming_mode
Read more
fn try_for_some_quad<F, EF>(
&mut self,
f: &mut F
) -> StreamResult<bool, Self::Error, EF> where
F: FnMut(StreamedQuad<'_, Self::Quad>) -> Result<(), EF>,
EF: Error,
fn try_for_some_quad<F, EF>(
&mut self,
f: &mut F
) -> StreamResult<bool, Self::Error, EF> where
F: FnMut(StreamedQuad<'_, Self::Quad>) -> Result<(), EF>,
EF: Error,
Call f for at least one quad from this quad source, if any. Read more
fn try_for_each_quad<F, E>(
&mut self,
f: F
) -> Result<(), StreamError<Self::Error, E>> where
F: FnMut(StreamedQuad<'_, Self::Quad>) -> Result<(), E>,
E: Error,
fn try_for_each_quad<F, E>(
&mut self,
f: F
) -> Result<(), StreamError<Self::Error, E>> where
F: FnMut(StreamedQuad<'_, Self::Quad>) -> Result<(), E>,
E: Error,
Call f for all quads from this quad source.
fn for_some_quad<F>(&mut self, f: &mut F) -> Result<bool, Self::Error> where
F: FnMut(StreamedQuad<'_, Self::Quad>),
fn for_some_quad<F>(&mut self, f: &mut F) -> Result<bool, Self::Error> where
F: FnMut(StreamedQuad<'_, Self::Quad>),
Call f for at least one quad from this quad source, if any. Read more
fn for_each_quad<F>(&mut self, f: F) -> Result<(), Self::Error> where
F: FnMut(StreamedQuad<'_, Self::Quad>),
fn for_each_quad<F>(&mut self, f: F) -> Result<(), Self::Error> where
F: FnMut(StreamedQuad<'_, Self::Quad>),
Call f for all quads from this quad source.
fn filter_quads<F>(self, filter: F) -> FilterSource<Self, F> where
F: FnMut(&StreamedQuad<'_, Self::Quad>) -> bool,
fn filter_quads<F>(self, filter: F) -> FilterSource<Self, F> where
F: FnMut(&StreamedQuad<'_, Self::Quad>) -> bool,
Creates a quad source which uses a closure to determine if a quad should be yielded.
fn filter_map_quads<F, T>(self, filter_map: F) -> FilterMapSource<Self, F> where
F: FnMut(StreamedQuad<'_, Self::Quad>) -> Option<T>,
fn filter_map_quads<F, T>(self, filter_map: F) -> FilterMapSource<Self, F> where
F: FnMut(StreamedQuad<'_, Self::Quad>) -> Option<T>,
Creates a quad source that both filters and maps.
Takes a closure and creates quad source which yield the result of that closure for each quad.
Returns the bounds on the remaining length of the quad source. Read more
fn collect_quads<D>(
self
) -> Result<D, StreamError<Self::Error, <D as Dataset>::Error>> where
D: CollectibleDataset,
fn collect_quads<D>(
self
) -> Result<D, StreamError<Self::Error, <D as Dataset>::Error>> where
D: CollectibleDataset,
Collect these quads into a new dataset.
fn add_to_dataset<D>(
self,
dataset: &mut D
) -> Result<usize, StreamError<Self::Error, <D as MutableDataset>::MutationError>> where
D: MutableDataset,
fn add_to_dataset<D>(
self,
dataset: &mut D
) -> Result<usize, StreamError<Self::Error, <D as MutableDataset>::MutationError>> where
D: MutableDataset,
Insert all quads from this source into the given MutableDataset. Read more