From 44c216c348aa108866f65ab3897cf25d1bb07df1 Mon Sep 17 00:00:00 2001 From: Tpt Date: Fri, 14 Aug 2020 11:50:54 +0200 Subject: [PATCH] Moves sophia implementations into model and store packages --- lib/src/lib.rs | 12 ++----- lib/src/model/mod.rs | 2 ++ lib/src/{sophia/model.rs => model/sophia.rs} | 6 ++-- lib/src/store/mod.rs | 2 ++ lib/src/{sophia/store.rs => store/sophia.rs} | 33 +++++++++----------- 5 files changed, 24 insertions(+), 31 deletions(-) rename lib/src/{sophia/model.rs => model/sophia.rs} (98%) rename lib/src/{sophia/store.rs => store/sophia.rs} (97%) diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 33835e50..82ab424f 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -14,6 +14,8 @@ //! //! Oxigraph also provides a set of utility functions for reading, writing and processing RDF files. //! +//! The disabled by default `"sophia"` feature provides [`sophia_api`](https://docs.rs/sophia_api/) traits implemention on Oxigraph terms and stores. +//! //! Usage example with the [`MemoryStore`](store/memory/struct.MemoryStore.html): //! //! ``` @@ -118,13 +120,3 @@ pub use crate::store::memory::MemoryStore; pub use crate::store::rocksdb::RocksDbStore; #[cfg(feature = "sled")] pub use crate::store::sled::SledStore; - -#[cfg(feature = "sophia")] -/// Provides implementation of [Sophia] traits for Oxigraph types, -/// if the `sophia` feature is enabled. -/// -/// [Sophia]: https://docs.rs/sophia/latest/sophia/ -mod sophia { - mod model; - mod store; -} diff --git a/lib/src/model/mod.rs b/lib/src/model/mod.rs index f9bd3b1c..b3ec5e95 100644 --- a/lib/src/model/mod.rs +++ b/lib/src/model/mod.rs @@ -5,6 +5,8 @@ mod blank_node; mod literal; mod named_node; +#[cfg(feature = "sophia")] +mod sophia; mod triple; pub mod vocab; pub(crate) mod xsd; diff --git a/lib/src/sophia/model.rs b/lib/src/model/sophia.rs similarity index 98% rename from lib/src/sophia/model.rs rename to lib/src/model/sophia.rs index 69bfdf5c..6ca458b1 100644 --- a/lib/src/sophia/model.rs +++ b/lib/src/model/sophia.rs @@ -393,16 +393,16 @@ impl<'a> From> for [TermRef<'a>; 3] { } } -/// Error raised when trying to conpy a [Sophia] +/// Error raised when trying to copy a [Sophia](https://docs.rs/sophia/) /// term as an incompatible Oxigraph term /// (e.g. a literal into `NamedNode`). -/// -/// [Sophia]: https://docs.rs/sophia/latest/sophia/ #[derive(Clone, Copy, Debug)] pub struct SophiaToOxigraphConversionError; + impl fmt::Display for SophiaToOxigraphConversionError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{:?}", self) } } + impl std::error::Error for SophiaToOxigraphConversionError {} diff --git a/lib/src/store/mod.rs b/lib/src/store/mod.rs index d80bcfe9..71cea670 100644 --- a/lib/src/store/mod.rs +++ b/lib/src/store/mod.rs @@ -9,6 +9,8 @@ pub mod rocksdb; #[cfg(feature = "sled")] pub mod sled; pub(crate) mod small_string; +#[cfg(feature = "sophia")] +mod sophia; pub use crate::store::memory::MemoryStore; #[cfg(feature = "rocksdb")] diff --git a/lib/src/sophia/store.rs b/lib/src/store/sophia.rs similarity index 97% rename from lib/src/sophia/store.rs rename to lib/src/store/sophia.rs index e23e86f4..3d99b1e5 100644 --- a/lib/src/sophia/store.rs +++ b/lib/src/store/sophia.rs @@ -22,23 +22,20 @@ type StreamedSophiaQuad<'a> = StreamedQuad<'a, ByValue>; /// + the query must be a SELECT query with a single selected variable /// + it must not produce NULL results macro_rules! sparql_to_hashset { - ($store: ident, $err_map: ident, $sparql: expr) => { - //sparql_result_as_term_set($store, $sparql).map_err($err_map) - { - (|| -> Result, EvaluationError> { - let q = $store.prepare_query($sparql, QueryOptions::default())?; - let r = q.exec()?; - if let QueryResults::Solutions(solutions) = r { - solutions - .map(|r| r.map(|v| v.get(0).unwrap().clone())) - .collect() - } else { - unreachable!() - } - })() - .map_err($err_map) - } - }; + ($store: ident, $err_map: ident, $sparql: expr) => {{ + (|| -> Result, EvaluationError> { + if let QueryResults::Solutions(solutions) = + $store.query($sparql, QueryOptions::default())? + { + solutions + .map(|r| r.map(|v| v.get(0).unwrap().clone())) + .collect() + } else { + unreachable!() + } + })() + .map_err($err_map) + }}; } macro_rules! impl_dataset { @@ -418,7 +415,7 @@ macro_rules! impl_dataset { }; } -mod mem { +mod memory { use super::*; impl_dataset!(