|
|
@ -481,80 +481,33 @@ impl From<EncodedTriple> for EncodedTerm { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[derive(Eq, PartialEq, Debug, Clone, Hash)] |
|
|
|
impl From<NamedNodeRef<'_>> for EncodedTerm { |
|
|
|
pub struct EncodedTriple { |
|
|
|
fn from(named_node: NamedNodeRef<'_>) -> Self { |
|
|
|
pub subject: EncodedTerm, |
|
|
|
Self::NamedNode { |
|
|
|
pub predicate: EncodedTerm, |
|
|
|
|
|
|
|
pub object: EncodedTerm, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl EncodedTriple { |
|
|
|
|
|
|
|
pub fn new(subject: EncodedTerm, predicate: EncodedTerm, object: EncodedTerm) -> Self { |
|
|
|
|
|
|
|
Self { |
|
|
|
|
|
|
|
subject, |
|
|
|
|
|
|
|
predicate, |
|
|
|
|
|
|
|
object, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Eq, PartialEq, Debug, Clone, Hash)] |
|
|
|
|
|
|
|
pub struct EncodedQuad { |
|
|
|
|
|
|
|
pub subject: EncodedTerm, |
|
|
|
|
|
|
|
pub predicate: EncodedTerm, |
|
|
|
|
|
|
|
pub object: EncodedTerm, |
|
|
|
|
|
|
|
pub graph_name: EncodedTerm, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl EncodedQuad { |
|
|
|
|
|
|
|
pub fn new( |
|
|
|
|
|
|
|
subject: EncodedTerm, |
|
|
|
|
|
|
|
predicate: EncodedTerm, |
|
|
|
|
|
|
|
object: EncodedTerm, |
|
|
|
|
|
|
|
graph_name: EncodedTerm, |
|
|
|
|
|
|
|
) -> Self { |
|
|
|
|
|
|
|
Self { |
|
|
|
|
|
|
|
subject, |
|
|
|
|
|
|
|
predicate, |
|
|
|
|
|
|
|
object, |
|
|
|
|
|
|
|
graph_name, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub(crate) trait StrLookup { |
|
|
|
|
|
|
|
type Error: Error + Into<EvaluationError> + 'static; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn get_str(&self, key: &StrHash) -> Result<Option<String>, Self::Error>; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn contains_str(&self, key: &StrHash) -> Result<bool, Self::Error>; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub(crate) trait StrContainer: StrLookup { |
|
|
|
|
|
|
|
fn insert_str(&self, key: &StrHash, value: &str) -> Result<bool, Self::Error>; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
pub(crate) fn get_encoded_named_node(named_node: NamedNodeRef<'_>) -> EncodedTerm { |
|
|
|
|
|
|
|
EncodedTerm::NamedNode { |
|
|
|
|
|
|
|
iri_id: StrHash::new(named_node.as_str()), |
|
|
|
iri_id: StrHash::new(named_node.as_str()), |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub(crate) fn get_encoded_blank_node(blank_node: BlankNodeRef<'_>) -> EncodedTerm { |
|
|
|
impl From<BlankNodeRef<'_>> for EncodedTerm { |
|
|
|
|
|
|
|
fn from(blank_node: BlankNodeRef<'_>) -> Self { |
|
|
|
if let Some(id) = blank_node.id() { |
|
|
|
if let Some(id) = blank_node.id() { |
|
|
|
EncodedTerm::NumericalBlankNode { id } |
|
|
|
Self::NumericalBlankNode { id } |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
let id = blank_node.as_str(); |
|
|
|
let id = blank_node.as_str(); |
|
|
|
if let Ok(id) = id.try_into() { |
|
|
|
if let Ok(id) = id.try_into() { |
|
|
|
EncodedTerm::SmallBlankNode(id) |
|
|
|
Self::SmallBlankNode(id) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
EncodedTerm::BigBlankNode { |
|
|
|
Self::BigBlankNode { |
|
|
|
id_id: StrHash::new(id), |
|
|
|
id_id: StrHash::new(id), |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub(crate) fn get_encoded_literal(literal: LiteralRef<'_>) -> EncodedTerm { |
|
|
|
impl From<LiteralRef<'_>> for EncodedTerm { |
|
|
|
|
|
|
|
fn from(literal: LiteralRef<'_>) -> Self { |
|
|
|
let value = literal.value(); |
|
|
|
let value = literal.value(); |
|
|
|
let datatype = literal.datatype().as_str(); |
|
|
|
let datatype = literal.datatype().as_str(); |
|
|
|
let native_encoding = match datatype { |
|
|
|
let native_encoding = match datatype { |
|
|
@ -624,7 +577,9 @@ pub(crate) fn get_encoded_literal(literal: LiteralRef<'_>) -> EncodedTerm { |
|
|
|
"http://www.w3.org/2001/XMLSchema#yearMonthDuration" => { |
|
|
|
"http://www.w3.org/2001/XMLSchema#yearMonthDuration" => { |
|
|
|
parse_year_month_duration_str(value) |
|
|
|
parse_year_month_duration_str(value) |
|
|
|
} |
|
|
|
} |
|
|
|
"http://www.w3.org/2001/XMLSchema#dayTimeDuration" => parse_day_time_duration_str(value), |
|
|
|
"http://www.w3.org/2001/XMLSchema#dayTimeDuration" => { |
|
|
|
|
|
|
|
parse_day_time_duration_str(value) |
|
|
|
|
|
|
|
} |
|
|
|
_ => None, |
|
|
|
_ => None, |
|
|
|
}; |
|
|
|
}; |
|
|
|
match native_encoding { |
|
|
|
match native_encoding { |
|
|
@ -643,52 +598,118 @@ pub(crate) fn get_encoded_literal(literal: LiteralRef<'_>) -> EncodedTerm { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub(crate) fn get_encoded_subject(term: SubjectRef<'_>) -> EncodedTerm { |
|
|
|
impl From<SubjectRef<'_>> for EncodedTerm { |
|
|
|
|
|
|
|
fn from(term: SubjectRef<'_>) -> Self { |
|
|
|
match term { |
|
|
|
match term { |
|
|
|
SubjectRef::NamedNode(named_node) => get_encoded_named_node(named_node), |
|
|
|
SubjectRef::NamedNode(named_node) => named_node.into(), |
|
|
|
SubjectRef::BlankNode(blank_node) => get_encoded_blank_node(blank_node), |
|
|
|
SubjectRef::BlankNode(blank_node) => blank_node.into(), |
|
|
|
SubjectRef::Triple(triple) => { |
|
|
|
SubjectRef::Triple(triple) => triple.as_ref().into(), |
|
|
|
EncodedTerm::Triple(Rc::new(get_encoded_triple(triple.as_ref()))) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub(crate) fn get_encoded_term(term: TermRef<'_>) -> EncodedTerm { |
|
|
|
impl From<TermRef<'_>> for EncodedTerm { |
|
|
|
|
|
|
|
fn from(term: TermRef<'_>) -> Self { |
|
|
|
match term { |
|
|
|
match term { |
|
|
|
TermRef::NamedNode(named_node) => get_encoded_named_node(named_node), |
|
|
|
TermRef::NamedNode(named_node) => named_node.into(), |
|
|
|
TermRef::BlankNode(blank_node) => get_encoded_blank_node(blank_node), |
|
|
|
TermRef::BlankNode(blank_node) => blank_node.into(), |
|
|
|
TermRef::Literal(literal) => get_encoded_literal(literal), |
|
|
|
TermRef::Literal(literal) => literal.into(), |
|
|
|
TermRef::Triple(triple) => { |
|
|
|
TermRef::Triple(triple) => triple.as_ref().into(), |
|
|
|
EncodedTerm::Triple(Rc::new(get_encoded_triple(triple.as_ref()))) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub(crate) fn get_encoded_graph_name(name: GraphNameRef<'_>) -> EncodedTerm { |
|
|
|
impl From<GraphNameRef<'_>> for EncodedTerm { |
|
|
|
|
|
|
|
fn from(name: GraphNameRef<'_>) -> Self { |
|
|
|
match name { |
|
|
|
match name { |
|
|
|
GraphNameRef::NamedNode(named_node) => get_encoded_named_node(named_node), |
|
|
|
GraphNameRef::NamedNode(named_node) => named_node.into(), |
|
|
|
GraphNameRef::BlankNode(blank_node) => get_encoded_blank_node(blank_node), |
|
|
|
GraphNameRef::BlankNode(blank_node) => blank_node.into(), |
|
|
|
GraphNameRef::DefaultGraph => EncodedTerm::DefaultGraph, |
|
|
|
GraphNameRef::DefaultGraph => EncodedTerm::DefaultGraph, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl From<TripleRef<'_>> for EncodedTerm { |
|
|
|
|
|
|
|
fn from(triple: TripleRef<'_>) -> Self { |
|
|
|
|
|
|
|
EncodedTerm::Triple(Rc::new(triple.into())) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Eq, PartialEq, Debug, Clone, Hash)] |
|
|
|
|
|
|
|
pub struct EncodedTriple { |
|
|
|
|
|
|
|
pub subject: EncodedTerm, |
|
|
|
|
|
|
|
pub predicate: EncodedTerm, |
|
|
|
|
|
|
|
pub object: EncodedTerm, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl EncodedTriple { |
|
|
|
|
|
|
|
pub fn new(subject: EncodedTerm, predicate: EncodedTerm, object: EncodedTerm) -> Self { |
|
|
|
|
|
|
|
Self { |
|
|
|
|
|
|
|
subject, |
|
|
|
|
|
|
|
predicate, |
|
|
|
|
|
|
|
object, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub(crate) fn get_encoded_triple(quad: TripleRef<'_>) -> EncodedTriple { |
|
|
|
impl From<TripleRef<'_>> for EncodedTriple { |
|
|
|
|
|
|
|
fn from(triple: TripleRef<'_>) -> Self { |
|
|
|
EncodedTriple { |
|
|
|
EncodedTriple { |
|
|
|
subject: get_encoded_subject(quad.subject), |
|
|
|
subject: triple.subject.into(), |
|
|
|
predicate: get_encoded_named_node(quad.predicate), |
|
|
|
predicate: triple.predicate.into(), |
|
|
|
object: get_encoded_term(quad.object), |
|
|
|
object: triple.object.into(), |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Eq, PartialEq, Debug, Clone, Hash)] |
|
|
|
|
|
|
|
pub struct EncodedQuad { |
|
|
|
|
|
|
|
pub subject: EncodedTerm, |
|
|
|
|
|
|
|
pub predicate: EncodedTerm, |
|
|
|
|
|
|
|
pub object: EncodedTerm, |
|
|
|
|
|
|
|
pub graph_name: EncodedTerm, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl EncodedQuad { |
|
|
|
|
|
|
|
pub fn new( |
|
|
|
|
|
|
|
subject: EncodedTerm, |
|
|
|
|
|
|
|
predicate: EncodedTerm, |
|
|
|
|
|
|
|
object: EncodedTerm, |
|
|
|
|
|
|
|
graph_name: EncodedTerm, |
|
|
|
|
|
|
|
) -> Self { |
|
|
|
|
|
|
|
Self { |
|
|
|
|
|
|
|
subject, |
|
|
|
|
|
|
|
predicate, |
|
|
|
|
|
|
|
object, |
|
|
|
|
|
|
|
graph_name, |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub(crate) fn get_encoded_quad(quad: QuadRef<'_>) -> EncodedQuad { |
|
|
|
impl From<QuadRef<'_>> for EncodedQuad { |
|
|
|
|
|
|
|
fn from(quad: QuadRef<'_>) -> Self { |
|
|
|
EncodedQuad { |
|
|
|
EncodedQuad { |
|
|
|
subject: get_encoded_subject(quad.subject), |
|
|
|
subject: quad.subject.into(), |
|
|
|
predicate: get_encoded_named_node(quad.predicate), |
|
|
|
predicate: quad.predicate.into(), |
|
|
|
object: get_encoded_term(quad.object), |
|
|
|
object: quad.object.into(), |
|
|
|
graph_name: get_encoded_graph_name(quad.graph_name), |
|
|
|
graph_name: quad.graph_name.into(), |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub(crate) trait StrLookup { |
|
|
|
|
|
|
|
type Error: Error + Into<EvaluationError> + 'static; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn get_str(&self, key: &StrHash) -> Result<Option<String>, Self::Error>; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn contains_str(&self, key: &StrHash) -> Result<bool, Self::Error>; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub(crate) trait StrContainer: StrLookup { |
|
|
|
|
|
|
|
fn insert_str(&self, key: &StrHash, value: &str) -> Result<bool, Self::Error>; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Encodes a term and insert strings if needed
|
|
|
|
/// Encodes a term and insert strings if needed
|
|
|
|