diff --git a/lib/src/rio/rio.rs b/lib/src/rio.rs similarity index 55% rename from lib/src/rio/rio.rs rename to lib/src/rio.rs index 15bbbb79..ac905074 100644 --- a/lib/src/rio/rio.rs +++ b/lib/src/rio.rs @@ -1,12 +1,47 @@ -//! Wrapper for RIO parsers +//! Implementations of serializers and deserializers for usual RDF syntaxes use crate::model::*; use crate::Result; 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::io::BufRead; 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(reader: R) -> Result>> { + 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( + reader: R, + base_url: Option, +) -> Result>> { + 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( + reader: R, + base_url: Option, +) -> Result>> { + 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, bnodes_map: &mut BTreeMap, ) -> Result { diff --git a/lib/src/rio/mod.rs b/lib/src/rio/mod.rs deleted file mode 100644 index 685a3f3b..00000000 --- a/lib/src/rio/mod.rs +++ /dev/null @@ -1,6 +0,0 @@ -//! Implementations of serializers and deserializers for usual RDF syntaxes - -pub mod ntriples; -mod rio; -pub mod turtle; -pub mod xml; diff --git a/lib/src/rio/ntriples.rs b/lib/src/rio/ntriples.rs deleted file mode 100644 index 7c8ece60..00000000 --- a/lib/src/rio/ntriples.rs +++ /dev/null @@ -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(reader: R) -> Result>> { - let mut bnode_map = BTreeMap::default(); - Ok(NTriplesParser::new(reader)?.into_iter(move |t| convert_triple(t, &mut bnode_map))) -} diff --git a/lib/src/rio/turtle.rs b/lib/src/rio/turtle.rs deleted file mode 100644 index aecec384..00000000 --- a/lib/src/rio/turtle.rs +++ /dev/null @@ -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( - reader: R, - base_url: Option, -) -> Result>> { - 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)), - ) -} diff --git a/lib/src/rio/xml.rs b/lib/src/rio/xml.rs deleted file mode 100644 index 6f145f7f..00000000 --- a/lib/src/rio/xml.rs +++ /dev/null @@ -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( - reader: R, - base_url: Option, -) -> Result>> { - 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)), - ) -} diff --git a/lib/tests/rdf_test_cases.rs b/lib/tests/rdf_test_cases.rs index 91ada529..7aa0debc 100644 --- a/lib/tests/rdf_test_cases.rs +++ b/lib/tests/rdf_test_cases.rs @@ -3,9 +3,9 @@ use failure::format_err; use rudf::model::vocab::rdf; use rudf::model::vocab::rdfs; use rudf::model::*; -use rudf::rio::ntriples::read_ntriples; -use rudf::rio::turtle::read_turtle; -use rudf::rio::xml::read_rdf_xml; +use rudf::rio::read_ntriples; +use rudf::rio::read_rdf_xml; +use rudf::rio::read_turtle; use rudf::Result; use std::fmt; use std::fs::File; diff --git a/lib/tests/sparql_test_cases.rs b/lib/tests/sparql_test_cases.rs index 9fed87ca..455d1d30 100644 --- a/lib/tests/sparql_test_cases.rs +++ b/lib/tests/sparql_test_cases.rs @@ -3,8 +3,8 @@ use failure::format_err; use rudf::model::vocab::rdf; use rudf::model::vocab::rdfs; use rudf::model::*; -use rudf::rio::turtle::read_turtle; -use rudf::rio::xml::read_rdf_xml; +use rudf::rio::read_rdf_xml; +use rudf::rio::read_turtle; use rudf::sparql::algebra::Query; use rudf::sparql::algebra::QueryResult; use rudf::sparql::parser::read_sparql_query; diff --git a/server/src/main.rs b/server/src/main.rs index a3d6cf75..bd00293e 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -28,7 +28,7 @@ use lazy_static::lazy_static; use mime; use mime::Mime; use rudf::model::Graph; -use rudf::rio::ntriples::read_ntriples; +use rudf::rio::read_ntriples; use rudf::sparql::algebra::QueryResult; use rudf::sparql::xml_results::write_xml_results; use rudf::sparql::PreparedQuery;