Simplifies rio package architecture

pull/10/head
Tpt 5 years ago
parent f78121f9d3
commit 4ad8aa6fcf
  1. 39
      lib/src/rio.rs
  2. 6
      lib/src/rio/mod.rs
  3. 15
      lib/src/rio/ntriples.rs
  4. 22
      lib/src/rio/turtle.rs
  5. 22
      lib/src/rio/xml.rs
  6. 6
      lib/tests/rdf_test_cases.rs
  7. 4
      lib/tests/sparql_test_cases.rs
  8. 2
      server/src/main.rs

@ -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)),
)
}

@ -3,9 +3,9 @@ use failure::format_err;
use rudf::model::vocab::rdf; use rudf::model::vocab::rdf;
use rudf::model::vocab::rdfs; use rudf::model::vocab::rdfs;
use rudf::model::*; use rudf::model::*;
use rudf::rio::ntriples::read_ntriples; use rudf::rio::read_ntriples;
use rudf::rio::turtle::read_turtle; use rudf::rio::read_rdf_xml;
use rudf::rio::xml::read_rdf_xml; use rudf::rio::read_turtle;
use rudf::Result; use rudf::Result;
use std::fmt; use std::fmt;
use std::fs::File; use std::fs::File;

@ -3,8 +3,8 @@ use failure::format_err;
use rudf::model::vocab::rdf; use rudf::model::vocab::rdf;
use rudf::model::vocab::rdfs; use rudf::model::vocab::rdfs;
use rudf::model::*; use rudf::model::*;
use rudf::rio::turtle::read_turtle; use rudf::rio::read_rdf_xml;
use rudf::rio::xml::read_rdf_xml; use rudf::rio::read_turtle;
use rudf::sparql::algebra::Query; use rudf::sparql::algebra::Query;
use rudf::sparql::algebra::QueryResult; use rudf::sparql::algebra::QueryResult;
use rudf::sparql::parser::read_sparql_query; use rudf::sparql::parser::read_sparql_query;

@ -28,7 +28,7 @@ use lazy_static::lazy_static;
use mime; use mime;
use mime::Mime; use mime::Mime;
use rudf::model::Graph; use rudf::model::Graph;
use rudf::rio::ntriples::read_ntriples; use rudf::rio::read_ntriples;
use rudf::sparql::algebra::QueryResult; use rudf::sparql::algebra::QueryResult;
use rudf::sparql::xml_results::write_xml_results; use rudf::sparql::xml_results::write_xml_results;
use rudf::sparql::PreparedQuery; use rudf::sparql::PreparedQuery;

Loading…
Cancel
Save