[−][src]Struct rio_xml::RdfXmlParser
A RDF XML streaming parser.
It implements the TriplesParser
trait.
It reads the file in streaming.
It does not keep data in memory except a stack for handling nested XML tags, and a set of all
seen rdf:ID
s to detect duplicate ids and fail according to the specification.
Its performances are not optimized yet and hopefully could be significantly enhanced by reducing the number of allocations and copies done by the parser.
Count the number of people using the TriplesParser
API without proper error management:
use rio_xml::{RdfXmlParser, RdfXmlError}; use rio_api::parser::TriplesParser; use rio_api::model::NamedNode; let file = b"<?xml version=\"1.0\"?> <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:schema=\"http://schema.org/\"> <rdf:Description rdf:about=\"http://example.com/foo\"> <rdf:type rdf:resource=\"http://schema.org/Person\" /> <schema:name>Foo</schema:name> </rdf:Description> <schema:Person rdf:about=\"http://example.com/bar\" schema:name=\"Bar\" /> </rdf:RDF>"; 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; RdfXmlParser::new(file.as_ref(), None).parse_all(&mut |t| { if t.predicate == rdf_type && t.object == schema_person.into() { count += 1; } Ok(()) as Result<(), RdfXmlError> })?; assert_eq!(2, count);
Implementations
impl<R: BufRead> RdfXmlParser<R>
[src]
pub fn new(reader: R, base_iri: Option<Iri<String>>) -> Self
[src]
Builds the parser from a BufRead
implementation, and a base IRI for relative IRI resolution.
Trait Implementations
impl<B: BufRead> TripleSource for RdfXmlParser<B>
[src]
type Error = RdfXmlError
The type of errors produced by this source.
type Triple = ScopedRioSourceTriple
Determine the type of Triple
s
that this triple source yields.
(see streaming_mode
Read more
pub 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,
[src]
&mut self,
f: &mut F
) -> StreamResult<bool, Self::Error, EF> where
F: FnMut(StreamedTriple<'_, Self::Triple>) -> Result<(), EF>,
EF: Error,
pub fn try_for_each_triple<F, E>(
&mut self,
f: F
) -> Result<(), StreamError<Self::Error, E>> where
E: Error,
F: FnMut(StreamedTriple<'_, Self::Triple>) -> Result<(), E>,
[src]
&mut self,
f: F
) -> Result<(), StreamError<Self::Error, E>> where
E: Error,
F: FnMut(StreamedTriple<'_, Self::Triple>) -> Result<(), E>,
pub fn for_some_triple<F>(&mut self, f: &mut F) -> Result<bool, Self::Error> where
F: FnMut(StreamedTriple<'_, Self::Triple>),
[src]
F: FnMut(StreamedTriple<'_, Self::Triple>),
pub fn for_each_triple<F>(&mut self, f: F) -> Result<(), Self::Error> where
F: FnMut(StreamedTriple<'_, Self::Triple>),
[src]
F: FnMut(StreamedTriple<'_, Self::Triple>),
pub fn filter_triples<F>(self, filter: F) -> FilterSource<Self, F> where
F: FnMut(&StreamedTriple<'_, Self::Triple>) -> bool,
[src]
F: FnMut(&StreamedTriple<'_, Self::Triple>) -> bool,
pub fn filter_map_triples<F, T>(self, filter_map: F) -> FilterMapSource<Self, F> where
F: FnMut(StreamedTriple<'_, Self::Triple>) -> Option<T>,
[src]
F: FnMut(StreamedTriple<'_, Self::Triple>) -> Option<T>,
pub fn map_triples<F, T>(self, map: F) -> MapSource<Self, F> where
F: FnMut(StreamedTriple<'_, Self::Triple>) -> T,
[src]
F: FnMut(StreamedTriple<'_, Self::Triple>) -> T,
pub fn size_hint_triples(&self) -> (usize, Option<usize>)
[src]
pub fn collect_triples<G>(
self
) -> Result<G, StreamError<Self::Error, <G as Graph>::Error>> where
G: CollectibleGraph,
[src]
self
) -> Result<G, StreamError<Self::Error, <G as Graph>::Error>> where
G: CollectibleGraph,
pub fn add_to_graph<G>(
self,
graph: &mut G
) -> Result<usize, StreamError<Self::Error, <G as MutableGraph>::MutationError>> where
G: MutableGraph,
[src]
self,
graph: &mut G
) -> Result<usize, StreamError<Self::Error, <G as MutableGraph>::MutationError>> where
G: MutableGraph,
impl<R: BufRead> TriplesParser for RdfXmlParser<R>
[src]
type Error = RdfXmlError
pub fn parse_step<E: From<RdfXmlError>>(
&mut self,
on_triple: &mut impl FnMut(Triple<'_>) -> Result<(), E>
) -> Result<(), E>
[src]
&mut self,
on_triple: &mut impl FnMut(Triple<'_>) -> Result<(), E>
) -> Result<(), E>
pub fn is_end(&self) -> bool
[src]
pub fn parse_all<E>(
&mut self,
on_triple: &mut impl FnMut(Triple<'_>) -> Result<(), E>
) -> Result<(), E> where
E: From<Self::Error>,
[src]
&mut self,
on_triple: &mut impl FnMut(Triple<'_>) -> Result<(), E>
) -> Result<(), E> where
E: From<Self::Error>,
pub 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>,
Auto Trait Implementations
impl<R> RefUnwindSafe for RdfXmlParser<R> where
R: RefUnwindSafe,
[src]
R: RefUnwindSafe,
impl<R> Send for RdfXmlParser<R> where
R: Send,
[src]
R: Send,
impl<R> Sync for RdfXmlParser<R> where
R: Sync,
[src]
R: Sync,
impl<R> Unpin for RdfXmlParser<R> where
R: Unpin,
[src]
R: Unpin,
impl<R> UnwindSafe for RdfXmlParser<R> where
R: UnwindSafe,
[src]
R: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
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.
pub 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>,