diff --git a/contracts/okp4-cognitarium/src/contract.rs b/contracts/okp4-cognitarium/src/contract.rs index 74603966..43b8432f 100644 --- a/contracts/okp4-cognitarium/src/contract.rs +++ b/contracts/okp4-cognitarium/src/contract.rs @@ -97,7 +97,7 @@ pub mod query { VarOrNodeOrLiteral, WhereCondition, IRI, }; use crate::querier::{PlanBuilder, QueryEngine}; - use crate::rdf::{self, expand_uri, Atom, TripleWriter}; + use crate::rdf::{self, expand_uri, Atom, Subject, TripleWriter}; pub fn store(deps: Deps) -> StdResult { STORE.load(deps.storage).map(|s| s.into()) @@ -214,12 +214,13 @@ pub mod query { let subject = match subject_value { Value::URI { value: IRI::Full(uri), - } => uri, + } => Subject::NamedNode(uri), Value::URI { value: IRI::Prefixed(curie), - } => expand_uri(curie, &query.prefixes)?, + } => Subject::NamedNode(expand_uri(curie, &query.prefixes)?), + Value::BlankNode { value: id } => Subject::BlankNode(id.clone()), _ => Err(StdError::generic_err(format!( - "Unexpected value: {subject_value:?} (this was unexpected)" + "Unexpected subject value: {subject_value:?} (this was unexpected)" )))?, }; @@ -232,7 +233,7 @@ pub mod query { value: IRI::Prefixed(curie), } => expand_uri(curie, &query.prefixes)?, _ => Err(StdError::generic_err(format!( - "Unexpected value: {predicate_value:?} (this was unexpected)" + "Unexpected predicate value: {predicate_value:?} (this was unexpected)" )))?, }; @@ -266,7 +267,7 @@ pub mod query { } => rdf::Value::LiteralDatatype(value, expand_uri(curie, &query.prefixes)?), Value::BlankNode { value } => rdf::Value::BlankNode(value), _ => Err(StdError::generic_err(format!( - "Unexpected value: {object_value:?} (this was unexpected)" + "Unexpected object value: {object_value:?} (this was unexpected)" )))?, }; diff --git a/contracts/okp4-cognitarium/src/rdf/atom.rs b/contracts/okp4-cognitarium/src/rdf/atom.rs index 6ffce2fc..e185c27c 100644 --- a/contracts/okp4-cognitarium/src/rdf/atom.rs +++ b/contracts/okp4-cognitarium/src/rdf/atom.rs @@ -1,3 +1,21 @@ +use rio_api::model::{Literal, NamedNode, Triple}; +use std::fmt; + +#[derive(Eq, PartialEq, Debug, Clone, Hash)] +pub enum Subject { + NamedNode(String), + BlankNode(String), +} + +impl fmt::Display for Subject { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Subject::NamedNode(s) => write!(f, "{s}"), + Subject::BlankNode(s) => write!(f, "{s}"), + } + } +} + #[derive(Eq, PartialEq, Debug, Clone, Hash)] pub enum Value { NamedNode(String), @@ -7,9 +25,6 @@ pub enum Value { LiteralDatatype(String, String), } -use std::fmt; - -use rio_api::model::{Literal, NamedNode, Triple}; impl fmt::Display for Value { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { @@ -24,7 +39,7 @@ impl fmt::Display for Value { #[derive(Eq, PartialEq, Debug, Clone, Hash)] pub struct Atom { - pub subject: String, + pub subject: Subject, pub property: String, pub value: Value, } @@ -42,8 +57,9 @@ impl std::fmt::Display for Atom { impl<'a> From<&'a Atom> for Triple<'a> { fn from(atom: &'a Atom) -> Self { Triple { - subject: NamedNode { - iri: atom.subject.as_str(), + subject: match &atom.subject { + Subject::NamedNode(s) => NamedNode { iri: s.as_str() }, + Subject::BlankNode(s) => NamedNode { iri: s.as_str() }, } .into(), predicate: NamedNode {