Skip to content

Commit

Permalink
style(cognitarium): make it readable
Browse files Browse the repository at this point in the history
  • Loading branch information
amimart committed Feb 28, 2024
1 parent e22d9b9 commit 9a7085a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
2 changes: 1 addition & 1 deletion contracts/okp4-cognitarium/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ pub mod execute {
.collect::<StdResult<Vec<Triple>>>()?
} else {
query_engine
.construct_triples(plan, delete_templates)?
.construct_triples(plan, delete_templates)
.collect::<StdResult<Vec<Triple>>>()?
};

Expand Down
37 changes: 17 additions & 20 deletions contracts/okp4-cognitarium/src/querier/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,31 +66,28 @@ impl<'a> QueryEngine<'a> {
.map(|t| AtomTemplate::try_new(&plan, prefixes, t))
.collect::<StdResult<Vec<AtomTemplate>>>()?;

ResolvedAtomIterator::try_new(
Ok(ResolvedAtomIterator::new(
self.storage,
ns_cache.into(),
IdentifierIssuer::new("b", 0u128),
self.eval_plan(plan),
templates,
)
))
}

pub fn construct_triples(
&'a self,
plan: QueryPlan,
templates: Vec<TripleTemplate>,
) -> StdResult<ResolvedTripleIterator<'_>> {
ResolvedTripleIterator::try_new(self.eval_plan(plan), templates)
) -> ResolvedTripleIterator<'_> {
ResolvedTripleIterator::new(self.eval_plan(plan), templates)
}

pub fn make_triple_templates(
&'a self,
plan: &QueryPlan,
prefixes: &HashMap<String, String>,
templates: Either<
Vec<(VarOrNode, VarOrNamedNode, VarOrNodeOrLiteral)>,
Vec<(VarOrNamedNode, VarOrNamedNode, VarOrNamedNodeOrLiteral)>,
>,
templates: Either<Vec<TripleTemplateWithBlankNode>, Vec<TripleTemplateNoBlankNode>>,
ns_cache: Vec<Namespace>,
) -> StdResult<Vec<TripleTemplate>> {
let mut ns_resolver: NamespaceResolver = ns_cache.into();
Expand Down Expand Up @@ -536,15 +533,15 @@ pub struct ResolvedTripleIterator<'a> {
}

impl<'a> ResolvedTripleIterator<'a> {
pub fn try_new(
pub fn new(
upstream_iter: ResolvedVariablesIterator<'a>,
templates: Vec<TripleTemplate>,
) -> StdResult<Self> {
Ok(Self {
) -> Self {
Self {
upstream_iter,
templates,
buffer: VecDeque::new(),
})
}
}
}

Expand Down Expand Up @@ -590,16 +587,16 @@ pub struct TripleTemplate {
object: Either<Object, usize>,
}

pub type TripleTemplateWithBlankNode = (VarOrNode, VarOrNamedNode, VarOrNodeOrLiteral);
pub type TripleTemplateNoBlankNode = (VarOrNamedNode, VarOrNamedNode, VarOrNamedNodeOrLiteral);

impl TripleTemplate {
fn try_new(
storage: &dyn Storage,
ns_resolver: &mut NamespaceResolver,
plan: &QueryPlan,
prefixes: &HashMap<String, String>,
template: Either<
(VarOrNode, VarOrNamedNode, VarOrNodeOrLiteral),
(VarOrNamedNode, VarOrNamedNode, VarOrNamedNodeOrLiteral),
>,
template: Either<TripleTemplateWithBlankNode, TripleTemplateNoBlankNode>,
) -> StdResult<TripleTemplate> {
let (s_tpl, p_tpl, o_tpl) = match template {
Right((s, p, o)) => (Right(s), p, Right(o)),
Expand Down Expand Up @@ -759,21 +756,21 @@ pub struct ResolvedAtomIterator<'a> {
}

impl<'a> ResolvedAtomIterator<'a> {
pub fn try_new(
pub fn new(
storage: &'a dyn Storage,
ns_resolver: NamespaceResolver,
id_issuer: IdentifierIssuer,
upstream_iter: ResolvedVariablesIterator<'a>,
templates: Vec<AtomTemplate>,
) -> StdResult<Self> {
Ok(Self {
) -> Self {
Self {
storage,
ns_resolver,
id_issuer,
upstream_iter,
templates,
buffer: VecDeque::new(),
})
}
}
}

Expand Down
9 changes: 7 additions & 2 deletions contracts/okp4-cognitarium/src/querier/plan_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::msg::{
use crate::querier::mapper::{iri_as_node, literal_as_object};
use crate::querier::plan::{PatternValue, PlanVariable, QueryNode, QueryPlan};
use crate::state::{HasCachedNamespaces, Namespace, NamespaceResolver, Object, Predicate, Subject};
use cosmwasm_std::{StdError, StdResult, Storage};
use cosmwasm_std::{StdResult, Storage};
use std::collections::HashMap;

pub struct PlanBuilder<'a> {
Expand Down Expand Up @@ -480,7 +480,12 @@ mod test {
None,
None,
vec![],
Err(StdError::generic_err("Empty basic graph pattern")),
Ok(QueryPlan {
entrypoint: QueryNode::Noop {
bound_variables: vec![],
},
variables: vec![],
}),
),
(
None,
Expand Down

0 comments on commit 9a7085a

Please sign in to comment.