From 29b9cf01ec5985dc9dfb9d25cffffcccd46dfd1d Mon Sep 17 00:00:00 2001 From: Arnaud Mimart <33665250+amimart@users.noreply.github.com> Date: Thu, 22 Aug 2024 10:39:58 +0200 Subject: [PATCH] feat(cognitarium): allow to issue term from variable --- .../axone-cognitarium/src/querier/variable.rs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/contracts/axone-cognitarium/src/querier/variable.rs b/contracts/axone-cognitarium/src/querier/variable.rs index d3458d91..511d13be 100644 --- a/contracts/axone-cognitarium/src/querier/variable.rs +++ b/contracts/axone-cognitarium/src/querier/variable.rs @@ -1,4 +1,5 @@ use crate::msg::{Value, IRI}; +use crate::querier::expression::Term; use crate::state::{Literal, NamespaceSolver, Object, Predicate, Subject}; use axone_rdf::normalize::IdentifierIssuer; use cosmwasm_std::StdResult; @@ -95,6 +96,31 @@ impl ResolvedVariable { }, }) } + + pub fn as_term(&self, ns_solver: &mut dyn NamespaceSolver) -> StdResult { + Ok(match self { + ResolvedVariable::Subject(subject) => match subject { + Subject::Named(named) => named.as_iri(ns_solver).map(Term::String)?, + Subject::Blank(blank) => Term::String(format!("_:{}", blank)), + }, + ResolvedVariable::Predicate(predicate) => { + predicate.as_iri(ns_solver).map(Term::String)? + } + ResolvedVariable::Object(object) => match object { + Object::Named(named) => named.as_iri(ns_solver).map(Term::String)?, + Object::Blank(blank) => Term::String(format!("_:{}", blank)), + Object::Literal(literal) => Term::String(match literal { + Literal::Simple { value } => value.clone(), + Literal::I18NString { value, language } => { + format!("{}{}", value, language).to_string() + } + Literal::Typed { value, datatype } => { + format!("{}{}", value, datatype.as_iri(ns_solver)?).to_string() + } + }), + }, + }) + } } #[derive(Eq, PartialEq, Debug, Clone)]