Skip to content

Commit

Permalink
feat(cognitarium): allow to issue term from variable
Browse files Browse the repository at this point in the history
  • Loading branch information
amimart committed Aug 22, 2024
1 parent 2a40d06 commit 29b9cf0
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions contracts/axone-cognitarium/src/querier/variable.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -95,6 +96,31 @@ impl ResolvedVariable {
},
})
}

pub fn as_term(&self, ns_solver: &mut dyn NamespaceSolver) -> StdResult<Term> {
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)]
Expand Down

0 comments on commit 29b9cf0

Please sign in to comment.