[−][src]Struct rio_turtle::NTriplesParser
A N-Triples streaming parser.
It implements the TripleParser
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 of people using the TripleParser
API:
use rio_turtle::NTriplesParser; use rio_api::parser::TripleParser; 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()).unwrap().parse_all(&mut |t| { if t.predicate == rdf_type && t.object == schema_person.into() { count += 1; } }).unwrap(); assert_eq!(2, count)
Methods
impl<R: BufRead> NTriplesParser<R>
[src]
pub fn new(reader: R) -> Result<Self, TurtleError>
[src]
Trait Implementations
impl<R: BufRead> TripleParser for NTriplesParser<R>
[src]
type Error = TurtleError
fn parse_step(
&mut self,
on_triple: &mut impl FnMut(Triple)
) -> Result<(), TurtleError>
[src]
&mut self,
on_triple: &mut impl FnMut(Triple)
) -> Result<(), TurtleError>
fn is_end(&self) -> bool
[src]
fn parse_all<impl FnMut(Triple) -> ()>(
&mut self,
on_triple: &mut impl FnMut(Triple) -> ()
) -> Result<(), Self::Error> where
impl FnMut(Triple) -> (): FnMut(Triple),
[src]
&mut self,
on_triple: &mut impl FnMut(Triple) -> ()
) -> Result<(), Self::Error> where
impl FnMut(Triple) -> (): FnMut(Triple),
Parses the complete file and calls on_triple
each time a new triple is read.
fn into_iter<T, E, F>(
self,
convert_triple: F
) -> TriplesParserIterator<T, E, F, Self> where
E: From<Self::Error>,
F: FnMut(Triple) -> Result<T, E>,
[src]
self,
convert_triple: F
) -> TriplesParserIterator<T, E, F, Self> where
E: From<Self::Error>,
F: FnMut(Triple) -> Result<T, E>,
Converts the parser into a Result<T, E>
iterator. Read more
Auto Trait Implementations
impl<R> Sync for NTriplesParser<R> where
R: Sync,
R: Sync,
impl<R> Send for NTriplesParser<R> where
R: Send,
R: Send,
impl<R> Unpin for NTriplesParser<R> where
R: Unpin,
R: Unpin,
impl<R> RefUnwindSafe for NTriplesParser<R> where
R: RefUnwindSafe,
R: RefUnwindSafe,
impl<R> UnwindSafe for NTriplesParser<R> where
R: UnwindSafe,
R: UnwindSafe,
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,