Improves documentation and public interfaces

pull/10/head
Tpt 6 years ago
parent d69d9c526e
commit 5cff79c372
  1. 5
      src/lib.rs
  2. 19
      src/model/blank_node.rs
  3. 2
      src/model/dataset.rs
  4. 108
      src/model/literal.rs
  5. 7
      src/model/mod.rs
  6. 31
      src/model/named_node.rs
  7. 131
      src/model/triple.rs
  8. 7
      src/model/vocab.rs
  9. 2
      src/rio/ntriples/mod.rs
  10. 4
      src/rio/xml.rs
  11. 6
      src/sparql/algebra.rs
  12. 3
      src/sparql/mod.rs
  13. 2
      src/sparql/xml_results.rs
  14. 2
      src/store/isomorphism.rs
  15. 2
      src/store/memory.rs
  16. 6
      src/store/numeric_encoder.rs
  17. 2
      src/store/rocksdb.rs
  18. 2
      src/store/sparql.rs
  19. 2
      src/store/store.rs
  20. 10
      tests/rdf_test_cases.rs
  21. 6
      tests/sparql_test_cases.rs

@ -8,9 +8,12 @@ extern crate rocksdb;
extern crate url;
extern crate uuid;
pub mod errors;
mod errors;
pub mod model;
pub mod rio;
pub mod sparql;
pub mod store;
mod utils;
pub use errors::Error;
pub use errors::Result;

@ -1,17 +1,24 @@
use std::fmt;
use std::ops::Deref;
use uuid::Uuid;
/// A RDF [blank node](https://www.w3.org/TR/rdf11-concepts/#dfn-blank-node)
/// A RDF [blank node](https://www.w3.org/TR/rdf11-concepts/#dfn-blank-node).
///
/// This implementation enforces that the blank node id is an UUID to easily ensure
/// that it is not possible for two blank nodes to share an id.
///
/// The common way to create a new blank node is to use the `Default::default` trait method.
///
/// The default string formatter is returning a N-Triples, Turtle and SPARQL compatible representation.
/// `BlankNode::default().to_string()` should return something like `_:00112233445566778899aabbccddeeff`
///
#[derive(Eq, PartialEq, Ord, PartialOrd, Debug, Clone, Hash)]
pub struct BlankNode {
id: Uuid,
}
impl Deref for BlankNode {
type Target = Uuid;
fn deref(&self) -> &Uuid {
impl BlankNode {
/// Returns the underlying UUID of this blank node
pub fn as_uuid(&self) -> &Uuid {
&self.id
}
}

@ -1,7 +1,7 @@
use errors::*;
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)
pub trait Graph {

@ -7,8 +7,32 @@ use std::option::Option;
use utils::Escaper;
/// A RDF [literal](https://www.w3.org/TR/rdf11-concepts/#dfn-literal)
///
/// The default string formatter is returning a N-Triples, Turtle and SPARQL compatible representation:
/// ```
/// use rudf::model::Literal;
/// use rudf::model::vocab::xsd;
///
/// assert_eq!(
/// "\"foo\\tbar\"",
/// Literal::new_simple_literal("foo\tbar").to_string()
/// );
///
/// assert_eq!(
/// "\"1999-01-01\"^^<http://www.w3.org/2001/XMLSchema#date>",
/// Literal::new_typed_literal("1999-01-01", xsd::DATE.clone()).to_string()
/// );
///
/// assert_eq!(
/// "\"foo\"@en",
/// Literal::new_language_tagged_literal("foo", "en").to_string()
/// );
/// ```
#[derive(Eq, PartialEq, Ord, PartialOrd, Debug, Clone, Hash)]
pub enum Literal {
pub struct Literal(LiteralContent);
#[derive(Eq, PartialEq, Ord, PartialOrd, Debug, Clone, Hash)]
enum LiteralContent {
SimpleLiteral(String),
String(String),
LanguageTaggedString { value: String, language: String },
@ -19,7 +43,7 @@ pub enum Literal {
impl Literal {
/// Builds a RDF [simple literal](https://www.w3.org/TR/rdf11-concepts/#dfn-simple-literal)
pub fn new_simple_literal(value: impl Into<String>) -> Self {
Literal::SimpleLiteral(value.into())
Literal(LiteralContent::SimpleLiteral(value.into()))
}
/// Builds a RDF [literal](https://www.w3.org/TR/rdf11-concepts/#dfn-literal) with a [datatype](https://www.w3.org/TR/rdf11-concepts/#dfn-datatype-iri)
@ -28,14 +52,14 @@ impl Literal {
let datatype = datatype.into();
if datatype == *xsd::BOOLEAN {
match value.as_str() {
"true" | "1" => Literal::Boolean(true),
"false" | "0" => Literal::Boolean(false),
_ => Literal::TypedLiteral { value, datatype },
"true" | "1" => Literal(LiteralContent::Boolean(true)),
"false" | "0" => Literal(LiteralContent::Boolean(false)),
_ => Literal(LiteralContent::TypedLiteral { value, datatype }),
}
} else if datatype == *xsd::STRING {
Literal::String(value)
Literal(LiteralContent::String(value))
} else {
Literal::TypedLiteral { value, datatype }
Literal(LiteralContent::TypedLiteral { value, datatype })
}
}
@ -44,48 +68,54 @@ impl Literal {
value: impl Into<String>,
language: impl Into<String>,
) -> Self {
Literal::LanguageTaggedString {
Literal(LiteralContent::LanguageTaggedString {
value: value.into(),
language: language.into(),
}
})
}
/// The literal [lexical form](https://www.w3.org/TR/rdf11-concepts/#dfn-lexical-form)
pub fn value(&self) -> Cow<String> {
match self {
Literal::SimpleLiteral(value) => Cow::Borrowed(value),
Literal::String(value) => Cow::Borrowed(value),
Literal::LanguageTaggedString { value, .. } => Cow::Borrowed(value),
Literal::Boolean(value) => Cow::Owned(value.to_string()),
Literal::TypedLiteral { value, .. } => Cow::Borrowed(value),
match self.0 {
LiteralContent::SimpleLiteral(ref value) => Cow::Borrowed(value),
LiteralContent::String(ref value) => Cow::Borrowed(value),
LiteralContent::LanguageTaggedString { ref value, .. } => Cow::Borrowed(value),
LiteralContent::Boolean(value) => Cow::Owned(value.to_string()),
LiteralContent::TypedLiteral { ref value, .. } => Cow::Borrowed(value),
}
}
/// The literal [language tag](https://www.w3.org/TR/rdf11-concepts/#dfn-language-tag) if it is a [language-tagged string](https://www.w3.org/TR/rdf11-concepts/#dfn-language-tagged-string)
/// The literal [language tag](https://www.w3.org/TR/rdf11-concepts/#dfn-language-tag) if it is a [language-tagged string](https://www.w3.org/TR/rdf11-concepts/#dfn-language-tagged-string).
/// Language tags are defined by the [BCP47](https://tools.ietf.org/html/bcp47).
pub fn language(&self) -> Option<&str> {
match self {
Literal::LanguageTaggedString { language, .. } => Some(language),
match self.0 {
LiteralContent::LanguageTaggedString { ref language, .. } => Some(language),
_ => None,
}
}
/// The literal [datatype](https://www.w3.org/TR/rdf11-concepts/#dfn-datatype-iri)
/// The datatype of [language-tagged string](https://www.w3.org/TR/rdf11-concepts/#dfn-language-tagged-string) is always http://www.w3.org/1999/02/22-rdf-syntax-ns#langString
/// The literal [datatype](https://www.w3.org/TR/rdf11-concepts/#dfn-datatype-iri).
///
/// The datatype of [language-tagged string](https://www.w3.org/TR/rdf11-concepts/#dfn-language-tagged-string) is always [rdf:langString](http://www.w3.org/1999/02/22-rdf-syntax-ns#langString).
/// The datatype of [simple literals](https://www.w3.org/TR/rdf11-concepts/#dfn-simple-literal) is [xsd:string](http://www.w3.org/2001/XMLSchema#string).
pub fn datatype(&self) -> &NamedNode {
match self {
Literal::SimpleLiteral(_) => &xsd::STRING,
Literal::String(_) => &xsd::STRING,
Literal::LanguageTaggedString { .. } => &rdf::LANG_STRING,
Literal::Boolean(_) => &xsd::BOOLEAN,
Literal::TypedLiteral { datatype, .. } => datatype,
match self.0 {
LiteralContent::SimpleLiteral(_) => &xsd::STRING,
LiteralContent::String(_) => &xsd::STRING,
LiteralContent::LanguageTaggedString { .. } => &rdf::LANG_STRING,
LiteralContent::Boolean(_) => &xsd::BOOLEAN,
LiteralContent::TypedLiteral { ref datatype, .. } => datatype,
}
}
/// Checks if it could be considered as an RDF 1.0 [plain literal](https://www.w3.org/TR/rdf-concepts/#dfn-plain-literal)
/// Checks if it could be considered as an RDF 1.0 [plain literal](https://www.w3.org/TR/rdf-concepts/#dfn-plain-literal).
///
/// It returns true if the literal is a [language-tagged string](https://www.w3.org/TR/rdf11-concepts/#dfn-language-tagged-string)
/// or have been created by `Literal::new_simple_literal`.
pub fn is_plain(&self) -> bool {
match self {
Literal::SimpleLiteral(_) => true,
Literal::LanguageTaggedString { .. } => true,
match self.0 {
LiteralContent::SimpleLiteral(_) => true,
LiteralContent::LanguageTaggedString { .. } => true,
_ => false,
}
}
@ -105,45 +135,45 @@ impl fmt::Display for Literal {
impl<'a> From<&'a str> for Literal {
fn from(value: &'a str) -> Self {
Literal::String(value.into())
Literal(LiteralContent::String(value.into()))
}
}
impl From<String> for Literal {
fn from(value: String) -> Self {
Literal::String(value)
Literal(LiteralContent::String(value))
}
}
impl From<bool> for Literal {
fn from(value: bool) -> Self {
Literal::Boolean(value)
Literal(LiteralContent::Boolean(value))
}
}
impl From<usize> for Literal {
fn from(value: usize) -> Self {
Literal::TypedLiteral {
Literal(LiteralContent::TypedLiteral {
value: value.to_string(),
datatype: xsd::INTEGER.clone(),
}
})
}
}
impl From<f32> for Literal {
fn from(value: f32) -> Self {
Literal::TypedLiteral {
Literal(LiteralContent::TypedLiteral {
value: value.to_string(),
datatype: xsd::FLOAT.clone(),
}
})
}
}
impl From<f64> for Literal {
fn from(value: f64) -> Self {
Literal::TypedLiteral {
Literal(LiteralContent::TypedLiteral {
value: value.to_string(),
datatype: xsd::DOUBLE.clone(),
}
})
}
}

@ -1,5 +1,6 @@
///! Implements data structures for https://www.w3.org/TR/rdf11-concepts/
///! Inspired by [RDFjs](http://rdf.js.org/)
//! Implements data structures for [RDF 1.1 Concepts](https://www.w3.org/TR/rdf11-concepts/)
//! Inspired by [RDFjs](http://rdf.js.org/) and [Apache Commons RDF](http://commons.apache.org/proper/commons-rdf/)
mod blank_node;
mod dataset;
mod literal;
@ -15,7 +16,5 @@ pub use model::literal::Literal;
pub use model::named_node::NamedNode;
pub use model::triple::NamedOrBlankNode;
pub use model::triple::Quad;
pub use model::triple::QuadLike;
pub use model::triple::Term;
pub use model::triple::Triple;
pub use model::triple::TripleLike;

@ -1,11 +1,26 @@
use errors::*;
use std::fmt;
use std::ops::Deref;
use std::str::FromStr;
use std::sync::Arc;
use url::Url;
use Error;
use Result;
/// A RDF [IRI](https://www.w3.org/TR/rdf11-concepts/#dfn-iri)
///
/// The common way to build it is to use the `FromStr::from_str` trait method.
/// This method takes care of usual IRI normalization and validation.
///
/// The default string formatter is returning a N-Triples, Turtle and SPARQL compatible representation:
/// ```
/// use rudf::model::NamedNode;
/// use std::str::FromStr;
///
/// assert_eq!(
/// "<http://example.com/foo>",
/// NamedNode::from_str("http://example.com/foo").unwrap().to_string()
/// )
/// ```
///
#[derive(Eq, PartialEq, Ord, PartialOrd, Debug, Clone, Hash)]
pub struct NamedNode {
iri: Arc<Url>,
@ -25,19 +40,11 @@ impl NamedNode {
}
}
pub fn value(&self) -> &str {
pub fn as_str(&self) -> &str {
self.iri.as_str()
}
pub fn url(&self) -> &Url {
&self.iri
}
}
impl Deref for NamedNode {
type Target = Url;
fn deref(&self) -> &Url {
pub fn as_url(&self) -> &Url {
&self.iri
}
}

@ -119,27 +119,6 @@ impl From<NamedOrBlankNode> for Term {
}
}
/// The interface of containers that looks like [RDF triples](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-triple)
pub trait TripleLike {
/// The [subject](https://www.w3.org/TR/rdf11-concepts/#dfn-subject) of this triple
fn subject(&self) -> &NamedOrBlankNode;
/// The [subject](https://www.w3.org/TR/rdf11-concepts/#dfn-subject) of this triple
fn subject_owned(self) -> NamedOrBlankNode;
/// The [predicate](https://www.w3.org/TR/rdf11-concepts/#dfn-predicate) of this triple
fn predicate(&self) -> &NamedNode;
/// The [predicate](https://www.w3.org/TR/rdf11-concepts/#dfn-predicate) of this triple
fn predicate_owned(self) -> NamedNode;
/// The [object](https://www.w3.org/TR/rdf11-concepts/#dfn-object) of this triple
fn object(&self) -> &Term;
/// The [object](https://www.w3.org/TR/rdf11-concepts/#dfn-object) of this triple
fn object_owned(self) -> Term;
}
/// A [RDF triple](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-triple)
#[derive(Eq, PartialEq, Ord, PartialOrd, Debug, Clone, Hash)]
pub struct Triple {
@ -162,55 +141,51 @@ impl Triple {
}
}
pub fn in_graph(self, graph_name: Option<NamedOrBlankNode>) -> Quad {
Quad {
subject: self.subject,
predicate: self.predicate,
object: self.object,
graph_name,
}
}
}
impl fmt::Display for Triple {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{} {} {} .", self.subject, self.predicate, self.object)
}
}
impl TripleLike for Triple {
fn subject(&self) -> &NamedOrBlankNode {
/// The [subject](https://www.w3.org/TR/rdf11-concepts/#dfn-subject) of this triple
pub fn subject(&self) -> &NamedOrBlankNode {
&self.subject
}
fn subject_owned(self) -> NamedOrBlankNode {
/// The [subject](https://www.w3.org/TR/rdf11-concepts/#dfn-subject) of this triple
pub fn subject_owned(self) -> NamedOrBlankNode {
self.subject
}
fn predicate(&self) -> &NamedNode {
/// The [predicate](https://www.w3.org/TR/rdf11-concepts/#dfn-predicate) of this triple
pub fn predicate(&self) -> &NamedNode {
&self.predicate
}
fn predicate_owned(self) -> NamedNode {
/// The [predicate](https://www.w3.org/TR/rdf11-concepts/#dfn-predicate) of this triple
pub fn predicate_owned(self) -> NamedNode {
self.predicate
}
fn object(&self) -> &Term {
/// The [object](https://www.w3.org/TR/rdf11-concepts/#dfn-object) of this triple
pub fn object(&self) -> &Term {
&self.object
}
fn object_owned(self) -> Term {
/// The [object](https://www.w3.org/TR/rdf11-concepts/#dfn-object) of this triple
pub fn object_owned(self) -> Term {
self.object
}
}
/// The interface of containers that looks like [triples](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-triple) that are in a [RDF dataset](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-dataset)
pub trait QuadLike: TripleLike {
/// The name of the RDF [graph](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-graph) in which the triple is or None if it is in the [default graph](https://www.w3.org/TR/rdf11-concepts/#dfn-default-graph)
fn graph_name(&self) -> &Option<NamedOrBlankNode>;
/// Encodes that this triple is in a [RDF dataset](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-dataset)
pub fn in_graph(self, graph_name: Option<NamedOrBlankNode>) -> Quad {
Quad {
subject: self.subject,
predicate: self.predicate,
object: self.object,
graph_name,
}
}
}
/// The name of the RDF [graph](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-graph) in which the triple is or None if it is in the [default graph](https://www.w3.org/TR/rdf11-concepts/#dfn-default-graph)
fn graph_name_owned(self) -> Option<NamedOrBlankNode>;
impl fmt::Display for Triple {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{} {} {} .", self.subject, self.predicate, self.object)
}
}
/// A [triple](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-triple) in a [RDF dataset](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-dataset)
@ -237,53 +212,57 @@ impl Quad {
graph_name: graph_name.into(),
}
}
}
impl fmt::Display for Quad {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self.graph_name {
Some(ref graph_name) => write!(
f,
"{} {} {} {} .",
self.subject, self.predicate, self.object, graph_name
),
None => write!(f, "{} {} {} .", self.subject, self.predicate, self.object),
}
}
}
impl TripleLike for Quad {
fn subject(&self) -> &NamedOrBlankNode {
/// The [subject](https://www.w3.org/TR/rdf11-concepts/#dfn-subject) of this triple
pub fn subject(&self) -> &NamedOrBlankNode {
&self.subject
}
fn subject_owned(self) -> NamedOrBlankNode {
/// The [subject](https://www.w3.org/TR/rdf11-concepts/#dfn-subject) of this triple
pub fn subject_owned(self) -> NamedOrBlankNode {
self.subject
}
fn predicate(&self) -> &NamedNode {
/// The [predicate](https://www.w3.org/TR/rdf11-concepts/#dfn-predicate) of this triple
pub fn predicate(&self) -> &NamedNode {
&self.predicate
}
fn predicate_owned(self) -> NamedNode {
/// The [predicate](https://www.w3.org/TR/rdf11-concepts/#dfn-predicate) of this triple
pub fn predicate_owned(self) -> NamedNode {
self.predicate
}
fn object(&self) -> &Term {
/// The [object](https://www.w3.org/TR/rdf11-concepts/#dfn-object) of this triple
pub fn object(&self) -> &Term {
&self.object
}
fn object_owned(self) -> Term {
/// The [object](https://www.w3.org/TR/rdf11-concepts/#dfn-object) of this triple
pub fn object_owned(self) -> Term {
self.object
}
}
impl QuadLike for Quad {
fn graph_name(&self) -> &Option<NamedOrBlankNode> {
/// The name of the RDF [graph](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-graph) in which the triple is or None if it is in the [default graph](https://www.w3.org/TR/rdf11-concepts/#dfn-default-graph)
pub fn graph_name(&self) -> &Option<NamedOrBlankNode> {
&self.graph_name
}
fn graph_name_owned(self) -> Option<NamedOrBlankNode> {
/// The name of the RDF [graph](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-graph) in which the triple is or None if it is in the [default graph](https://www.w3.org/TR/rdf11-concepts/#dfn-default-graph)
pub fn graph_name_owned(self) -> Option<NamedOrBlankNode> {
self.graph_name
}
}
impl fmt::Display for Quad {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self.graph_name {
Some(ref graph_name) => write!(
f,
"{} {} {} {} .",
self.subject, self.predicate, self.object, graph_name
),
None => write!(f, "{} {} {} .", self.subject, self.predicate, self.object),
}
}
}

@ -1,6 +1,7 @@
///! Provides ready to use NamedNode for basic RDF vocabularies
//! Provides ready to use `NamedNode`s for basic RDF vocabularies
pub mod rdf {
//! [RDF 1.1](https://www.w3.org/TR/rdf11-concepts/) vocabulary
use model::named_node::NamedNode;
use std::str::FromStr;
@ -31,6 +32,8 @@ pub mod rdf {
}
pub mod rdfs {
//! [RDFS](https://www.w3.org/TR/rdf-schema/) vocabulary
use model::named_node::NamedNode;
use std::str::FromStr;
@ -41,7 +44,7 @@ pub mod rdfs {
}
pub mod xsd {
///! NamedNodes for [RDF compatible XSD datatypes](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-compatible-xsd-types)
//! `NamedNode`s for [RDF compatible XSD datatypes](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-compatible-xsd-types)
use model::named_node::NamedNode;
use std::str::FromStr;

@ -32,12 +32,12 @@ mod grammar {
include!(concat!(env!("OUT_DIR"), "/ntriples_grammar.rs"));
}
use errors::*;
use model::*;
use std::collections::BTreeMap;
use std::io::BufRead;
use std::io::BufReader;
use std::io::Read;
use Result;
pub(crate) type ParseError = self::grammar::ParseError;

@ -1,4 +1,3 @@
use errors::*;
use model::vocab::rdf;
use model::Triple;
use model::*;
@ -11,6 +10,7 @@ use std::collections::BTreeMap;
use std::io::BufRead;
use std::str::FromStr;
use url::Url;
use Result;
pub fn read_rdf_xml(
source: impl BufRead,
@ -237,7 +237,7 @@ impl<R: BufRead> RdfXmlIterator<R> {
b"Resource" => RdfXmlParseType::Resource,
_ => RdfXmlParseType::Other,
};
} else if attribute_url == **rdf::TYPE {
} else if attribute_url == *rdf::TYPE.as_url() {
type_attr = Some(attribute.unescaped_value()?.to_vec());
} else {
property_attrs.push((

@ -1,4 +1,3 @@
use errors::*;
use model::*;
use std::collections::BTreeMap;
use std::collections::BTreeSet;
@ -7,6 +6,7 @@ use std::ops::Add;
use store::MemoryGraph;
use utils::Escaper;
use uuid::Uuid;
use Result;
#[derive(Eq, PartialEq, Ord, PartialOrd, Debug, Clone, Hash)]
pub enum Variable {
@ -53,7 +53,9 @@ impl Default for Variable {
impl From<BlankNode> for Variable {
fn from(blank_node: BlankNode) -> Self {
Variable::BlankNode { id: *blank_node }
Variable::BlankNode {
id: *blank_node.as_uuid(),
}
}
}

@ -1,3 +1,6 @@
//! SPARQL 1.1 implementation.
//! This is a work in progress!!!
pub mod algebra;
pub mod parser;
pub mod xml_results;

@ -1,4 +1,3 @@
use errors::*;
use model::*;
use quick_xml::events::Event;
use quick_xml::Reader;
@ -9,6 +8,7 @@ use std::collections::BTreeMap;
use std::io::BufRead;
use std::iter::empty;
use std::str::FromStr;
use Result;
pub fn read_xml_results(source: impl BufRead + 'static) -> Result<QueryResult> {
enum State {

@ -1,4 +1,3 @@
use errors::*;
use model::*;
use std::collections::hash_map::DefaultHasher;
use std::collections::BTreeSet;
@ -6,6 +5,7 @@ use std::collections::HashMap;
use std::collections::HashSet;
use std::hash::Hash;
use std::hash::Hasher;
use Result;
#[derive(Eq, PartialEq, Hash, Ord, PartialOrd)]
struct SubjectPredicate {

@ -1,9 +1,9 @@
use errors::*;
use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::sync::RwLock;
use store::numeric_encoder::*;
use store::store::*;
use Result;
pub type MemoryDataset = StoreDataset<MemoryStore>;
pub type MemoryGraph = StoreDefaultGraph<MemoryStore>;

@ -1,5 +1,4 @@
use byteorder::{NetworkEndian, ReadBytesExt, WriteBytesExt};
use errors::*;
use model::*;
use std::io::Read;
use std::io::Write;
@ -8,6 +7,7 @@ use std::str;
use std::str::FromStr;
use url::Url;
use uuid::Uuid;
use Result;
pub trait BytesStore {
type BytesOutput: Deref<Target = [u8]>;
@ -213,7 +213,7 @@ impl<S: BytesStore> Encoder<S> {
}
pub fn encode_blank_node(&self, blank_node: &BlankNode) -> Result<EncodedTerm> {
Ok(EncodedTerm::BlankNode(*blank_node.deref()))
Ok(EncodedTerm::BlankNode(*blank_node.as_uuid()))
}
pub fn encode_literal(&self, literal: &Literal) -> Result<EncodedTerm> {
@ -225,7 +225,7 @@ impl<S: BytesStore> Encoder<S> {
} else {
Ok(EncodedTerm::TypedLiteral {
value_id: self.encode_str_value(&literal.value())?,
datatype_id: self.encode_str_value(literal.datatype().as_ref())?,
datatype_id: self.encode_str_value(literal.datatype().as_str())?,
})
}
}

@ -1,6 +1,5 @@
use byteorder::ByteOrder;
use byteorder::NetworkEndian;
use errors::*;
use rocksdb::ColumnFamily;
use rocksdb::DBRawIterator;
use rocksdb::DBVector;
@ -14,6 +13,7 @@ use std::sync::Mutex;
use store::numeric_encoder::*;
use store::store::EncodedQuadsStore;
use store::store::StoreDataset;
use Result;
pub type RocksDbDataset = StoreDataset<RocksDbStore>;

@ -1,10 +1,10 @@
use errors::*;
use sparql::algebra::*;
use std::iter::once;
use std::iter::Iterator;
use std::sync::Arc;
use store::numeric_encoder::EncodedTerm;
use store::store::EncodedQuadsStore;
use Result;
type EncodedBinding = Vec<Option<EncodedTerm>>;

@ -1,4 +1,3 @@
use errors::*;
use model::*;
use sparql::algebra::QueryResult;
use sparql::parser::read_sparql_query;
@ -11,6 +10,7 @@ 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

@ -8,7 +8,6 @@ extern crate url;
use reqwest::Client;
use reqwest::Response;
use rudf::errors::*;
use rudf::model::vocab::rdf;
use rudf::model::vocab::rdfs;
use rudf::model::*;
@ -17,6 +16,7 @@ use rudf::rio::turtle::read_turtle;
use rudf::rio::xml::read_rdf_xml;
use rudf::store::isomorphism::GraphIsomorphism;
use rudf::store::MemoryGraph;
use rudf::Result;
use std::error::Error;
use std::fmt;
use std::io::BufReader;
@ -294,7 +294,7 @@ impl<'a> Iterator for TestManifest<'a> {
.object_for_subject_predicate(&test_subject, &rdf::TYPE)
.unwrap()
{
Some(Term::NamedNode(c)) => match c.value().split("#").last() {
Some(Term::NamedNode(c)) => match c.as_str().split("#").last() {
Some(k) => k.to_string(),
None => return Some(Err("no type".into())),
},
@ -321,7 +321,7 @@ impl<'a> Iterator for TestManifest<'a> {
.object_for_subject_predicate(&test_subject, &*mf::ACTION)
.unwrap()
{
Some(Term::NamedNode(n)) => n.url().clone(),
Some(Term::NamedNode(n)) => n.as_url().clone(),
Some(_) => return Some(Err("invalid action".into())),
None => return Some(Err("action not found".into())),
};
@ -330,7 +330,7 @@ impl<'a> Iterator for TestManifest<'a> {
.object_for_subject_predicate(&test_subject, &*mf::RESULT)
.unwrap()
{
Some(Term::NamedNode(n)) => Some(n.url().clone()),
Some(Term::NamedNode(n)) => Some(n.as_url().clone()),
Some(_) => return Some(Err("invalid result".into())),
None => None,
};
@ -366,7 +366,7 @@ impl<'a> Iterator for TestManifest<'a> {
self.manifests_to_do.extend(
RdfListIterator::iter(&self.graph, list.clone().into())
.flat_map(|m| match m {
Term::NamedNode(nm) => Some(nm.url().clone()),
Term::NamedNode(nm) => Some(nm.as_url().clone()),
_ => None,
}),
);

@ -7,7 +7,6 @@ extern crate url;
use reqwest::Client;
use reqwest::Response;
use rudf::errors::*;
use rudf::model::vocab::rdf;
use rudf::model::vocab::rdfs;
use rudf::model::*;
@ -20,6 +19,7 @@ use rudf::sparql::xml_results::read_xml_results;
use rudf::store::isomorphism::GraphIsomorphism;
use rudf::store::MemoryDataset;
use rudf::store::MemoryGraph;
use rudf::Result;
use std::error::Error;
use std::fmt;
use std::io::BufReader;
@ -366,7 +366,7 @@ impl<'a> Iterator for TestManifest<'a> {
.object_for_subject_predicate(&test_subject, &rdf::TYPE)
.unwrap()
{
Some(Term::NamedNode(c)) => match c.value().split("#").last() {
Some(Term::NamedNode(c)) => match c.as_str().split("#").last() {
Some(k) => k.to_string(),
None => return Some(Err("no type".into())),
},
@ -464,7 +464,7 @@ impl<'a> Iterator for TestManifest<'a> {
self.manifests_to_do.extend(
RdfListIterator::iter(&self.graph, list.clone().into())
.flat_map(|m| match m {
Term::NamedNode(nm) => Some(nm.url().clone()),
Term::NamedNode(nm) => Some(nm.as_url().clone()),
_ => None,
}),
);

Loading…
Cancel
Save