|
|
@ -773,7 +773,7 @@ pub(crate) trait StrLookup: WithStoreError { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub(crate) trait StrContainer: WithStoreError { |
|
|
|
pub(crate) trait StrContainer: WithStoreError { |
|
|
|
fn insert_str(&mut self, key: StrHash, value: &str) -> Result<(), Self::Error>; |
|
|
|
fn insert_str(&mut self, value: &str) -> Result<StrHash, Self::Error>; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub struct MemoryStrStore { |
|
|
|
pub struct MemoryStrStore { |
|
|
@ -800,9 +800,10 @@ impl StrLookup for MemoryStrStore { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl StrContainer for MemoryStrStore { |
|
|
|
impl StrContainer for MemoryStrStore { |
|
|
|
fn insert_str(&mut self, key: StrHash, value: &str) -> Result<(), Infallible> { |
|
|
|
fn insert_str(&mut self, value: &str) -> Result<StrHash, Infallible> { |
|
|
|
|
|
|
|
let key = StrHash::new(value); |
|
|
|
self.id2str.entry(key).or_insert_with(|| value.to_owned()); |
|
|
|
self.id2str.entry(key).or_insert_with(|| value.to_owned()); |
|
|
|
Ok(()) |
|
|
|
Ok(key) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -940,19 +941,18 @@ impl<S: StrContainer> Encoder for S { |
|
|
|
&mut self, |
|
|
|
&mut self, |
|
|
|
named_node: rio::NamedNode<'_>, |
|
|
|
named_node: rio::NamedNode<'_>, |
|
|
|
) -> Result<EncodedTerm, Self::Error> { |
|
|
|
) -> Result<EncodedTerm, Self::Error> { |
|
|
|
let iri_id = StrHash::new(named_node.iri); |
|
|
|
Ok(EncodedTerm::NamedNode { |
|
|
|
self.insert_str(iri_id, named_node.iri)?; |
|
|
|
iri_id: self.insert_str(named_node.iri)?, |
|
|
|
Ok(EncodedTerm::NamedNode { iri_id }) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn encode_blank_node(&mut self, blank_node: &BlankNode) -> Result<EncodedTerm, Self::Error> { |
|
|
|
fn encode_blank_node(&mut self, blank_node: &BlankNode) -> Result<EncodedTerm, Self::Error> { |
|
|
|
if let Some(id) = blank_node.id() { |
|
|
|
if let Some(id) = blank_node.id() { |
|
|
|
Ok(EncodedTerm::InlineBlankNode { id }) |
|
|
|
Ok(EncodedTerm::InlineBlankNode { id }) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
let id = blank_node.as_str(); |
|
|
|
Ok(EncodedTerm::NamedBlankNode { |
|
|
|
let id_id = StrHash::new(id); |
|
|
|
id_id: self.insert_str(blank_node.as_str())?, |
|
|
|
self.insert_str(id_id, id)?; |
|
|
|
}) |
|
|
|
Ok(EncodedTerm::NamedBlankNode { id_id }) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -975,29 +975,21 @@ impl<S: StrContainer> Encoder for S { |
|
|
|
literal: rio::Literal<'_>, |
|
|
|
literal: rio::Literal<'_>, |
|
|
|
) -> Result<EncodedTerm, Self::Error> { |
|
|
|
) -> Result<EncodedTerm, Self::Error> { |
|
|
|
Ok(match literal { |
|
|
|
Ok(match literal { |
|
|
|
rio::Literal::Simple { value } => { |
|
|
|
rio::Literal::Simple { value } => EncodedTerm::StringLiteral { |
|
|
|
let value_id = StrHash::new(value); |
|
|
|
value_id: self.insert_str(value)?, |
|
|
|
self.insert_str(value_id, value)?; |
|
|
|
}, |
|
|
|
EncodedTerm::StringLiteral { value_id } |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
rio::Literal::LanguageTaggedString { value, language } => { |
|
|
|
rio::Literal::LanguageTaggedString { value, language } => { |
|
|
|
let value_id = StrHash::new(value); |
|
|
|
|
|
|
|
self.insert_str(value_id, value)?; |
|
|
|
|
|
|
|
let language_id = StrHash::new(language); |
|
|
|
|
|
|
|
self.insert_str(language_id, language)?; |
|
|
|
|
|
|
|
EncodedTerm::LangStringLiteral { |
|
|
|
EncodedTerm::LangStringLiteral { |
|
|
|
value_id, |
|
|
|
value_id: self.insert_str(value)?, |
|
|
|
language_id, |
|
|
|
language_id: self.insert_str(language)?, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
rio::Literal::Typed { value, datatype } => { |
|
|
|
rio::Literal::Typed { value, datatype } => { |
|
|
|
match match datatype.iri { |
|
|
|
match match datatype.iri { |
|
|
|
"http://www.w3.org/2001/XMLSchema#boolean" => parse_boolean_str(value), |
|
|
|
"http://www.w3.org/2001/XMLSchema#boolean" => parse_boolean_str(value), |
|
|
|
"http://www.w3.org/2001/XMLSchema#string" => { |
|
|
|
"http://www.w3.org/2001/XMLSchema#string" => Some(EncodedTerm::StringLiteral { |
|
|
|
let value_id = StrHash::new(value); |
|
|
|
value_id: self.insert_str(value)?, |
|
|
|
self.insert_str(value_id, value)?; |
|
|
|
}), |
|
|
|
Some(EncodedTerm::StringLiteral { value_id }) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
"http://www.w3.org/2001/XMLSchema#float" => parse_float_str(value), |
|
|
|
"http://www.w3.org/2001/XMLSchema#float" => parse_float_str(value), |
|
|
|
"http://www.w3.org/2001/XMLSchema#double" => parse_double_str(value), |
|
|
|
"http://www.w3.org/2001/XMLSchema#double" => parse_double_str(value), |
|
|
|
"http://www.w3.org/2001/XMLSchema#integer" |
|
|
|
"http://www.w3.org/2001/XMLSchema#integer" |
|
|
@ -1032,16 +1024,10 @@ impl<S: StrContainer> Encoder for S { |
|
|
|
_ => None, |
|
|
|
_ => None, |
|
|
|
} { |
|
|
|
} { |
|
|
|
Some(v) => v, |
|
|
|
Some(v) => v, |
|
|
|
None => { |
|
|
|
None => EncodedTerm::TypedLiteral { |
|
|
|
let value_id = StrHash::new(value); |
|
|
|
value_id: self.insert_str(value)?, |
|
|
|
self.insert_str(value_id, value)?; |
|
|
|
datatype_id: self.insert_str(datatype.iri)?, |
|
|
|
let datatype_id = StrHash::new(datatype.iri); |
|
|
|
}, |
|
|
|
self.insert_str(datatype_id, datatype.iri)?; |
|
|
|
|
|
|
|
EncodedTerm::TypedLiteral { |
|
|
|
|
|
|
|
value_id, |
|
|
|
|
|
|
|
datatype_id, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|