Skip to content

Commit 29b9cf0

Browse files
committedAug 22, 2024
feat(cognitarium): allow to issue term from variable
1 parent 2a40d06 commit 29b9cf0

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
 

‎contracts/axone-cognitarium/src/querier/variable.rs

+26
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::msg::{Value, IRI};
2+
use crate::querier::expression::Term;
23
use crate::state::{Literal, NamespaceSolver, Object, Predicate, Subject};
34
use axone_rdf::normalize::IdentifierIssuer;
45
use cosmwasm_std::StdResult;
@@ -95,6 +96,31 @@ impl ResolvedVariable {
9596
},
9697
})
9798
}
99+
100+
pub fn as_term(&self, ns_solver: &mut dyn NamespaceSolver) -> StdResult<Term> {
101+
Ok(match self {
102+
ResolvedVariable::Subject(subject) => match subject {
103+
Subject::Named(named) => named.as_iri(ns_solver).map(Term::String)?,
104+
Subject::Blank(blank) => Term::String(format!("_:{}", blank)),
105+
},
106+
ResolvedVariable::Predicate(predicate) => {
107+
predicate.as_iri(ns_solver).map(Term::String)?
108+
}
109+
ResolvedVariable::Object(object) => match object {
110+
Object::Named(named) => named.as_iri(ns_solver).map(Term::String)?,
111+
Object::Blank(blank) => Term::String(format!("_:{}", blank)),
112+
Object::Literal(literal) => Term::String(match literal {
113+
Literal::Simple { value } => value.clone(),
114+
Literal::I18NString { value, language } => {
115+
format!("{}{}", value, language).to_string()
116+
}
117+
Literal::Typed { value, datatype } => {
118+
format!("{}{}", value, datatype.as_iri(ns_solver)?).to_string()
119+
}
120+
}),
121+
},
122+
})
123+
}
98124
}
99125

100126
#[derive(Eq, PartialEq, Debug, Clone)]

0 commit comments

Comments
 (0)
Please sign in to comment.