Skip to content

Commit

Permalink
feat(cognitarium): specify construction query
Browse files Browse the repository at this point in the history
  • Loading branch information
ccamel committed Aug 23, 2023
1 parent 254654f commit 111a73c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
21 changes: 17 additions & 4 deletions contracts/okp4-cognitarium/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ pub fn query(deps: Deps<'_>, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
QueryMsg::Describe { query, format } => to_binary(&query::describe(
deps,
query,
format.unwrap_or(DataFormat::Turtle),
format.unwrap_or(DataFormat::default()),
)?),
QueryMsg::Construct { query, format } => to_binary(&query::construct(
deps,
query,
format.unwrap_or(DataFormat::default()),
)?),
}
}
Expand All @@ -90,9 +95,9 @@ pub mod query {

use super::*;
use crate::msg::{
DescribeQuery, DescribeResponse, Node, Prefix, SelectItem, SelectQuery, SelectResponse,
SimpleWhereCondition, StoreResponse, TriplePattern, Value, VarOrNamedNode, VarOrNode,
VarOrNodeOrLiteral, WhereCondition,
ConstructQuery, DescribeQuery, DescribeResponse, Node, Prefix, SelectItem, SelectQuery,
SelectResponse, SimpleWhereCondition, StoreResponse, TriplePattern, Value, VarOrNamedNode,
VarOrNode, VarOrNodeOrLiteral, WhereCondition,
};
use crate::querier::{PlanBuilder, QueryEngine};
use crate::rdf::{self, Atom, TripleWriter};
Expand Down Expand Up @@ -224,6 +229,14 @@ pub mod query {
data: Binary::from(out),
})
}

pub fn construct(
_deps: Deps<'_>,
_query: ConstructQuery,
_format: DataFormat,
) -> StdResult<SelectResponse> {
todo!()
}
}

#[cfg(test)]
Expand Down
40 changes: 40 additions & 0 deletions contracts/okp4-cognitarium/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,26 @@ pub enum QueryMsg {
/// If not provided, the default format is [Turtle](https://www.w3.org/TR/turtle/) format.
format: Option<DataFormat>,
},

/// # Construct
///
/// Returns the resources matching the criteria defined by the provided query as a set of RDF
/// triples serialized in the provided format.
#[returns(ConstructResponse)]
Construct {
/// The query to execute.
query: ConstructQuery,
/// The format in which the triples are serialized.
/// If not provided, the default format is [Turtle](https://www.w3.org/TR/turtle/) format.
format: Option<DataFormat>,
},
}

/// # DataFormat
/// Represents the format in which the data are serialized, for example when returned by a query or
/// when inserted in the store.
#[cw_serde]
#[derive(Default)]
pub enum DataFormat {
/// # RDF XML
/// Output in [RDF/XML](https://www.w3.org/TR/rdf-syntax-grammar/) format.
Expand All @@ -121,6 +135,7 @@ pub enum DataFormat {
/// # Turtle
/// Output in [Turtle](https://www.w3.org/TR/turtle/) format.
#[serde(rename = "turtle")]
#[default]
Turtle,
/// # N-Triples
/// Output in [N-Triples](https://www.w3.org/TR/n-triples/) format.
Expand Down Expand Up @@ -308,6 +323,16 @@ pub struct DescribeResponse {
pub data: Binary,
}

/// # ConstructResponse
/// Represents the response of a [QueryMsg::Construct] query.
#[cw_serde]
pub struct ConstructResponse {
/// The format of the data.
pub format: DataFormat,
/// The data serialized in the specified format.
pub data: Binary,
}

/// # Head
/// Represents the head of a [SelectResponse].
#[cw_serde]
Expand Down Expand Up @@ -389,6 +414,21 @@ pub struct DescribeQuery {
pub r#where: WhereClause,
}

/// # ConstructQuery
/// Represents a CONSTRUCT query over the triple store, allowing to retrieve a set of triples
/// serialized in a specific format.
#[cw_serde]
pub struct ConstructQuery {
/// The prefixes used in the query.
pub prefixes: Vec<Prefix>,
/// The triples to construct.
/// If nothing is provided, the patterns from the `where` clause are used for construction.
pub construct: Vec<TriplePattern>,
/// The WHERE clause.
/// This clause is used to specify the triples to construct using variable bindings.
pub r#where: WhereClause,
}

/// # Prefix
/// Represents a prefix in a [SelectQuery]. A prefix is a shortcut for a namespace used in the query.
#[cw_serde]
Expand Down

0 comments on commit 111a73c

Please sign in to comment.