diff --git a/contracts/okp4-cognitarium/src/contract.rs b/contracts/okp4-cognitarium/src/contract.rs index c422cf3a..9ef1d23b 100644 --- a/contracts/okp4-cognitarium/src/contract.rs +++ b/contracts/okp4-cognitarium/src/contract.rs @@ -298,15 +298,15 @@ pub mod query { .map(|t| TripleConstructTemplate { subject: match t.subject { VarOrNode::Node(Node::BlankNode(n)) => { - VarOrNode::Node(Node::BlankNode(id_issuer.get_str_or_issue(n))) + VarOrNode::Node(Node::BlankNode(id_issuer.get_str_or_issue(n).to_string())) } _ => t.subject, }, predicate: t.predicate, object: match t.object { - VarOrNodeOrLiteral::Node(Node::BlankNode(n)) => { - VarOrNodeOrLiteral::Node(Node::BlankNode(id_issuer.get_str_or_issue(n))) - } + VarOrNodeOrLiteral::Node(Node::BlankNode(n)) => VarOrNodeOrLiteral::Node( + Node::BlankNode(id_issuer.get_str_or_issue(n).to_string()), + ), _ => t.object, }, }) diff --git a/contracts/okp4-cognitarium/src/querier/engine.rs b/contracts/okp4-cognitarium/src/querier/engine.rs index c48d8d80..ea423516 100644 --- a/contracts/okp4-cognitarium/src/querier/engine.rs +++ b/contracts/okp4-cognitarium/src/querier/engine.rs @@ -902,9 +902,9 @@ impl AtomTemplate { &mut |value| { Ok(match value { Subject::Named(n) => rdf::Subject::NamedNode(n.as_iri(resolve_ns_fn)?), - Subject::Blank(n) => { - rdf::Subject::BlankNode(id_issuer.get_str_or_issue(n.to_string())) - } + Subject::Blank(n) => rdf::Subject::BlankNode( + id_issuer.get_str_or_issue(n.to_string()).to_string(), + ), }) }, "subject", @@ -945,7 +945,7 @@ impl AtomTemplate { Ok(match value { Object::Named(n) => rdf::Value::NamedNode(n.as_iri(resolve_ns_fn)?), Object::Blank(n) => { - rdf::Value::BlankNode(id_issuer.get_str_or_issue(n.to_string())) + rdf::Value::BlankNode(id_issuer.get_str_or_issue(n.to_string()).to_string()) } Object::Literal(l) => match l { state::Literal::Simple { value } => rdf::Value::LiteralSimple(value), diff --git a/contracts/okp4-cognitarium/src/querier/variable.rs b/contracts/okp4-cognitarium/src/querier/variable.rs index 538a159b..4ff1f867 100644 --- a/contracts/okp4-cognitarium/src/querier/variable.rs +++ b/contracts/okp4-cognitarium/src/querier/variable.rs @@ -59,7 +59,7 @@ impl ResolvedVariable { value: IRI::Full(iri), })?, Subject::Blank(blank) => Value::BlankNode { - value: id_issuer.get_str_or_issue(blank.to_string()), + value: id_issuer.get_str_or_issue(blank.to_string()).to_string(), }, }, ResolvedVariable::Predicate(predicate) => { @@ -72,7 +72,7 @@ impl ResolvedVariable { value: IRI::Full(named.as_iri(ns_fn)?), }, Object::Blank(blank) => Value::BlankNode { - value: id_issuer.get_str_or_issue(blank.to_string()), + value: id_issuer.get_str_or_issue(blank.to_string()).to_string(), }, Object::Literal(literal) => match literal { Literal::Simple { value } => Value::Literal { diff --git a/packages/okp4-rdf/src/normalize.rs b/packages/okp4-rdf/src/normalize.rs index 37c0dc91..b9eb1541 100644 --- a/packages/okp4-rdf/src/normalize.rs +++ b/packages/okp4-rdf/src/normalize.rs @@ -233,7 +233,7 @@ impl<'a> Normalizer<'a> { if !issuer.issued(&related) { recursion_list.push(related.clone()); } - path.push_str(&issuer.get_str_or_issue(related)); + path.push_str(issuer.get_str_or_issue(related)); } } @@ -245,7 +245,7 @@ impl<'a> Normalizer<'a> { for related in recursion_list { let (result, mut issuer) = self.compute_n_degree_hash(&mut issuer, &related)?; path.push_str("_:"); - path.push_str(&issuer.get_str_or_issue(related)); + path.push_str(issuer.get_str_or_issue(related)); path.push('<'); path.push_str(&result); path.push('>'); @@ -347,25 +347,26 @@ impl IdentifierIssuer { } } - pub fn get_or_issue(&mut self, identifier: String) -> (u128, String) { - match self.issued.entry(identifier.clone()) { - Entry::Occupied(e) => e.get().clone(), + pub fn get_or_issue(&mut self, identifier: String) -> (u128, &str) { + let res = match self.issued.entry(identifier.clone()) { + Entry::Occupied(e) => e.into_mut(), Entry::Vacant(e) => { let n = self.counter; let str = format!("{}{}", self.prefix, n); self.counter += 1; self.issue_log.push(identifier); - e.insert((n, str)).clone() + e.insert((n, str)) } - } + }; + (res.0, res.1.as_str()) } pub fn get_n_or_issue(&mut self, identifier: String) -> u128 { self.get_or_issue(identifier).0 } - pub fn get_str_or_issue(&mut self, identifier: String) -> String { + pub fn get_str_or_issue(&mut self, identifier: String) -> &str { self.get_or_issue(identifier).1 }