parent
f78121f9d3
commit
4ad8aa6fcf
@ -1,12 +1,47 @@ |
|||||||
//! Wrapper for RIO parsers
|
//! Implementations of serializers and deserializers for usual RDF syntaxes
|
||||||
|
|
||||||
use crate::model::*; |
use crate::model::*; |
||||||
use crate::Result; |
use crate::Result; |
||||||
use rio_api::model as rio; |
use rio_api::model as rio; |
||||||
|
use rio_api::parser::TripleParser; |
||||||
|
use rio_turtle::{NTriplesParser, TurtleParser}; |
||||||
|
use rio_xml::RdfXmlParser; |
||||||
use std::collections::BTreeMap; |
use std::collections::BTreeMap; |
||||||
|
use std::io::BufRead; |
||||||
use std::str::FromStr; |
use std::str::FromStr; |
||||||
|
use url::Url; |
||||||
|
|
||||||
pub fn convert_triple( |
/// Reads a [N-Triples](https://www.w3.org/TR/n-triples/) file from a Rust `BufRead` and returns an iterator of the read `Triple`s
|
||||||
|
pub fn read_ntriples<R: BufRead>(reader: R) -> Result<impl Iterator<Item = Result<Triple>>> { |
||||||
|
let mut bnode_map = BTreeMap::default(); |
||||||
|
Ok(NTriplesParser::new(reader)?.into_iter(move |t| convert_triple(t, &mut bnode_map))) |
||||||
|
} |
||||||
|
|
||||||
|
/// Reads a [Turtle](https://www.w3.org/TR/turtle/) file from a Rust `BufRead` and returns an iterator of the read `Triple`s
|
||||||
|
pub fn read_turtle<R: BufRead>( |
||||||
|
reader: R, |
||||||
|
base_url: Option<Url>, |
||||||
|
) -> Result<impl Iterator<Item = Result<Triple>>> { |
||||||
|
let mut bnode_map = BTreeMap::default(); |
||||||
|
Ok( |
||||||
|
TurtleParser::new(reader, base_url.as_ref().map_or("", |url| url.as_str()))? |
||||||
|
.into_iter(move |t| convert_triple(t, &mut bnode_map)), |
||||||
|
) |
||||||
|
} |
||||||
|
|
||||||
|
/// Reads a [RDF XML](https://www.w3.org/TR/rdf-syntax-grammar/) file from a Rust `BufRead` and returns an iterator of the read `Triple`s
|
||||||
|
pub fn read_rdf_xml<R: BufRead>( |
||||||
|
reader: R, |
||||||
|
base_url: Option<Url>, |
||||||
|
) -> Result<impl Iterator<Item = Result<Triple>>> { |
||||||
|
let mut bnode_map = BTreeMap::default(); |
||||||
|
Ok( |
||||||
|
RdfXmlParser::new(reader, base_url.as_ref().map_or("", |url| url.as_str()))? |
||||||
|
.into_iter(move |t| convert_triple(t, &mut bnode_map)), |
||||||
|
) |
||||||
|
} |
||||||
|
|
||||||
|
fn convert_triple( |
||||||
value: rio::Triple, |
value: rio::Triple, |
||||||
bnodes_map: &mut BTreeMap<String, BlankNode>, |
bnodes_map: &mut BTreeMap<String, BlankNode>, |
||||||
) -> Result<Triple> { |
) -> Result<Triple> { |
@ -1,6 +0,0 @@ |
|||||||
//! Implementations of serializers and deserializers for usual RDF syntaxes
|
|
||||||
|
|
||||||
pub mod ntriples; |
|
||||||
mod rio; |
|
||||||
pub mod turtle; |
|
||||||
pub mod xml; |
|
@ -1,15 +0,0 @@ |
|||||||
//! Implementation of [N-Triples](https://www.w3.org/TR/n-triples/) RDF syntax
|
|
||||||
|
|
||||||
use crate::model::Triple; |
|
||||||
use crate::rio::rio::convert_triple; |
|
||||||
use crate::Result; |
|
||||||
use rio_api::parser::TripleParser; |
|
||||||
use rio_turtle::NTriplesParser; |
|
||||||
use std::collections::BTreeMap; |
|
||||||
use std::io::BufRead; |
|
||||||
|
|
||||||
/// Reads a [N-Triples](https://www.w3.org/TR/n-triples/) file from a Rust `BufRead` and returns an iterator of the read `Triple`s
|
|
||||||
pub fn read_ntriples<R: BufRead>(reader: R) -> Result<impl Iterator<Item = Result<Triple>>> { |
|
||||||
let mut bnode_map = BTreeMap::default(); |
|
||||||
Ok(NTriplesParser::new(reader)?.into_iter(move |t| convert_triple(t, &mut bnode_map))) |
|
||||||
} |
|
@ -1,22 +0,0 @@ |
|||||||
//! Implementation of [Turtle](https://www.w3.org/TR/turtle/) RDF syntax
|
|
||||||
|
|
||||||
use crate::model::Triple; |
|
||||||
use crate::rio::rio::convert_triple; |
|
||||||
use crate::Result; |
|
||||||
use rio_api::parser::TripleParser; |
|
||||||
use rio_turtle::TurtleParser; |
|
||||||
use std::collections::BTreeMap; |
|
||||||
use std::io::BufRead; |
|
||||||
use url::Url; |
|
||||||
|
|
||||||
/// Reads a [Turtle](https://www.w3.org/TR/turtle/) file from a Rust `BufRead` and returns an iterator of the read `Triple`s
|
|
||||||
pub fn read_turtle<R: BufRead>( |
|
||||||
reader: R, |
|
||||||
base_url: Option<Url>, |
|
||||||
) -> Result<impl Iterator<Item = Result<Triple>>> { |
|
||||||
let mut bnode_map = BTreeMap::default(); |
|
||||||
Ok( |
|
||||||
TurtleParser::new(reader, base_url.as_ref().map_or("", |url| url.as_str()))? |
|
||||||
.into_iter(move |t| convert_triple(t, &mut bnode_map)), |
|
||||||
) |
|
||||||
} |
|
@ -1,22 +0,0 @@ |
|||||||
//! Implementation of [RDF XML](https://www.w3.org/TR/rdf-syntax-grammar/) syntax
|
|
||||||
|
|
||||||
use crate::model::Triple; |
|
||||||
use crate::rio::rio::convert_triple; |
|
||||||
use crate::Result; |
|
||||||
use rio_api::parser::TripleParser; |
|
||||||
use rio_xml::RdfXmlParser; |
|
||||||
use std::collections::BTreeMap; |
|
||||||
use std::io::BufRead; |
|
||||||
use url::Url; |
|
||||||
|
|
||||||
/// Reads a [RDF XML](https://www.w3.org/TR/rdf-syntax-grammar/) file from a Rust `BufRead` and returns an iterator of the read `Triple`s
|
|
||||||
pub fn read_rdf_xml<R: BufRead>( |
|
||||||
reader: R, |
|
||||||
base_url: Option<Url>, |
|
||||||
) -> Result<impl Iterator<Item = Result<Triple>>> { |
|
||||||
let mut bnode_map = BTreeMap::default(); |
|
||||||
Ok( |
|
||||||
RdfXmlParser::new(reader, base_url.as_ref().map_or("", |url| url.as_str()))? |
|
||||||
.into_iter(move |t| convert_triple(t, &mut bnode_map)), |
|
||||||
) |
|
||||||
} |
|
Loading…
Reference in new issue