|
1 | 1 | use crate::msg::{Value, IRI};
|
| 2 | +use crate::querier::expression::Term; |
2 | 3 | use crate::state::{Literal, NamespaceSolver, Object, Predicate, Subject};
|
3 | 4 | use axone_rdf::normalize::IdentifierIssuer;
|
4 | 5 | use cosmwasm_std::StdResult;
|
@@ -95,6 +96,31 @@ impl ResolvedVariable {
|
95 | 96 | },
|
96 | 97 | })
|
97 | 98 | }
|
| 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 | + } |
98 | 124 | }
|
99 | 125 |
|
100 | 126 | #[derive(Eq, PartialEq, Debug, Clone)]
|
|
0 commit comments