Drops support of plain literals

They are merged with xsd:string datatyped literal in RDF 1.1
pull/10/head
Tpt 6 years ago
parent 1e474cd320
commit 25397c5751
  1. 32
      lib/src/model/literal.rs
  2. 62
      lib/src/sparql/eval.rs
  3. 29
      lib/src/store/numeric_encoder.rs
  4. 2
      lib/tests/sparql_test_cases.rs

@ -40,7 +40,6 @@ pub struct Literal(LiteralContent);
#[derive(PartialEq, Eq, Ord, PartialOrd, Debug, Clone, Hash)] #[derive(PartialEq, Eq, Ord, PartialOrd, Debug, Clone, Hash)]
enum LiteralContent { enum LiteralContent {
SimpleLiteral(String),
String(String), String(String),
LanguageTaggedString { value: String, language: String }, LanguageTaggedString { value: String, language: String },
Boolean(bool), Boolean(bool),
@ -58,7 +57,7 @@ enum LiteralContent {
impl Literal { impl Literal {
/// Builds a RDF [simple literal](https://www.w3.org/TR/rdf11-concepts/#dfn-simple-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 { pub fn new_simple_literal(value: impl Into<String>) -> Self {
Literal(LiteralContent::SimpleLiteral(value.into())) Literal(LiteralContent::String(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) /// 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)
@ -143,8 +142,7 @@ impl Literal {
/// The literal [lexical form](https://www.w3.org/TR/rdf11-concepts/#dfn-lexical-form) /// The literal [lexical form](https://www.w3.org/TR/rdf11-concepts/#dfn-lexical-form)
pub fn value(&self) -> Cow<'_, str> { pub fn value(&self) -> Cow<'_, str> {
match self.0 { match self.0 {
LiteralContent::SimpleLiteral(ref value) LiteralContent::String(ref value)
| LiteralContent::String(ref value)
| LiteralContent::LanguageTaggedString { ref value, .. } | LiteralContent::LanguageTaggedString { ref value, .. }
| LiteralContent::TypedLiteral { ref value, .. } => Cow::Borrowed(value), | LiteralContent::TypedLiteral { ref value, .. } => Cow::Borrowed(value),
LiteralContent::Boolean(value) => Cow::Owned(value.to_string()), LiteralContent::Boolean(value) => Cow::Owned(value.to_string()),
@ -174,7 +172,7 @@ impl Literal {
/// 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). /// 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 { pub fn datatype(&self) -> &NamedNode {
match self.0 { match self.0 {
LiteralContent::SimpleLiteral(_) | LiteralContent::String(_) => &xsd::STRING, LiteralContent::String(_) => &xsd::STRING,
LiteralContent::LanguageTaggedString { .. } => &rdf::LANG_STRING, LiteralContent::LanguageTaggedString { .. } => &rdf::LANG_STRING,
LiteralContent::Boolean(_) => &xsd::BOOLEAN, LiteralContent::Boolean(_) => &xsd::BOOLEAN,
LiteralContent::Float(_) => &xsd::FLOAT, LiteralContent::Float(_) => &xsd::FLOAT,
@ -191,10 +189,10 @@ impl Literal {
/// 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) /// 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`. /// or has the datatype [xsd:string](http://www.w3.org/2001/XMLSchema#string).
pub fn is_plain(&self) -> bool { pub fn is_plain(&self) -> bool {
match self.0 { match self.0 {
LiteralContent::SimpleLiteral(_) | LiteralContent::LanguageTaggedString { .. } => true, LiteralContent::String(_) | LiteralContent::LanguageTaggedString { .. } => true,
_ => false, _ => false,
} }
} }
@ -282,9 +280,7 @@ impl Literal {
/// Returns the [effective boolean value](https://www.w3.org/TR/sparql11-query/#ebv) of the literal if it exists /// Returns the [effective boolean value](https://www.w3.org/TR/sparql11-query/#ebv) of the literal if it exists
pub fn to_bool(&self) -> Option<bool> { pub fn to_bool(&self) -> Option<bool> {
match self.0 { match self.0 {
LiteralContent::SimpleLiteral(ref value) | LiteralContent::String(ref value) => { LiteralContent::String(ref value) => Some(!value.is_empty()),
Some(!value.is_empty())
}
LiteralContent::Boolean(value) => Some(value), LiteralContent::Boolean(value) => Some(value),
LiteralContent::Float(value) => Some(!value.is_zero()), LiteralContent::Float(value) => Some(!value.is_zero()),
LiteralContent::Double(value) => Some(!value.is_zero()), LiteralContent::Double(value) => Some(!value.is_zero()),
@ -302,9 +298,7 @@ impl Literal {
LiteralContent::Integer(value) => value.to_f32(), LiteralContent::Integer(value) => value.to_f32(),
LiteralContent::Decimal(value) => value.to_f32(), LiteralContent::Decimal(value) => value.to_f32(),
LiteralContent::Boolean(value) => Some(if value { 1. } else { 0. }), LiteralContent::Boolean(value) => Some(if value { 1. } else { 0. }),
LiteralContent::SimpleLiteral(ref value) | LiteralContent::String(ref value) => { LiteralContent::String(ref value) => value.parse().ok(),
value.parse().ok()
}
_ => None, _ => None,
} }
} }
@ -317,9 +311,7 @@ impl Literal {
LiteralContent::Integer(value) => value.to_f64(), LiteralContent::Integer(value) => value.to_f64(),
LiteralContent::Decimal(value) => value.to_f64(), LiteralContent::Decimal(value) => value.to_f64(),
LiteralContent::Boolean(value) => Some(if value { 1. } else { 0. }), LiteralContent::Boolean(value) => Some(if value { 1. } else { 0. }),
LiteralContent::SimpleLiteral(ref value) | LiteralContent::String(ref value) => { LiteralContent::String(ref value) => value.parse().ok(),
value.parse().ok()
}
_ => None, _ => None,
} }
} }
@ -332,9 +324,7 @@ impl Literal {
LiteralContent::Integer(value) => value.to_i128(), LiteralContent::Integer(value) => value.to_i128(),
LiteralContent::Decimal(value) => value.to_i128(), LiteralContent::Decimal(value) => value.to_i128(),
LiteralContent::Boolean(value) => Some(if value { 1 } else { 0 }), LiteralContent::Boolean(value) => Some(if value { 1 } else { 0 }),
LiteralContent::SimpleLiteral(ref value) | LiteralContent::String(ref value) => { LiteralContent::String(ref value) => value.parse().ok(),
value.parse().ok()
}
_ => None, _ => None,
} }
} }
@ -351,9 +341,7 @@ impl Literal {
} else { } else {
Decimal::zero() Decimal::zero()
}), }),
LiteralContent::SimpleLiteral(ref value) | LiteralContent::String(ref value) => { LiteralContent::String(ref value) => value.parse().ok(),
value.parse().ok()
}
_ => None, _ => None,
} }
} }

@ -445,32 +445,30 @@ impl<S: EncodedQuadsStore> SimpleEvaluator<S> {
PlanExpression::UnaryNot(e) => self PlanExpression::UnaryNot(e) => self
.to_bool(self.eval_expression(e, tuple)?) .to_bool(self.eval_expression(e, tuple)?)
.map(|v| (!v).into()), .map(|v| (!v).into()),
PlanExpression::Str(e) => Some(EncodedTerm::SimpleLiteral { PlanExpression::Str(e) => Some(EncodedTerm::StringLiteral {
value_id: self.to_string_id(self.eval_expression(e, tuple)?)?, value_id: self.to_string_id(self.eval_expression(e, tuple)?)?,
}), }),
PlanExpression::Lang(e) => match self.eval_expression(e, tuple)? { PlanExpression::Lang(e) => match self.eval_expression(e, tuple)? {
EncodedTerm::LangStringLiteral { language_id, .. } => { EncodedTerm::LangStringLiteral { language_id, .. } => {
Some(EncodedTerm::SimpleLiteral { Some(EncodedTerm::StringLiteral {
value_id: language_id, value_id: language_id,
}) })
} }
e if e.is_literal() => Some(ENCODED_EMPTY_SIMPLE_LITERAL), e if e.is_literal() => Some(ENCODED_EMPTY_STRING_LITERAL),
_ => None, _ => None,
}, },
PlanExpression::Datatype(e) => self.eval_expression(e, tuple)?.datatype(), PlanExpression::Datatype(e) => self.eval_expression(e, tuple)?.datatype(),
PlanExpression::Bound(v) => Some(has_tuple_value(*v, tuple).into()), PlanExpression::Bound(v) => Some(has_tuple_value(*v, tuple).into()),
PlanExpression::IRI(e) => match self.eval_expression(e, tuple)? { PlanExpression::IRI(e) => match self.eval_expression(e, tuple)? {
EncodedTerm::NamedNode { iri_id } => Some(EncodedTerm::NamedNode { iri_id }), EncodedTerm::NamedNode { iri_id } => Some(EncodedTerm::NamedNode { iri_id }),
EncodedTerm::SimpleLiteral { value_id } EncodedTerm::StringLiteral { value_id } => {
| EncodedTerm::StringLiteral { value_id } => {
Some(EncodedTerm::NamedNode { iri_id: value_id }) Some(EncodedTerm::NamedNode { iri_id: value_id })
} }
_ => None, _ => None,
}, },
PlanExpression::BNode(id) => match id { PlanExpression::BNode(id) => match id {
Some(id) => match self.eval_expression(id, tuple)? { Some(id) => match self.eval_expression(id, tuple)? {
EncodedTerm::SimpleLiteral { value_id } EncodedTerm::StringLiteral { value_id } => Some(
| EncodedTerm::StringLiteral { value_id } => Some(
self.bnodes_map self.bnodes_map
.lock() .lock()
.ok()? .ok()?
@ -525,7 +523,7 @@ impl<S: EncodedQuadsStore> SimpleEvaluator<S> {
.insert_str(&Uuid::new_v4().to_urn().to_string()) .insert_str(&Uuid::new_v4().to_urn().to_string())
.ok()?, .ok()?,
}), }),
PlanExpression::StrUUID() => Some(EncodedTerm::SimpleLiteral { PlanExpression::StrUUID() => Some(EncodedTerm::StringLiteral {
value_id: self value_id: self
.store .store
.insert_str(&Uuid::new_v4().to_simple().to_string()) .insert_str(&Uuid::new_v4().to_simple().to_string())
@ -624,8 +622,7 @@ impl<S: EncodedQuadsStore> SimpleEvaluator<S> {
} }
PlanExpression::BooleanCast(e) => match self.eval_expression(e, tuple)? { PlanExpression::BooleanCast(e) => match self.eval_expression(e, tuple)? {
EncodedTerm::BooleanLiteral(value) => Some(value.into()), EncodedTerm::BooleanLiteral(value) => Some(value.into()),
EncodedTerm::SimpleLiteral { value_id } EncodedTerm::StringLiteral { value_id } => {
| EncodedTerm::StringLiteral { value_id } => {
match &*self.store.get_str(value_id).ok()? { match &*self.store.get_str(value_id).ok()? {
"true" | "1" => Some(true.into()), "true" | "1" => Some(true.into()),
"false" | "0" => Some(false.into()), "false" | "0" => Some(false.into()),
@ -642,8 +639,7 @@ impl<S: EncodedQuadsStore> SimpleEvaluator<S> {
EncodedTerm::BooleanLiteral(value) => { EncodedTerm::BooleanLiteral(value) => {
Some(if value { 1. as f64 } else { 0. }.into()) Some(if value { 1. as f64 } else { 0. }.into())
} }
EncodedTerm::SimpleLiteral { value_id } EncodedTerm::StringLiteral { value_id } => Some(EncodedTerm::DoubleLiteral(
| EncodedTerm::StringLiteral { value_id } => Some(EncodedTerm::DoubleLiteral(
OrderedFloat(self.store.get_str(value_id).ok()?.parse().ok()?), OrderedFloat(self.store.get_str(value_id).ok()?.parse().ok()?),
)), )),
_ => None, _ => None,
@ -656,8 +652,7 @@ impl<S: EncodedQuadsStore> SimpleEvaluator<S> {
EncodedTerm::BooleanLiteral(value) => { EncodedTerm::BooleanLiteral(value) => {
Some(if value { 1. as f32 } else { 0. }.into()) Some(if value { 1. as f32 } else { 0. }.into())
} }
EncodedTerm::SimpleLiteral { value_id } EncodedTerm::StringLiteral { value_id } => Some(EncodedTerm::FloatLiteral(
| EncodedTerm::StringLiteral { value_id } => Some(EncodedTerm::FloatLiteral(
OrderedFloat(self.store.get_str(value_id).ok()?.parse().ok()?), OrderedFloat(self.store.get_str(value_id).ok()?.parse().ok()?),
)), )),
_ => None, _ => None,
@ -668,8 +663,7 @@ impl<S: EncodedQuadsStore> SimpleEvaluator<S> {
EncodedTerm::IntegerLiteral(value) => Some(value.to_i128()?.into()), EncodedTerm::IntegerLiteral(value) => Some(value.to_i128()?.into()),
EncodedTerm::DecimalLiteral(value) => Some(value.to_i128()?.into()), EncodedTerm::DecimalLiteral(value) => Some(value.to_i128()?.into()),
EncodedTerm::BooleanLiteral(value) => Some(if value { 1 } else { 0 }.into()), EncodedTerm::BooleanLiteral(value) => Some(if value { 1 } else { 0 }.into()),
EncodedTerm::SimpleLiteral { value_id } EncodedTerm::StringLiteral { value_id } => Some(EncodedTerm::IntegerLiteral(
| EncodedTerm::StringLiteral { value_id } => Some(EncodedTerm::IntegerLiteral(
self.store.get_str(value_id).ok()?.parse().ok()?, self.store.get_str(value_id).ok()?.parse().ok()?,
)), )),
_ => None, _ => None,
@ -687,8 +681,7 @@ impl<S: EncodedQuadsStore> SimpleEvaluator<S> {
} }
.into(), .into(),
), ),
EncodedTerm::SimpleLiteral { value_id } EncodedTerm::StringLiteral { value_id } => Some(EncodedTerm::DecimalLiteral(
| EncodedTerm::StringLiteral { value_id } => Some(EncodedTerm::DecimalLiteral(
self.store.get_str(value_id).ok()?.parse().ok()?, self.store.get_str(value_id).ok()?.parse().ok()?,
)), )),
_ => None, _ => None,
@ -697,8 +690,7 @@ impl<S: EncodedQuadsStore> SimpleEvaluator<S> {
EncodedTerm::NaiveDate(value) => Some(value.into()), EncodedTerm::NaiveDate(value) => Some(value.into()),
EncodedTerm::DateTime(value) => Some(value.date().naive_utc().into()), //TODO: use date with timezone EncodedTerm::DateTime(value) => Some(value.date().naive_utc().into()), //TODO: use date with timezone
EncodedTerm::NaiveDateTime(value) => Some(value.date().into()), EncodedTerm::NaiveDateTime(value) => Some(value.date().into()),
EncodedTerm::SimpleLiteral { value_id } EncodedTerm::StringLiteral { value_id } => {
| EncodedTerm::StringLiteral { value_id } => {
let value = self.store.get_str(value_id).ok()?; let value = self.store.get_str(value_id).ok()?;
Some(NaiveDate::parse_from_str(&value, "%Y-%m-%d").ok()?.into()) Some(NaiveDate::parse_from_str(&value, "%Y-%m-%d").ok()?.into())
} }
@ -708,8 +700,7 @@ impl<S: EncodedQuadsStore> SimpleEvaluator<S> {
EncodedTerm::NaiveTime(value) => Some(value.into()), EncodedTerm::NaiveTime(value) => Some(value.into()),
EncodedTerm::DateTime(value) => Some(value.time().into()), EncodedTerm::DateTime(value) => Some(value.time().into()),
EncodedTerm::NaiveDateTime(value) => Some(value.time().into()), EncodedTerm::NaiveDateTime(value) => Some(value.time().into()),
EncodedTerm::SimpleLiteral { value_id } EncodedTerm::StringLiteral { value_id } => {
| EncodedTerm::StringLiteral { value_id } => {
let value = self.store.get_str(value_id).ok()?; let value = self.store.get_str(value_id).ok()?;
Some(NaiveTime::parse_from_str(&value, "%H:%M:%S").ok()?.into()) Some(NaiveTime::parse_from_str(&value, "%H:%M:%S").ok()?.into())
} }
@ -718,8 +709,7 @@ impl<S: EncodedQuadsStore> SimpleEvaluator<S> {
PlanExpression::DateTimeCast(e) => match self.eval_expression(e, tuple)? { PlanExpression::DateTimeCast(e) => match self.eval_expression(e, tuple)? {
EncodedTerm::DateTime(value) => Some(value.into()), EncodedTerm::DateTime(value) => Some(value.into()),
EncodedTerm::NaiveDateTime(value) => Some(value.into()), EncodedTerm::NaiveDateTime(value) => Some(value.into()),
EncodedTerm::SimpleLiteral { value_id } EncodedTerm::StringLiteral { value_id } => {
| EncodedTerm::StringLiteral { value_id } => {
let value = self.store.get_str(value_id).ok()?; let value = self.store.get_str(value_id).ok()?;
Some(match DateTime::parse_from_rfc3339(&value) { Some(match DateTime::parse_from_rfc3339(&value) {
Ok(value) => value.into(), Ok(value) => value.into(),
@ -739,7 +729,6 @@ impl<S: EncodedQuadsStore> SimpleEvaluator<S> {
fn to_bool(&self, term: EncodedTerm) -> Option<bool> { fn to_bool(&self, term: EncodedTerm) -> Option<bool> {
match term { match term {
EncodedTerm::BooleanLiteral(value) => Some(value), EncodedTerm::BooleanLiteral(value) => Some(value),
EncodedTerm::SimpleLiteral { .. } => Some(term != ENCODED_EMPTY_SIMPLE_LITERAL),
EncodedTerm::StringLiteral { .. } => Some(term != ENCODED_EMPTY_STRING_LITERAL), EncodedTerm::StringLiteral { .. } => Some(term != ENCODED_EMPTY_STRING_LITERAL),
EncodedTerm::FloatLiteral(value) => Some(!value.is_zero()), EncodedTerm::FloatLiteral(value) => Some(!value.is_zero()),
EncodedTerm::DoubleLiteral(value) => Some(!value.is_zero()), EncodedTerm::DoubleLiteral(value) => Some(!value.is_zero()),
@ -754,8 +743,7 @@ impl<S: EncodedQuadsStore> SimpleEvaluator<S> {
EncodedTerm::DefaultGraph {} => None, EncodedTerm::DefaultGraph {} => None,
EncodedTerm::NamedNode { iri_id } => Some(iri_id), EncodedTerm::NamedNode { iri_id } => Some(iri_id),
EncodedTerm::BlankNode(_) => None, EncodedTerm::BlankNode(_) => None,
EncodedTerm::SimpleLiteral { value_id } EncodedTerm::StringLiteral { value_id }
| EncodedTerm::StringLiteral { value_id }
| EncodedTerm::LangStringLiteral { value_id, .. } | EncodedTerm::LangStringLiteral { value_id, .. }
| EncodedTerm::TypedLiteral { value_id, .. } => Some(value_id), | EncodedTerm::TypedLiteral { value_id, .. } => Some(value_id),
EncodedTerm::BooleanLiteral(value) => self EncodedTerm::BooleanLiteral(value) => self
@ -774,7 +762,7 @@ impl<S: EncodedQuadsStore> SimpleEvaluator<S> {
} }
fn to_simple_string(&self, term: EncodedTerm) -> Option<String> { fn to_simple_string(&self, term: EncodedTerm) -> Option<String> {
if let EncodedTerm::SimpleLiteral { value_id } = term { if let EncodedTerm::StringLiteral { value_id } = term {
Some(self.store.get_str(value_id).ok()?.into()) Some(self.store.get_str(value_id).ok()?.into())
} else { } else {
None None
@ -782,7 +770,7 @@ impl<S: EncodedQuadsStore> SimpleEvaluator<S> {
} }
fn to_simple_string_id(&self, term: EncodedTerm) -> Option<u64> { fn to_simple_string_id(&self, term: EncodedTerm) -> Option<u64> {
if let EncodedTerm::SimpleLiteral { value_id } = term { if let EncodedTerm::StringLiteral { value_id } = term {
Some(value_id) Some(value_id)
} else { } else {
None None
@ -791,8 +779,7 @@ impl<S: EncodedQuadsStore> SimpleEvaluator<S> {
fn to_string(&self, term: EncodedTerm) -> Option<String> { fn to_string(&self, term: EncodedTerm) -> Option<String> {
match term { match term {
EncodedTerm::SimpleLiteral { value_id } EncodedTerm::StringLiteral { value_id }
| EncodedTerm::StringLiteral { value_id }
| EncodedTerm::LangStringLiteral { value_id, .. } => { | EncodedTerm::LangStringLiteral { value_id, .. } => {
Some(self.store.get_str(value_id).ok()?.into()) Some(self.store.get_str(value_id).ok()?.into())
} }
@ -931,12 +918,13 @@ impl<S: EncodedQuadsStore> SimpleEvaluator<S> {
fn partial_cmp_literals(&self, a: EncodedTerm, b: EncodedTerm) -> Option<Ordering> { fn partial_cmp_literals(&self, a: EncodedTerm, b: EncodedTerm) -> Option<Ordering> {
match a { match a {
EncodedTerm::SimpleLiteral { value_id: a } EncodedTerm::StringLiteral { value_id: a } => {
| EncodedTerm::StringLiteral { value_id: a } => match b { if let EncodedTerm::StringLiteral { value_id: b } = b {
EncodedTerm::SimpleLiteral { value_id: b } self.compare_str_ids(a, b)
| EncodedTerm::StringLiteral { value_id: b } => self.compare_str_ids(a, b), } else {
_ => None, None
}, }
}
EncodedTerm::FloatLiteral(a) => match b { EncodedTerm::FloatLiteral(a) => match b {
EncodedTerm::FloatLiteral(b) => (*a).partial_cmp(&*b), EncodedTerm::FloatLiteral(b) => (*a).partial_cmp(&*b),
EncodedTerm::DoubleLiteral(b) => a.to_f64()?.partial_cmp(&*b), EncodedTerm::DoubleLiteral(b) => a.to_f64()?.partial_cmp(&*b),

@ -128,7 +128,6 @@ impl StringStore for MemoryStringStore {
const TYPE_DEFAULT_GRAPH_ID: u8 = 0; const TYPE_DEFAULT_GRAPH_ID: u8 = 0;
const TYPE_NAMED_NODE_ID: u8 = 1; const TYPE_NAMED_NODE_ID: u8 = 1;
const TYPE_BLANK_NODE_ID: u8 = 2; const TYPE_BLANK_NODE_ID: u8 = 2;
const TYPE_SIMPLE_LITERAL_ID: u8 = 3;
const TYPE_LANG_STRING_LITERAL_ID: u8 = 4; const TYPE_LANG_STRING_LITERAL_ID: u8 = 4;
const TYPE_TYPED_LITERAL_ID: u8 = 5; const TYPE_TYPED_LITERAL_ID: u8 = 5;
const TYPE_STRING_LITERAL: u8 = 6; const TYPE_STRING_LITERAL: u8 = 6;
@ -144,9 +143,6 @@ const TYPE_NAIVE_DATE_LITERAL: u8 = 15;
const TYPE_NAIVE_TIME_LITERAL: u8 = 16; const TYPE_NAIVE_TIME_LITERAL: u8 = 16;
pub static ENCODED_DEFAULT_GRAPH: EncodedTerm = EncodedTerm::DefaultGraph {}; pub static ENCODED_DEFAULT_GRAPH: EncodedTerm = EncodedTerm::DefaultGraph {};
pub static ENCODED_EMPTY_SIMPLE_LITERAL: EncodedTerm = EncodedTerm::SimpleLiteral {
value_id: EMPTY_STRING_ID,
};
pub static ENCODED_EMPTY_STRING_LITERAL: EncodedTerm = EncodedTerm::StringLiteral { pub static ENCODED_EMPTY_STRING_LITERAL: EncodedTerm = EncodedTerm::StringLiteral {
value_id: EMPTY_STRING_ID, value_id: EMPTY_STRING_ID,
}; };
@ -186,10 +182,9 @@ pub enum EncodedTerm {
DefaultGraph {}, DefaultGraph {},
NamedNode { iri_id: u64 }, NamedNode { iri_id: u64 },
BlankNode(Uuid), BlankNode(Uuid),
SimpleLiteral { value_id: u64 }, StringLiteral { value_id: u64 },
LangStringLiteral { value_id: u64, language_id: u64 }, LangStringLiteral { value_id: u64, language_id: u64 },
TypedLiteral { value_id: u64, datatype_id: u64 }, TypedLiteral { value_id: u64, datatype_id: u64 },
StringLiteral { value_id: u64 },
BooleanLiteral(bool), BooleanLiteral(bool),
FloatLiteral(OrderedFloat<f32>), FloatLiteral(OrderedFloat<f32>),
DoubleLiteral(OrderedFloat<f64>), DoubleLiteral(OrderedFloat<f64>),
@ -218,10 +213,9 @@ impl EncodedTerm {
pub fn is_literal(&self) -> bool { pub fn is_literal(&self) -> bool {
match self { match self {
EncodedTerm::SimpleLiteral { .. } EncodedTerm::StringLiteral { .. }
| EncodedTerm::LangStringLiteral { .. } | EncodedTerm::LangStringLiteral { .. }
| EncodedTerm::TypedLiteral { .. } | EncodedTerm::TypedLiteral { .. }
| EncodedTerm::StringLiteral { .. }
| EncodedTerm::BooleanLiteral(_) | EncodedTerm::BooleanLiteral(_)
| EncodedTerm::FloatLiteral(_) | EncodedTerm::FloatLiteral(_)
| EncodedTerm::DoubleLiteral(_) | EncodedTerm::DoubleLiteral(_)
@ -237,9 +231,7 @@ impl EncodedTerm {
pub fn datatype(&self) -> Option<Self> { pub fn datatype(&self) -> Option<Self> {
match self { match self {
EncodedTerm::SimpleLiteral { .. } | EncodedTerm::StringLiteral { .. } => { EncodedTerm::StringLiteral { .. } => Some(ENCODED_XSD_STRING_NAMED_NODE),
Some(ENCODED_XSD_STRING_NAMED_NODE)
}
EncodedTerm::LangStringLiteral { .. } => Some(ENCODED_RDF_LANG_STRING_NAMED_NODE), EncodedTerm::LangStringLiteral { .. } => Some(ENCODED_RDF_LANG_STRING_NAMED_NODE),
EncodedTerm::TypedLiteral { datatype_id, .. } => Some(EncodedTerm::NamedNode { EncodedTerm::TypedLiteral { datatype_id, .. } => Some(EncodedTerm::NamedNode {
iri_id: *datatype_id, iri_id: *datatype_id,
@ -263,10 +255,9 @@ impl EncodedTerm {
EncodedTerm::DefaultGraph { .. } => TYPE_DEFAULT_GRAPH_ID, EncodedTerm::DefaultGraph { .. } => TYPE_DEFAULT_GRAPH_ID,
EncodedTerm::NamedNode { .. } => TYPE_NAMED_NODE_ID, EncodedTerm::NamedNode { .. } => TYPE_NAMED_NODE_ID,
EncodedTerm::BlankNode(_) => TYPE_BLANK_NODE_ID, EncodedTerm::BlankNode(_) => TYPE_BLANK_NODE_ID,
EncodedTerm::SimpleLiteral { .. } => TYPE_SIMPLE_LITERAL_ID, EncodedTerm::StringLiteral { .. } => TYPE_STRING_LITERAL,
EncodedTerm::LangStringLiteral { .. } => TYPE_LANG_STRING_LITERAL_ID, EncodedTerm::LangStringLiteral { .. } => TYPE_LANG_STRING_LITERAL_ID,
EncodedTerm::TypedLiteral { .. } => TYPE_TYPED_LITERAL_ID, EncodedTerm::TypedLiteral { .. } => TYPE_TYPED_LITERAL_ID,
EncodedTerm::StringLiteral { .. } => TYPE_STRING_LITERAL,
EncodedTerm::BooleanLiteral(true) => TYPE_BOOLEAN_LITERAL_TRUE, EncodedTerm::BooleanLiteral(true) => TYPE_BOOLEAN_LITERAL_TRUE,
EncodedTerm::BooleanLiteral(false) => TYPE_BOOLEAN_LITERAL_FALSE, EncodedTerm::BooleanLiteral(false) => TYPE_BOOLEAN_LITERAL_FALSE,
EncodedTerm::FloatLiteral(_) => TYPE_FLOAT_LITERAL, EncodedTerm::FloatLiteral(_) => TYPE_FLOAT_LITERAL,
@ -396,9 +387,6 @@ impl<R: Read> TermReader for R {
self.read_exact(&mut uuid_buffer)?; self.read_exact(&mut uuid_buffer)?;
Ok(EncodedTerm::BlankNode(Uuid::from_bytes(uuid_buffer))) Ok(EncodedTerm::BlankNode(Uuid::from_bytes(uuid_buffer)))
} }
TYPE_SIMPLE_LITERAL_ID => Ok(EncodedTerm::SimpleLiteral {
value_id: self.read_u64::<LittleEndian>()?,
}),
TYPE_LANG_STRING_LITERAL_ID => Ok(EncodedTerm::LangStringLiteral { TYPE_LANG_STRING_LITERAL_ID => Ok(EncodedTerm::LangStringLiteral {
language_id: self.read_u64::<LittleEndian>()?, language_id: self.read_u64::<LittleEndian>()?,
value_id: self.read_u64::<LittleEndian>()?, value_id: self.read_u64::<LittleEndian>()?,
@ -511,7 +499,7 @@ impl<R: Write> TermWriter for R {
EncodedTerm::DefaultGraph {} => {} EncodedTerm::DefaultGraph {} => {}
EncodedTerm::NamedNode { iri_id } => self.write_u64::<LittleEndian>(iri_id)?, EncodedTerm::NamedNode { iri_id } => self.write_u64::<LittleEndian>(iri_id)?,
EncodedTerm::BlankNode(id) => self.write_all(id.as_bytes())?, EncodedTerm::BlankNode(id) => self.write_all(id.as_bytes())?,
EncodedTerm::SimpleLiteral { value_id } | EncodedTerm::StringLiteral { value_id } => { EncodedTerm::StringLiteral { value_id } => {
self.write_u64::<LittleEndian>(value_id)?; self.write_u64::<LittleEndian>(value_id)?;
} }
EncodedTerm::LangStringLiteral { EncodedTerm::LangStringLiteral {
@ -605,7 +593,7 @@ impl<S: StringStore> Encoder<S> {
language_id: self.string_store.insert_str(language)?, language_id: self.string_store.insert_str(language)?,
} }
} else { } else {
EncodedTerm::SimpleLiteral { EncodedTerm::StringLiteral {
value_id: self.string_store.insert_str(&literal.value())?, value_id: self.string_store.insert_str(&literal.value())?,
} }
} }
@ -715,7 +703,7 @@ impl<S: StringStore> Encoder<S> {
Ok(NamedNode::from(self.string_store.get_url(iri_id)?).into()) Ok(NamedNode::from(self.string_store.get_url(iri_id)?).into())
} }
EncodedTerm::BlankNode(id) => Ok(BlankNode::from(id).into()), EncodedTerm::BlankNode(id) => Ok(BlankNode::from(id).into()),
EncodedTerm::SimpleLiteral { value_id } => { EncodedTerm::StringLiteral { value_id } => {
Ok(Literal::new_simple_literal(self.string_store.get_str(value_id)?).into()) Ok(Literal::new_simple_literal(self.string_store.get_str(value_id)?).into())
} }
EncodedTerm::LangStringLiteral { EncodedTerm::LangStringLiteral {
@ -734,9 +722,6 @@ impl<S: StringStore> Encoder<S> {
NamedNode::from(self.string_store.get_url(datatype_id)?), NamedNode::from(self.string_store.get_url(datatype_id)?),
) )
.into()), .into()),
EncodedTerm::StringLiteral { value_id } => {
Ok(Literal::from(self.string_store.get_str(value_id)?.into()).into())
}
EncodedTerm::BooleanLiteral(value) => Ok(Literal::from(value).into()), EncodedTerm::BooleanLiteral(value) => Ok(Literal::from(value).into()),
EncodedTerm::FloatLiteral(value) => Ok(Literal::from(*value).into()), EncodedTerm::FloatLiteral(value) => Ok(Literal::from(*value).into()),
EncodedTerm::DoubleLiteral(value) => Ok(Literal::from(*value).into()), EncodedTerm::DoubleLiteral(value) => Ok(Literal::from(*value).into()),

@ -158,6 +158,8 @@ fn sparql_w3c_query_evaluation_testsuite() {
NamedNode::from_str( NamedNode::from_str(
"http://www.w3.org/2001/sw/DataAccess/tests/data-r2/expr-builtin/manifest#sameTerm-not-eq", "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/expr-builtin/manifest#sameTerm-not-eq",
).unwrap(), ).unwrap(),
//Simple literal vs xsd:string. We apply RDF 1.1
NamedNode::from_str("http://www.w3.org/2001/sw/DataAccess/tests/data-r2/distinct/manifest#distinct-2").unwrap(),
//URI normalization: we are normalizing more strongly //URI normalization: we are normalizing more strongly
NamedNode::from_str( NamedNode::from_str(
"http://www.w3.org/2001/sw/DataAccess/tests/data-r2/i18n/manifest#normalization-3", "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/i18n/manifest#normalization-3",

Loading…
Cancel
Save