Renames "parse_from_read" to "parse_read"

pull/582/head
Tpt 1 year ago committed by Thomas Tanon
parent 922023b1da
commit 3adf33d2f4
  1. 2
      fuzz/fuzz_targets/nquads.rs
  2. 4
      fuzz/fuzz_targets/rdf_xml.rs
  3. 2
      fuzz/fuzz_targets/trig.rs
  4. 2
      lib/oxrdfxml/README.md
  5. 18
      lib/oxrdfxml/src/parser.rs
  6. 2
      lib/oxttl/README.md
  7. 22
      lib/oxttl/src/n3.rs
  8. 22
      lib/oxttl/src/nquads.rs
  9. 22
      lib/oxttl/src/ntriples.rs
  10. 4
      lib/oxttl/src/toolkit/parser.rs
  11. 22
      lib/oxttl/src/trig.rs
  12. 22
      lib/oxttl/src/turtle.rs
  13. 12
      lib/src/io/read.rs
  14. 2
      testsuite/src/files.rs

@ -33,7 +33,7 @@ fuzz_target!(|data: &[u8]| {
// We parse the serialization // We parse the serialization
let new_quads = NQuadsParser::new() let new_quads = NQuadsParser::new()
.with_quoted_triples() .with_quoted_triples()
.parse_from_read(new_serialization.as_slice()) .parse_read(new_serialization.as_slice())
.collect::<Result<Vec<_>, _>>() .collect::<Result<Vec<_>, _>>()
.map_err(|e| { .map_err(|e| {
format!( format!(

@ -6,7 +6,7 @@ use oxrdfxml::{RdfXmlParser, RdfXmlSerializer};
fuzz_target!(|data: &[u8]| { fuzz_target!(|data: &[u8]| {
// We parse // We parse
let mut triples = Vec::new(); let mut triples = Vec::new();
for triple in RdfXmlParser::new().parse_from_read(data) { for triple in RdfXmlParser::new().parse_read(data) {
if let Ok(triple) = triple { if let Ok(triple) = triple {
triples.push(triple); triples.push(triple);
} }
@ -21,7 +21,7 @@ fuzz_target!(|data: &[u8]| {
// We parse the serialization // We parse the serialization
let new_triples = RdfXmlParser::new() let new_triples = RdfXmlParser::new()
.parse_from_read(new_serialization.as_slice()) .parse_read(new_serialization.as_slice())
.collect::<Result<Vec<_>, _>>() .collect::<Result<Vec<_>, _>>()
.map_err(|e| { .map_err(|e| {
format!( format!(

@ -37,7 +37,7 @@ fuzz_target!(|data: &[u8]| {
// We parse the serialization // We parse the serialization
let new_quads = TriGParser::new() let new_quads = TriGParser::new()
.with_quoted_triples() .with_quoted_triples()
.parse_from_read(new_serialization.as_slice()) .parse_read(new_serialization.as_slice())
.collect::<Result<Vec<_>, _>>() .collect::<Result<Vec<_>, _>>()
.map_err(|e| { .map_err(|e| {
format!( format!(

@ -25,7 +25,7 @@ let file = b"<?xml version=\"1.0\"?>
let schema_person = NamedNodeRef::new("http://schema.org/Person").unwrap(); let schema_person = NamedNodeRef::new("http://schema.org/Person").unwrap();
let mut count = 0; let mut count = 0;
for triple in RdfXmlParser::new().parse_from_read(file.as_ref()) { for triple in RdfXmlParser::new().parse_read(file.as_ref()) {
let triple = triple.unwrap(); let triple = triple.unwrap();
if triple.predicate == rdf::TYPE && triple.object == schema_person.into() { if triple.predicate == rdf::TYPE && triple.object == schema_person.into() {
count += 1; count += 1;

@ -40,7 +40,7 @@ use tokio::io::{AsyncRead, BufReader as AsyncBufReader};
/// ///
/// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?;
/// let mut count = 0; /// let mut count = 0;
/// for triple in RdfXmlParser::new().parse_from_read(file.as_ref()) { /// for triple in RdfXmlParser::new().parse_read(file.as_ref()) {
/// let triple = triple?; /// let triple = triple?;
/// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() { /// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() {
/// count += 1; /// count += 1;
@ -85,7 +85,7 @@ impl RdfXmlParser {
/// ///
/// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?;
/// let mut count = 0; /// let mut count = 0;
/// for triple in RdfXmlParser::new().parse_from_read(file.as_ref()) { /// for triple in RdfXmlParser::new().parse_read(file.as_ref()) {
/// let triple = triple?; /// let triple = triple?;
/// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() { /// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() {
/// count += 1; /// count += 1;
@ -94,7 +94,7 @@ impl RdfXmlParser {
/// assert_eq!(2, count); /// assert_eq!(2, count);
/// # Result::<_,Box<dyn std::error::Error>>::Ok(()) /// # Result::<_,Box<dyn std::error::Error>>::Ok(())
/// ``` /// ```
pub fn parse_from_read<R: Read>(&self, read: R) -> FromReadRdfXmlReader<R> { pub fn parse_read<R: Read>(&self, read: R) -> FromReadRdfXmlReader<R> {
FromReadRdfXmlReader { FromReadRdfXmlReader {
results: Vec::new(), results: Vec::new(),
reader: self.parse(BufReader::new(read)), reader: self.parse(BufReader::new(read)),
@ -122,7 +122,7 @@ impl RdfXmlParser {
/// ///
/// let schema_person = NamedNodeRef::new_unchecked("http://schema.org/Person"); /// let schema_person = NamedNodeRef::new_unchecked("http://schema.org/Person");
/// let mut count = 0; /// let mut count = 0;
/// let mut parser = RdfXmlParser::new().parse_from_tokio_async_read(file.as_ref()); /// let mut parser = RdfXmlParser::new().parse_tokio_async_read(file.as_ref());
/// while let Some(triple) = parser.next().await { /// while let Some(triple) = parser.next().await {
/// let triple = triple?; /// let triple = triple?;
/// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() { /// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() {
@ -134,7 +134,7 @@ impl RdfXmlParser {
/// } /// }
/// ``` /// ```
#[cfg(feature = "async-tokio")] #[cfg(feature = "async-tokio")]
pub fn parse_from_tokio_async_read<R: AsyncRead + Unpin>( pub fn parse_tokio_async_read<R: AsyncRead + Unpin>(
&self, &self,
read: R, read: R,
) -> FromTokioAsyncReadRdfXmlReader<R> { ) -> FromTokioAsyncReadRdfXmlReader<R> {
@ -161,7 +161,7 @@ impl RdfXmlParser {
} }
} }
/// Parses a RDF/XML file from a [`Read`] implementation. Can be built using [`RdfXmlParser::parse_from_read`]. /// Parses a RDF/XML file from a [`Read`] implementation. Can be built using [`RdfXmlParser::parse_read`].
/// ///
/// Count the number of people: /// Count the number of people:
/// ``` /// ```
@ -179,7 +179,7 @@ impl RdfXmlParser {
/// ///
/// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?;
/// let mut count = 0; /// let mut count = 0;
/// for triple in RdfXmlParser::new().parse_from_read(file.as_ref()) { /// for triple in RdfXmlParser::new().parse_read(file.as_ref()) {
/// let triple = triple?; /// let triple = triple?;
/// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() { /// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() {
/// count += 1; /// count += 1;
@ -227,7 +227,7 @@ impl<R: Read> FromReadRdfXmlReader<R> {
} }
} }
/// Parses a RDF/XML file from a [`AsyncRead`] implementation. Can be built using [`RdfXmlParser::parse_from_tokio_async_read`]. /// Parses a RDF/XML file from a [`AsyncRead`] implementation. Can be built using [`RdfXmlParser::parse_tokio_async_read`].
/// ///
/// Count the number of people: /// Count the number of people:
/// ``` /// ```
@ -247,7 +247,7 @@ impl<R: Read> FromReadRdfXmlReader<R> {
/// ///
/// let schema_person = NamedNodeRef::new_unchecked("http://schema.org/Person"); /// let schema_person = NamedNodeRef::new_unchecked("http://schema.org/Person");
/// let mut count = 0; /// let mut count = 0;
/// let mut parser = RdfXmlParser::new().parse_from_tokio_async_read(file.as_ref()); /// let mut parser = RdfXmlParser::new().parse_tokio_async_read(file.as_ref());
/// while let Some(triple) = parser.next().await { /// while let Some(triple) = parser.next().await {
/// let triple = triple?; /// let triple = triple?;
/// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() { /// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() {

@ -27,7 +27,7 @@ let file = b"@base <http://example.com/> .
let schema_person = NamedNodeRef::new("http://schema.org/Person").unwrap(); let schema_person = NamedNodeRef::new("http://schema.org/Person").unwrap();
let mut count = 0; let mut count = 0;
for triple in TurtleParser::new().parse_from_read(file.as_ref()) { for triple in TurtleParser::new().parse_read(file.as_ref()) {
let triple = triple.unwrap(); let triple = triple.unwrap();
if triple.predicate == rdf::TYPE && triple.object == schema_person.into() { if triple.predicate == rdf::TYPE && triple.object == schema_person.into() {
count += 1; count += 1;

@ -194,7 +194,7 @@ impl From<Quad> for N3Quad {
/// let rdf_type = N3Term::NamedNode(rdf::TYPE.into_owned()); /// let rdf_type = N3Term::NamedNode(rdf::TYPE.into_owned());
/// let schema_person = N3Term::NamedNode(NamedNode::new("http://schema.org/Person")?); /// let schema_person = N3Term::NamedNode(NamedNode::new("http://schema.org/Person")?);
/// let mut count = 0; /// let mut count = 0;
/// for triple in N3Parser::new().parse_from_read(file.as_ref()) { /// for triple in N3Parser::new().parse_read(file.as_ref()) {
/// let triple = triple?; /// let triple = triple?;
/// if triple.predicate == rdf_type && triple.object == schema_person { /// if triple.predicate == rdf_type && triple.object == schema_person {
/// count += 1; /// count += 1;
@ -250,7 +250,7 @@ impl N3Parser {
/// let rdf_type = N3Term::NamedNode(NamedNode::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")?); /// let rdf_type = N3Term::NamedNode(NamedNode::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")?);
/// let schema_person = N3Term::NamedNode(NamedNode::new("http://schema.org/Person")?); /// let schema_person = N3Term::NamedNode(NamedNode::new("http://schema.org/Person")?);
/// let mut count = 0; /// let mut count = 0;
/// for triple in N3Parser::new().parse_from_read(file.as_ref()) { /// for triple in N3Parser::new().parse_read(file.as_ref()) {
/// let triple = triple?; /// let triple = triple?;
/// if triple.predicate == rdf_type && triple.object == schema_person { /// if triple.predicate == rdf_type && triple.object == schema_person {
/// count += 1; /// count += 1;
@ -259,9 +259,9 @@ impl N3Parser {
/// assert_eq!(2, count); /// assert_eq!(2, count);
/// # Result::<_,Box<dyn std::error::Error>>::Ok(()) /// # Result::<_,Box<dyn std::error::Error>>::Ok(())
/// ``` /// ```
pub fn parse_from_read<R: Read>(&self, read: R) -> FromReadN3Reader<R> { pub fn parse_read<R: Read>(&self, read: R) -> FromReadN3Reader<R> {
FromReadN3Reader { FromReadN3Reader {
inner: self.parse().parser.parse_from_read(read), inner: self.parse().parser.parse_read(read),
} }
} }
@ -285,7 +285,7 @@ impl N3Parser {
/// let rdf_type = N3Term::NamedNode(rdf::TYPE.into_owned()); /// let rdf_type = N3Term::NamedNode(rdf::TYPE.into_owned());
/// let schema_person = N3Term::NamedNode(NamedNode::new_unchecked("http://schema.org/Person")); /// let schema_person = N3Term::NamedNode(NamedNode::new_unchecked("http://schema.org/Person"));
/// let mut count = 0; /// let mut count = 0;
/// let mut parser = N3Parser::new().parse_from_tokio_async_read(file.as_ref()); /// let mut parser = N3Parser::new().parse_tokio_async_read(file.as_ref());
/// while let Some(triple) = parser.next().await { /// while let Some(triple) = parser.next().await {
/// let triple = triple?; /// let triple = triple?;
/// if triple.predicate == rdf_type && triple.object == schema_person { /// if triple.predicate == rdf_type && triple.object == schema_person {
@ -297,12 +297,12 @@ impl N3Parser {
/// } /// }
/// ``` /// ```
#[cfg(feature = "async-tokio")] #[cfg(feature = "async-tokio")]
pub fn parse_from_tokio_async_read<R: AsyncRead + Unpin>( pub fn parse_tokio_async_read<R: AsyncRead + Unpin>(
&self, &self,
read: R, read: R,
) -> FromTokioAsyncReadN3Reader<R> { ) -> FromTokioAsyncReadN3Reader<R> {
FromTokioAsyncReadN3Reader { FromTokioAsyncReadN3Reader {
inner: self.parse().parser.parse_from_tokio_async_read(read), inner: self.parse().parser.parse_tokio_async_read(read),
} }
} }
@ -350,7 +350,7 @@ impl N3Parser {
} }
} }
/// Parses a N3 file from a [`Read`] implementation. Can be built using [`N3Parser::parse_from_read`]. /// Parses a N3 file from a [`Read`] implementation. Can be built using [`N3Parser::parse_read`].
/// ///
/// Count the number of people: /// Count the number of people:
/// ``` /// ```
@ -367,7 +367,7 @@ impl N3Parser {
/// let rdf_type = N3Term::NamedNode(rdf::TYPE.into_owned()); /// let rdf_type = N3Term::NamedNode(rdf::TYPE.into_owned());
/// let schema_person = N3Term::NamedNode(NamedNode::new("http://schema.org/Person")?); /// let schema_person = N3Term::NamedNode(NamedNode::new("http://schema.org/Person")?);
/// let mut count = 0; /// let mut count = 0;
/// for triple in N3Parser::new().parse_from_read(file.as_ref()) { /// for triple in N3Parser::new().parse_read(file.as_ref()) {
/// let triple = triple?; /// let triple = triple?;
/// if triple.predicate == rdf_type && triple.object == schema_person { /// if triple.predicate == rdf_type && triple.object == schema_person {
/// count += 1; /// count += 1;
@ -388,7 +388,7 @@ impl<R: Read> Iterator for FromReadN3Reader<R> {
} }
} }
/// Parses a N3 file from a [`AsyncRead`] implementation. Can be built using [`N3Parser::parse_from_tokio_async_read`]. /// Parses a N3 file from a [`AsyncRead`] implementation. Can be built using [`N3Parser::parse_tokio_async_read`].
/// ///
/// Count the number of people: /// Count the number of people:
/// ``` /// ```
@ -408,7 +408,7 @@ impl<R: Read> Iterator for FromReadN3Reader<R> {
/// let rdf_type = N3Term::NamedNode(rdf::TYPE.into_owned()); /// let rdf_type = N3Term::NamedNode(rdf::TYPE.into_owned());
/// let schema_person = N3Term::NamedNode(NamedNode::new_unchecked("http://schema.org/Person")); /// let schema_person = N3Term::NamedNode(NamedNode::new_unchecked("http://schema.org/Person"));
/// let mut count = 0; /// let mut count = 0;
/// let mut parser = N3Parser::new().parse_from_tokio_async_read(file.as_ref()); /// let mut parser = N3Parser::new().parse_tokio_async_read(file.as_ref());
/// while let Some(triple) = parser.next().await { /// while let Some(triple) = parser.next().await {
/// let triple = triple?; /// let triple = triple?;
/// if triple.predicate == rdf_type && triple.object == schema_person { /// if triple.predicate == rdf_type && triple.object == schema_person {

@ -25,7 +25,7 @@ use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt};
/// ///
/// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?;
/// let mut count = 0; /// let mut count = 0;
/// for quad in NQuadsParser::new().parse_from_read(file.as_ref()) { /// for quad in NQuadsParser::new().parse_read(file.as_ref()) {
/// let quad = quad?; /// let quad = quad?;
/// if quad.predicate == rdf::TYPE && quad.object == schema_person.into() { /// if quad.predicate == rdf::TYPE && quad.object == schema_person.into() {
/// count += 1; /// count += 1;
@ -70,7 +70,7 @@ impl NQuadsParser {
/// ///
/// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?;
/// let mut count = 0; /// let mut count = 0;
/// for quad in NQuadsParser::new().parse_from_read(file.as_ref()) { /// for quad in NQuadsParser::new().parse_read(file.as_ref()) {
/// let quad = quad?; /// let quad = quad?;
/// if quad.predicate == rdf::TYPE && quad.object == schema_person.into() { /// if quad.predicate == rdf::TYPE && quad.object == schema_person.into() {
/// count += 1; /// count += 1;
@ -79,9 +79,9 @@ impl NQuadsParser {
/// assert_eq!(2, count); /// assert_eq!(2, count);
/// # Result::<_,Box<dyn std::error::Error>>::Ok(()) /// # Result::<_,Box<dyn std::error::Error>>::Ok(())
/// ``` /// ```
pub fn parse_from_read<R: Read>(&self, read: R) -> FromReadNQuadsReader<R> { pub fn parse_read<R: Read>(&self, read: R) -> FromReadNQuadsReader<R> {
FromReadNQuadsReader { FromReadNQuadsReader {
inner: self.parse().parser.parse_from_read(read), inner: self.parse().parser.parse_read(read),
} }
} }
@ -101,7 +101,7 @@ impl NQuadsParser {
/// ///
/// let schema_person = NamedNodeRef::new_unchecked("http://schema.org/Person"); /// let schema_person = NamedNodeRef::new_unchecked("http://schema.org/Person");
/// let mut count = 0; /// let mut count = 0;
/// let mut parser = NQuadsParser::new().parse_from_tokio_async_read(file.as_ref()); /// let mut parser = NQuadsParser::new().parse_tokio_async_read(file.as_ref());
/// while let Some(triple) = parser.next().await { /// while let Some(triple) = parser.next().await {
/// let triple = triple?; /// let triple = triple?;
/// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() { /// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() {
@ -113,12 +113,12 @@ impl NQuadsParser {
/// } /// }
/// ``` /// ```
#[cfg(feature = "async-tokio")] #[cfg(feature = "async-tokio")]
pub fn parse_from_tokio_async_read<R: AsyncRead + Unpin>( pub fn parse_tokio_async_read<R: AsyncRead + Unpin>(
&self, &self,
read: R, read: R,
) -> FromTokioAsyncReadNQuadsReader<R> { ) -> FromTokioAsyncReadNQuadsReader<R> {
FromTokioAsyncReadNQuadsReader { FromTokioAsyncReadNQuadsReader {
inner: self.parse().parser.parse_from_tokio_async_read(read), inner: self.parse().parser.parse_tokio_async_read(read),
} }
} }
@ -170,7 +170,7 @@ impl NQuadsParser {
} }
} }
/// Parses a N-Quads file from a [`Read`] implementation. Can be built using [`NQuadsParser::parse_from_read`]. /// Parses a N-Quads file from a [`Read`] implementation. Can be built using [`NQuadsParser::parse_read`].
/// ///
/// Count the number of people: /// Count the number of people:
/// ``` /// ```
@ -184,7 +184,7 @@ impl NQuadsParser {
/// ///
/// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?;
/// let mut count = 0; /// let mut count = 0;
/// for quad in NQuadsParser::new().parse_from_read(file.as_ref()) { /// for quad in NQuadsParser::new().parse_read(file.as_ref()) {
/// let quad = quad?; /// let quad = quad?;
/// if quad.predicate == rdf::TYPE && quad.object == schema_person.into() { /// if quad.predicate == rdf::TYPE && quad.object == schema_person.into() {
/// count += 1; /// count += 1;
@ -205,7 +205,7 @@ impl<R: Read> Iterator for FromReadNQuadsReader<R> {
} }
} }
/// Parses a N-Quads file from a [`AsyncRead`] implementation. Can be built using [`NQuadsParser::parse_from_tokio_async_read`]. /// Parses a N-Quads file from a [`AsyncRead`] implementation. Can be built using [`NQuadsParser::parse_tokio_async_read`].
/// ///
/// Count the number of people: /// Count the number of people:
/// ``` /// ```
@ -221,7 +221,7 @@ impl<R: Read> Iterator for FromReadNQuadsReader<R> {
/// ///
/// let schema_person = NamedNodeRef::new_unchecked("http://schema.org/Person"); /// let schema_person = NamedNodeRef::new_unchecked("http://schema.org/Person");
/// let mut count = 0; /// let mut count = 0;
/// let mut parser = NQuadsParser::new().parse_from_tokio_async_read(file.as_ref()); /// let mut parser = NQuadsParser::new().parse_tokio_async_read(file.as_ref());
/// while let Some(triple) = parser.next().await { /// while let Some(triple) = parser.next().await {
/// let triple = triple?; /// let triple = triple?;
/// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() { /// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() {

@ -26,7 +26,7 @@ use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt};
/// ///
/// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?;
/// let mut count = 0; /// let mut count = 0;
/// for triple in NTriplesParser::new().parse_from_read(file.as_ref()) { /// for triple in NTriplesParser::new().parse_read(file.as_ref()) {
/// let triple = triple?; /// let triple = triple?;
/// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() { /// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() {
/// count += 1; /// count += 1;
@ -71,7 +71,7 @@ impl NTriplesParser {
/// ///
/// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?;
/// let mut count = 0; /// let mut count = 0;
/// for triple in NTriplesParser::new().parse_from_read(file.as_ref()) { /// for triple in NTriplesParser::new().parse_read(file.as_ref()) {
/// let triple = triple?; /// let triple = triple?;
/// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() { /// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() {
/// count += 1; /// count += 1;
@ -80,9 +80,9 @@ impl NTriplesParser {
/// assert_eq!(2, count); /// assert_eq!(2, count);
/// # Result::<_,Box<dyn std::error::Error>>::Ok(()) /// # Result::<_,Box<dyn std::error::Error>>::Ok(())
/// ``` /// ```
pub fn parse_from_read<R: Read>(&self, read: R) -> FromReadNTriplesReader<R> { pub fn parse_read<R: Read>(&self, read: R) -> FromReadNTriplesReader<R> {
FromReadNTriplesReader { FromReadNTriplesReader {
inner: self.parse().parser.parse_from_read(read), inner: self.parse().parser.parse_read(read),
} }
} }
@ -102,7 +102,7 @@ impl NTriplesParser {
/// ///
/// let schema_person = NamedNodeRef::new_unchecked("http://schema.org/Person"); /// let schema_person = NamedNodeRef::new_unchecked("http://schema.org/Person");
/// let mut count = 0; /// let mut count = 0;
/// let mut parser = NTriplesParser::new().parse_from_tokio_async_read(file.as_ref()); /// let mut parser = NTriplesParser::new().parse_tokio_async_read(file.as_ref());
/// while let Some(triple) = parser.next().await { /// while let Some(triple) = parser.next().await {
/// let triple = triple?; /// let triple = triple?;
/// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() { /// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() {
@ -114,12 +114,12 @@ impl NTriplesParser {
/// } /// }
/// ``` /// ```
#[cfg(feature = "async-tokio")] #[cfg(feature = "async-tokio")]
pub fn parse_from_tokio_async_read<R: AsyncRead + Unpin>( pub fn parse_tokio_async_read<R: AsyncRead + Unpin>(
&self, &self,
read: R, read: R,
) -> FromTokioAsyncReadNTriplesReader<R> { ) -> FromTokioAsyncReadNTriplesReader<R> {
FromTokioAsyncReadNTriplesReader { FromTokioAsyncReadNTriplesReader {
inner: self.parse().parser.parse_from_tokio_async_read(read), inner: self.parse().parser.parse_tokio_async_read(read),
} }
} }
@ -171,7 +171,7 @@ impl NTriplesParser {
} }
} }
/// Parses a N-Triples file from a [`Read`] implementation. Can be built using [`NTriplesParser::parse_from_read`]. /// Parses a N-Triples file from a [`Read`] implementation. Can be built using [`NTriplesParser::parse_read`].
/// ///
/// Count the number of people: /// Count the number of people:
/// ``` /// ```
@ -185,7 +185,7 @@ impl NTriplesParser {
/// ///
/// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?;
/// let mut count = 0; /// let mut count = 0;
/// for triple in NTriplesParser::new().parse_from_read(file.as_ref()) { /// for triple in NTriplesParser::new().parse_read(file.as_ref()) {
/// let triple = triple?; /// let triple = triple?;
/// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() { /// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() {
/// count += 1; /// count += 1;
@ -206,7 +206,7 @@ impl<R: Read> Iterator for FromReadNTriplesReader<R> {
} }
} }
/// Parses a N-Triples file from a [`AsyncRead`] implementation. Can be built using [`NTriplesParser::parse_from_tokio_async_read`]. /// Parses a N-Triples file from a [`AsyncRead`] implementation. Can be built using [`NTriplesParser::parse_tokio_async_read`].
/// ///
/// Count the number of people: /// Count the number of people:
/// ``` /// ```
@ -222,7 +222,7 @@ impl<R: Read> Iterator for FromReadNTriplesReader<R> {
/// ///
/// let schema_person = NamedNodeRef::new_unchecked("http://schema.org/Person"); /// let schema_person = NamedNodeRef::new_unchecked("http://schema.org/Person");
/// let mut count = 0; /// let mut count = 0;
/// let mut parser = NTriplesParser::new().parse_from_tokio_async_read(file.as_ref()); /// let mut parser = NTriplesParser::new().parse_tokio_async_read(file.as_ref());
/// while let Some(triple) = parser.next().await { /// while let Some(triple) = parser.next().await {
/// let triple = triple?; /// let triple = triple?;
/// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() { /// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() {

@ -113,12 +113,12 @@ impl<RR: RuleRecognizer> Parser<RR> {
} }
} }
pub fn parse_from_read<R: Read>(self, read: R) -> FromReadIterator<R, RR> { pub fn parse_read<R: Read>(self, read: R) -> FromReadIterator<R, RR> {
FromReadIterator { read, parser: self } FromReadIterator { read, parser: self }
} }
#[cfg(feature = "async-tokio")] #[cfg(feature = "async-tokio")]
pub fn parse_from_tokio_async_read<R: AsyncRead + Unpin>( pub fn parse_tokio_async_read<R: AsyncRead + Unpin>(
self, self,
read: R, read: R,
) -> FromTokioAsyncReadIterator<R, RR> { ) -> FromTokioAsyncReadIterator<R, RR> {

@ -30,7 +30,7 @@ use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt};
/// ///
/// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?;
/// let mut count = 0; /// let mut count = 0;
/// for quad in TriGParser::new().parse_from_read(file.as_ref()) { /// for quad in TriGParser::new().parse_read(file.as_ref()) {
/// let quad = quad?; /// let quad = quad?;
/// if quad.predicate == rdf::TYPE && quad.object == schema_person.into() { /// if quad.predicate == rdf::TYPE && quad.object == schema_person.into() {
/// count += 1; /// count += 1;
@ -96,7 +96,7 @@ impl TriGParser {
/// ///
/// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?;
/// let mut count = 0; /// let mut count = 0;
/// for quad in TriGParser::new().parse_from_read(file.as_ref()) { /// for quad in TriGParser::new().parse_read(file.as_ref()) {
/// let quad = quad?; /// let quad = quad?;
/// if quad.predicate == rdf::TYPE && quad.object == schema_person.into() { /// if quad.predicate == rdf::TYPE && quad.object == schema_person.into() {
/// count += 1; /// count += 1;
@ -105,9 +105,9 @@ impl TriGParser {
/// assert_eq!(2, count); /// assert_eq!(2, count);
/// # Result::<_,Box<dyn std::error::Error>>::Ok(()) /// # Result::<_,Box<dyn std::error::Error>>::Ok(())
/// ``` /// ```
pub fn parse_from_read<R: Read>(&self, read: R) -> FromReadTriGReader<R> { pub fn parse_read<R: Read>(&self, read: R) -> FromReadTriGReader<R> {
FromReadTriGReader { FromReadTriGReader {
inner: self.parse().parser.parse_from_read(read), inner: self.parse().parser.parse_read(read),
} }
} }
@ -129,7 +129,7 @@ impl TriGParser {
/// ///
/// let schema_person = NamedNodeRef::new_unchecked("http://schema.org/Person"); /// let schema_person = NamedNodeRef::new_unchecked("http://schema.org/Person");
/// let mut count = 0; /// let mut count = 0;
/// let mut parser = TriGParser::new().parse_from_tokio_async_read(file.as_ref()); /// let mut parser = TriGParser::new().parse_tokio_async_read(file.as_ref());
/// while let Some(triple) = parser.next().await { /// while let Some(triple) = parser.next().await {
/// let triple = triple?; /// let triple = triple?;
/// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() { /// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() {
@ -141,12 +141,12 @@ impl TriGParser {
/// } /// }
/// ``` /// ```
#[cfg(feature = "async-tokio")] #[cfg(feature = "async-tokio")]
pub fn parse_from_tokio_async_read<R: AsyncRead + Unpin>( pub fn parse_tokio_async_read<R: AsyncRead + Unpin>(
&self, &self,
read: R, read: R,
) -> FromTokioAsyncReadTriGReader<R> { ) -> FromTokioAsyncReadTriGReader<R> {
FromTokioAsyncReadTriGReader { FromTokioAsyncReadTriGReader {
inner: self.parse().parser.parse_from_tokio_async_read(read), inner: self.parse().parser.parse_tokio_async_read(read),
} }
} }
@ -199,7 +199,7 @@ impl TriGParser {
} }
} }
/// Parses a TriG file from a [`Read`] implementation. Can be built using [`TriGParser::parse_from_read`]. /// Parses a TriG file from a [`Read`] implementation. Can be built using [`TriGParser::parse_read`].
/// ///
/// Count the number of people: /// Count the number of people:
/// ``` /// ```
@ -215,7 +215,7 @@ impl TriGParser {
/// ///
/// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?;
/// let mut count = 0; /// let mut count = 0;
/// for quad in TriGParser::new().parse_from_read(file.as_ref()) { /// for quad in TriGParser::new().parse_read(file.as_ref()) {
/// let quad = quad?; /// let quad = quad?;
/// if quad.predicate == rdf::TYPE && quad.object == schema_person.into() { /// if quad.predicate == rdf::TYPE && quad.object == schema_person.into() {
/// count += 1; /// count += 1;
@ -236,7 +236,7 @@ impl<R: Read> Iterator for FromReadTriGReader<R> {
} }
} }
/// Parses a TriG file from a [`AsyncRead`] implementation. Can be built using [`TriGParser::parse_from_tokio_async_read`]. /// Parses a TriG file from a [`AsyncRead`] implementation. Can be built using [`TriGParser::parse_tokio_async_read`].
/// ///
/// Count the number of people: /// Count the number of people:
/// ``` /// ```
@ -254,7 +254,7 @@ impl<R: Read> Iterator for FromReadTriGReader<R> {
/// ///
/// let schema_person = NamedNodeRef::new_unchecked("http://schema.org/Person"); /// let schema_person = NamedNodeRef::new_unchecked("http://schema.org/Person");
/// let mut count = 0; /// let mut count = 0;
/// let mut parser = TriGParser::new().parse_from_tokio_async_read(file.as_ref()); /// let mut parser = TriGParser::new().parse_tokio_async_read(file.as_ref());
/// while let Some(triple) = parser.next().await { /// while let Some(triple) = parser.next().await {
/// let triple = triple?; /// let triple = triple?;
/// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() { /// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() {

@ -32,7 +32,7 @@ use tokio::io::{AsyncRead, AsyncWrite};
/// ///
/// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?;
/// let mut count = 0; /// let mut count = 0;
/// for triple in TurtleParser::new().parse_from_read(file.as_ref()) { /// for triple in TurtleParser::new().parse_read(file.as_ref()) {
/// let triple = triple?; /// let triple = triple?;
/// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() { /// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() {
/// count += 1; /// count += 1;
@ -98,7 +98,7 @@ impl TurtleParser {
/// ///
/// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?;
/// let mut count = 0; /// let mut count = 0;
/// for triple in TurtleParser::new().parse_from_read(file.as_ref()) { /// for triple in TurtleParser::new().parse_read(file.as_ref()) {
/// let triple = triple?; /// let triple = triple?;
/// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() { /// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() {
/// count += 1; /// count += 1;
@ -107,9 +107,9 @@ impl TurtleParser {
/// assert_eq!(2, count); /// assert_eq!(2, count);
/// # Result::<_,Box<dyn std::error::Error>>::Ok(()) /// # Result::<_,Box<dyn std::error::Error>>::Ok(())
/// ``` /// ```
pub fn parse_from_read<R: Read>(&self, read: R) -> FromReadTurtleReader<R> { pub fn parse_read<R: Read>(&self, read: R) -> FromReadTurtleReader<R> {
FromReadTurtleReader { FromReadTurtleReader {
inner: self.parse().parser.parse_from_read(read), inner: self.parse().parser.parse_read(read),
} }
} }
@ -131,7 +131,7 @@ impl TurtleParser {
/// ///
/// let schema_person = NamedNodeRef::new_unchecked("http://schema.org/Person"); /// let schema_person = NamedNodeRef::new_unchecked("http://schema.org/Person");
/// let mut count = 0; /// let mut count = 0;
/// let mut parser = TurtleParser::new().parse_from_tokio_async_read(file.as_ref()); /// let mut parser = TurtleParser::new().parse_tokio_async_read(file.as_ref());
/// while let Some(triple) = parser.next().await { /// while let Some(triple) = parser.next().await {
/// let triple = triple?; /// let triple = triple?;
/// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() { /// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() {
@ -143,12 +143,12 @@ impl TurtleParser {
/// } /// }
/// ``` /// ```
#[cfg(feature = "async-tokio")] #[cfg(feature = "async-tokio")]
pub fn parse_from_tokio_async_read<R: AsyncRead + Unpin>( pub fn parse_tokio_async_read<R: AsyncRead + Unpin>(
&self, &self,
read: R, read: R,
) -> FromTokioAsyncReadTurtleReader<R> { ) -> FromTokioAsyncReadTurtleReader<R> {
FromTokioAsyncReadTurtleReader { FromTokioAsyncReadTurtleReader {
inner: self.parse().parser.parse_from_tokio_async_read(read), inner: self.parse().parser.parse_tokio_async_read(read),
} }
} }
@ -201,7 +201,7 @@ impl TurtleParser {
} }
} }
/// Parses a Turtle file from a [`Read`] implementation. Can be built using [`TurtleParser::parse_from_read`]. /// Parses a Turtle file from a [`Read`] implementation. Can be built using [`TurtleParser::parse_read`].
/// ///
/// Count the number of people: /// Count the number of people:
/// ``` /// ```
@ -217,7 +217,7 @@ impl TurtleParser {
/// ///
/// let schema_person = NamedNodeRef::new("http://schema.org/Person")?; /// let schema_person = NamedNodeRef::new("http://schema.org/Person")?;
/// let mut count = 0; /// let mut count = 0;
/// for triple in TurtleParser::new().parse_from_read(file.as_ref()) { /// for triple in TurtleParser::new().parse_read(file.as_ref()) {
/// let triple = triple?; /// let triple = triple?;
/// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() { /// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() {
/// count += 1; /// count += 1;
@ -238,7 +238,7 @@ impl<R: Read> Iterator for FromReadTurtleReader<R> {
} }
} }
/// Parses a Turtle file from a [`AsyncRead`] implementation. Can be built using [`TurtleParser::parse_from_tokio_async_read`]. /// Parses a Turtle file from a [`AsyncRead`] implementation. Can be built using [`TurtleParser::parse_tokio_async_read`].
/// ///
/// Count the number of people: /// Count the number of people:
/// ``` /// ```
@ -256,7 +256,7 @@ impl<R: Read> Iterator for FromReadTurtleReader<R> {
/// ///
/// let schema_person = NamedNodeRef::new_unchecked("http://schema.org/Person"); /// let schema_person = NamedNodeRef::new_unchecked("http://schema.org/Person");
/// let mut count = 0; /// let mut count = 0;
/// let mut parser = TurtleParser::new().parse_from_tokio_async_read(file.as_ref()); /// let mut parser = TurtleParser::new().parse_tokio_async_read(file.as_ref());
/// while let Some(triple) = parser.next().await { /// while let Some(triple) = parser.next().await {
/// let triple = triple?; /// let triple = triple?;
/// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() { /// if triple.predicate == rdf::TYPE && triple.object == schema_person.into() {

@ -88,11 +88,9 @@ impl GraphParser {
TripleReader { TripleReader {
mapper: BlankNodeMapper::default(), mapper: BlankNodeMapper::default(),
parser: match &self.inner { parser: match &self.inner {
GraphParserKind::NTriples(p) => { GraphParserKind::NTriples(p) => TripleReaderKind::NTriples(p.parse_read(reader)),
TripleReaderKind::NTriples(p.parse_from_read(reader)) GraphParserKind::Turtle(p) => TripleReaderKind::Turtle(p.parse_read(reader)),
} GraphParserKind::RdfXml(p) => TripleReaderKind::RdfXml(p.parse_read(reader)),
GraphParserKind::Turtle(p) => TripleReaderKind::Turtle(p.parse_from_read(reader)),
GraphParserKind::RdfXml(p) => TripleReaderKind::RdfXml(p.parse_from_read(reader)),
}, },
} }
} }
@ -219,8 +217,8 @@ impl DatasetParser {
QuadReader { QuadReader {
mapper: BlankNodeMapper::default(), mapper: BlankNodeMapper::default(),
parser: match &self.inner { parser: match &self.inner {
DatasetParserKind::NQuads(p) => QuadReaderKind::NQuads(p.parse_from_read(reader)), DatasetParserKind::NQuads(p) => QuadReaderKind::NQuads(p.parse_read(reader)),
DatasetParserKind::TriG(p) => QuadReaderKind::TriG(p.parse_from_read(reader)), DatasetParserKind::TriG(p) => QuadReaderKind::TriG(p.parse_read(reader)),
}, },
} }
} }

@ -107,7 +107,7 @@ pub fn load_n3(url: &str, ignore_errors: bool) -> Result<Vec<N3Quad>> {
for q in N3Parser::new() for q in N3Parser::new()
.with_base_iri(url)? .with_base_iri(url)?
.with_prefix("", format!("{url}#"))? .with_prefix("", format!("{url}#"))?
.parse_from_read(read_file(url)?) .parse_read(read_file(url)?)
{ {
match q { match q {
Ok(q) => quads.push(q), Ok(q) => quads.push(q),

Loading…
Cancel
Save