Moves sophia implementations into model and store packages

pull/51/head
Tpt 4 years ago
parent 0e3d37cb25
commit 44c216c348
  1. 12
      lib/src/lib.rs
  2. 2
      lib/src/model/mod.rs
  3. 6
      lib/src/model/sophia.rs
  4. 2
      lib/src/store/mod.rs
  5. 15
      lib/src/store/sophia.rs

@ -14,6 +14,8 @@
//! //!
//! Oxigraph also provides a set of utility functions for reading, writing and processing RDF files. //! 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): //! 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; pub use crate::store::rocksdb::RocksDbStore;
#[cfg(feature = "sled")] #[cfg(feature = "sled")]
pub use crate::store::sled::SledStore; 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;
}

@ -5,6 +5,8 @@
mod blank_node; mod blank_node;
mod literal; mod literal;
mod named_node; mod named_node;
#[cfg(feature = "sophia")]
mod sophia;
mod triple; mod triple;
pub mod vocab; pub mod vocab;
pub(crate) mod xsd; pub(crate) mod xsd;

@ -393,16 +393,16 @@ impl<'a> From<TripleRef<'a>> 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 /// term as an incompatible Oxigraph term
/// (e.g. a literal into `NamedNode`). /// (e.g. a literal into `NamedNode`).
///
/// [Sophia]: https://docs.rs/sophia/latest/sophia/
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub struct SophiaToOxigraphConversionError; pub struct SophiaToOxigraphConversionError;
impl fmt::Display for SophiaToOxigraphConversionError { impl fmt::Display for SophiaToOxigraphConversionError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self) write!(f, "{:?}", self)
} }
} }
impl std::error::Error for SophiaToOxigraphConversionError {} impl std::error::Error for SophiaToOxigraphConversionError {}

@ -9,6 +9,8 @@ pub mod rocksdb;
#[cfg(feature = "sled")] #[cfg(feature = "sled")]
pub mod sled; pub mod sled;
pub(crate) mod small_string; pub(crate) mod small_string;
#[cfg(feature = "sophia")]
mod sophia;
pub use crate::store::memory::MemoryStore; pub use crate::store::memory::MemoryStore;
#[cfg(feature = "rocksdb")] #[cfg(feature = "rocksdb")]

@ -22,13 +22,11 @@ type StreamedSophiaQuad<'a> = StreamedQuad<'a, ByValue<SophiaQuad>>;
/// + the query must be a SELECT query with a single selected variable /// + the query must be a SELECT query with a single selected variable
/// + it must not produce NULL results /// + it must not produce NULL results
macro_rules! sparql_to_hashset { macro_rules! sparql_to_hashset {
($store: ident, $err_map: ident, $sparql: expr) => { ($store: ident, $err_map: ident, $sparql: expr) => {{
//sparql_result_as_term_set($store, $sparql).map_err($err_map)
{
(|| -> Result<HashSet<Term>, EvaluationError> { (|| -> Result<HashSet<Term>, EvaluationError> {
let q = $store.prepare_query($sparql, QueryOptions::default())?; if let QueryResults::Solutions(solutions) =
let r = q.exec()?; $store.query($sparql, QueryOptions::default())?
if let QueryResults::Solutions(solutions) = r { {
solutions solutions
.map(|r| r.map(|v| v.get(0).unwrap().clone())) .map(|r| r.map(|v| v.get(0).unwrap().clone()))
.collect() .collect()
@ -37,8 +35,7 @@ macro_rules! sparql_to_hashset {
} }
})() })()
.map_err($err_map) .map_err($err_map)
} }};
};
} }
macro_rules! impl_dataset { macro_rules! impl_dataset {
@ -418,7 +415,7 @@ macro_rules! impl_dataset {
}; };
} }
mod mem { mod memory {
use super::*; use super::*;
impl_dataset!( impl_dataset!(
Loading…
Cancel
Save