Struct rio_turtle::GTriGParser
source · [−]pub struct GTriGParser<R: BufRead> { /* private fields */ }
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
sourceimpl<R: BufRead> GTriGParser<R>
impl<R: BufRead> GTriGParser<R>
Trait Implementations
sourceimpl<R: BufRead> GeneralizedQuadsParser for GTriGParser<R>
impl<R: BufRead> GeneralizedQuadsParser for GTriGParser<R>
type Error = TurtleError
sourcefn 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
sourcefn parse_all<E>(
&mut self,
on_quad: &mut impl FnMut(GeneralizedQuad<'_>) -> Result<(), E>
) -> Result<(), E> where
E: From<Self::Error>,
fn parse_all<E>(
&mut self,
on_quad: &mut impl FnMut(GeneralizedQuad<'_>) -> Result<(), E>
) -> Result<(), E> where
E: From<Self::Error>,
Parses the complete file and calls on_quad
each time a new quad is read. Read more
sourcefn 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
Auto Trait Implementations
impl<R> RefUnwindSafe for GTriGParser<R> where
R: RefUnwindSafe,
impl<R> Send for GTriGParser<R> where
R: Send,
impl<R> Sync for GTriGParser<R> where
R: Sync,
impl<R> Unpin for GTriGParser<R> where
R: Unpin,
impl<R> UnwindSafe for GTriGParser<R> where
R: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more