Moves SPARQL evaluation out of store module

Keeps everything related to SPARQL in one place
pull/10/head
Tpt 6 years ago
parent 5966c62cc8
commit 002afb53b4
  1. 4
      src/model/dataset.rs
  2. 0
      src/sparql/eval.rs
  3. 21
      src/sparql/mod.rs
  4. 5
      src/store/mod.rs
  5. 13
      src/store/store.rs
  6. 1
      tests/sparql_test_cases.rs

@ -1,6 +1,4 @@
use model::*;
use sparql::algebra::QueryResult;
use std::io::Read;
use Result;
/// Trait for [RDF graphs](https://www.w3.org/TR/rdf11-concepts/#dfn-graph)
@ -210,6 +208,4 @@ pub trait Dataset {
/// Checks if this dataset contains a quad
fn is_empty(&self) -> Result<bool>;
fn query(&self, query: impl Read) -> Result<QueryResult>;
}

@ -1,6 +1,27 @@
//! SPARQL 1.1 implementation.
//! This is a work in progress!!!
use model::Dataset;
use sparql::algebra::QueryResult;
use sparql::eval::SparqlEvaluator;
use sparql::parser::read_sparql_query;
use std::io::Read;
use store::store::EncodedQuadsStore;
use store::store::StoreDataset;
use Result;
pub mod algebra;
mod eval;
pub mod parser;
pub mod xml_results;
pub trait SparqlDataset: Dataset {
fn query(&self, query: impl Read) -> Result<QueryResult>;
}
impl<S: EncodedQuadsStore> SparqlDataset for StoreDataset<S> {
fn query(&self, query: impl Read) -> Result<QueryResult> {
let query = read_sparql_query(query, None)?;
SparqlEvaluator::new(self.encoded()).evaluate(&query)
}
}

@ -2,10 +2,9 @@
pub mod isomorphism;
mod memory;
mod numeric_encoder;
pub(crate) mod numeric_encoder;
mod rocksdb;
mod sparql;
mod store;
pub(crate) mod store;
pub use store::memory::MemoryDataset;
pub use store::memory::MemoryGraph;

@ -1,15 +1,11 @@
use model::*;
use sparql::algebra::QueryResult;
use sparql::parser::read_sparql_query;
use std::fmt;
use std::io::Read;
use std::iter::empty;
use std::iter::once;
use std::iter::FromIterator;
use std::iter::Iterator;
use std::sync::Arc;
use store::numeric_encoder::*;
use store::sparql::SparqlEvaluator;
use Result;
/// Defines the Store traits that is used to have efficient binary storage
@ -187,6 +183,10 @@ impl<S: EncodedQuadsStore> StoreDataset<S> {
store: Arc::new(store),
}
}
pub(crate) fn encoded(&self) -> Arc<S> {
self.store.clone()
}
}
impl<S: EncodedQuadsStore> Dataset for StoreDataset<S> {
@ -349,11 +349,6 @@ impl<S: EncodedQuadsStore> Dataset for StoreDataset<S> {
fn is_empty(&self) -> Result<bool> {
Ok(self.store.quads()?.any(|_| true))
}
fn query(&self, query: impl Read) -> Result<QueryResult> {
let query = read_sparql_query(query, None)?;
SparqlEvaluator::new(self.store.clone()).evaluate(&query)
}
}
impl<S: EncodedQuadsStore> fmt::Display for StoreDataset<S> {

@ -16,6 +16,7 @@ use rudf::sparql::algebra::Query;
use rudf::sparql::algebra::QueryResult;
use rudf::sparql::parser::read_sparql_query;
use rudf::sparql::xml_results::read_xml_results;
use rudf::sparql::SparqlDataset;
use rudf::store::isomorphism::GraphIsomorphism;
use rudf::store::MemoryDataset;
use rudf::store::MemoryGraph;

Loading…
Cancel
Save