Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/blank node identifier #499

Merged
merged 22 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
2e60a12
feat(cognitarium): introduce blank node id counter state
amimart Feb 27, 2024
96286f7
feat(rdf): allow to get incremented raw id from issuer
amimart Feb 27, 2024
1a492e7
feat(cognitarium): update triple state model with u128 as bnode
amimart Feb 27, 2024
93acb93
feat(cognitarium): generate bnode identifiers on query
amimart Feb 27, 2024
7dfb48e
feat(cognitarium)!: rework delete input to remove template bnodes
amimart Feb 27, 2024
a194d1c
refactor(cognitarium)!: use var or named node as msg pattern predicate
amimart Feb 27, 2024
f15d822
feat(cognitarium)!: rework construct clause based on template
amimart Feb 27, 2024
54f6b63
test(cognitarium): add bnode insert counter test
amimart Feb 27, 2024
2ea17d7
test(cognitarium): update msg tests
amimart Feb 28, 2024
f22eb81
feat(cognitarium): issue new id for bnode provided in construct
amimart Feb 28, 2024
8514d5f
style: little coup de polish
amimart Feb 28, 2024
ea2013b
docs(cognitarium): update docs from schema
amimart Feb 28, 2024
8fecdea
test(dataverse): update tests according to cognitarium api
amimart Feb 28, 2024
61ff078
feat(cognitarium): reuse where clause in construct empty
amimart Feb 28, 2024
72766ff
perf(cognitarium): use resolved variables to construct atoms
amimart Feb 28, 2024
57ce519
refactor(cognitarium): share duplicate code for queries
amimart Feb 28, 2024
e389931
perf(cognitarium): use resolved vars to contruct triples
amimart Feb 28, 2024
2e763ee
fix(cognitarium): allow to reuse where as delete select
amimart Feb 28, 2024
b574e59
docs(cognitarium): update generated doc
amimart Feb 28, 2024
e22d9b9
feat(cognitarium): allow delete without where clause
amimart Feb 28, 2024
9a7085a
style(cognitarium): make it readable
amimart Feb 28, 2024
b7a1272
style(cognitarium): remove dead code
amimart Feb 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
743 changes: 451 additions & 292 deletions contracts/okp4-cognitarium/src/contract.rs

Large diffs are not rendered by default.

151 changes: 46 additions & 105 deletions contracts/okp4-cognitarium/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
/// "where": [
/// { "simple": { "triplePattern": {
/// "subject": { "variable": "s" },
/// "predicate": { "node": { "namedNode": {"prefixed": "foaf:givenName"} } },
/// "predicate": { "namedNode": {"prefixed": "foaf:givenName"} },
/// "object": { "literal": { "simple": "Myrddin" } }
/// } } },
/// { "simple": { "triplePattern": {
Expand All @@ -67,9 +67,9 @@
DeleteData {
/// The prefixes used in the operation.
prefixes: Vec<Prefix>,
/// Specifies the specific triple patterns to delete.
/// Specifies the specific triple templates to delete.
/// If nothing is provided, the patterns from the `where` clause are used for deletion.
delete: Vec<TriplePattern>,
delete: Vec<TripleDeleteTemplate>,
/// Defines the patterns that data (RDF triples) should match in order for it to be
/// considered for deletion.
r#where: WhereClause,
Expand Down Expand Up @@ -436,7 +436,7 @@
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>,
pub construct: Vec<TripleConstructTemplate>,
/// The WHERE clause.
/// This clause is used to specify the triples to construct using variable bindings.
pub r#where: WhereClause,
Expand Down Expand Up @@ -484,39 +484,42 @@
TriplePattern(TriplePattern),
}

/// # TripleDeleteTemplate
/// Represents a triple template to be deleted.
#[cw_serde]

Check warning on line 489 in contracts/okp4-cognitarium/src/msg.rs

View check run for this annotation

Codecov / codecov/patch

contracts/okp4-cognitarium/src/msg.rs#L489

Added line #L489 was not covered by tests
pub struct TripleDeleteTemplate {
/// The subject of the triple pattern.
pub subject: VarOrNamedNode,
/// The predicate of the triple pattern.
pub predicate: VarOrNamedNode,
/// The object of the triple pattern.
pub object: VarOrNamedNodeOrLiteral,
}

/// # TripleConstructTemplate
/// Represents a triple template to be forged for a construct query.
#[cw_serde]

Check warning on line 501 in contracts/okp4-cognitarium/src/msg.rs

View check run for this annotation

Codecov / codecov/patch

contracts/okp4-cognitarium/src/msg.rs#L501

Added line #L501 was not covered by tests
pub struct TripleConstructTemplate {
/// The subject of the triple pattern.
pub subject: VarOrNode,
/// The predicate of the triple pattern.
pub predicate: VarOrNamedNode,
/// The object of the triple pattern.
pub object: VarOrNodeOrLiteral,
}

/// # TriplePattern
/// Represents a triple pattern in a [SimpleWhereCondition].
#[cw_serde]
pub struct TriplePattern {
/// The subject of the triple pattern.
pub subject: VarOrNode,
/// The predicate of the triple pattern.
pub predicate: VarOrNode,
pub predicate: VarOrNamedNode,
/// The object of the triple pattern.
pub object: VarOrNodeOrLiteral,
}

impl TriplePattern {
/// Returns the variables used in the triple pattern.
pub fn variables(&self) -> Vec<String> {
let mut variables: Vec<String> = vec![];

if let VarOrNode::Variable(var) = &self.subject {
variables.push(var.clone());
}

if let VarOrNode::Variable(var) = &self.predicate {
variables.push(var.clone());
}

if let VarOrNodeOrLiteral::Variable(var) = &self.object {
variables.push(var.clone());
}

variables
}
}

/// # VarOrNode
/// Represents either a variable or a node.
#[cw_serde]
Expand Down Expand Up @@ -557,6 +560,22 @@
Literal(Literal),
}

/// # VarOrNamedNodeOrLiteral
/// Represents either a variable, a named node or a literal.
#[cw_serde]

Check warning on line 565 in contracts/okp4-cognitarium/src/msg.rs

View check run for this annotation

Codecov / codecov/patch

contracts/okp4-cognitarium/src/msg.rs#L565

Added line #L565 was not covered by tests
pub enum VarOrNamedNodeOrLiteral {
/// # Variable
/// A variable.
Variable(String),
/// # NamedNode
/// An RDF [IRI](https://www.w3.org/TR/rdf11-concepts/#dfn-iri).
NamedNode(IRI),
/// # Literal
/// An RDF [literal](https://www.w3.org/TR/rdf11-concepts/#dfn-literal), i.e. a simple literal,
/// a language-tagged string or a typed value.
Literal(Literal),
}

/// # Literal
/// An RDF [literal](https://www.w3.org/TR/rdf11-concepts/#dfn-literal).
#[cw_serde]
Expand Down Expand Up @@ -596,12 +615,7 @@

#[cfg(test)]
mod tests {
use crate::msg::Literal::Simple;
use crate::msg::Node::{BlankNode, NamedNode};
use crate::msg::IRI::{Full, Prefixed};
use crate::msg::{
InstantiateMsg, StoreLimitsInput, TriplePattern, VarOrNode, VarOrNodeOrLiteral,
};
use crate::msg::{InstantiateMsg, StoreLimitsInput};
use cosmwasm_std::Uint128;
use schemars::_serde_json;

Comment on lines 615 to 621
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [618-658]

The tests for default deserialization of StoreLimitsInput and InstantiateMsg are crucial for ensuring that the system's limitations and instantiation parameters are correctly handled. These tests validate the default values for various store limits, which is important for the system's robustness and reliability. Ensure that additional tests are added to cover the new changes introduced in this PR, especially regarding the handling of blank nodes and the new structs and enums.

Would you like assistance in adding more comprehensive tests to cover the new changes introduced in this PR?

Expand Down Expand Up @@ -636,77 +650,4 @@
assert_eq!(msg.limits.max_insert_data_byte_size, Uint128::MAX);
assert_eq!(msg.limits.max_insert_data_triple_count, Uint128::MAX);
}

#[test]
fn variables_from_triple_pattern() {
let (s, p, o) = ("s".to_string(), "p".to_string(), "o".to_string());
let (node, prefixed, literal) = (
"node".to_string(),
"a:node".to_string(),
"literal".to_string(),
);

let cases = vec![
(
TriplePattern {
subject: VarOrNode::Variable(s.clone()),
predicate: VarOrNode::Variable(p.clone()),
object: VarOrNodeOrLiteral::Variable(o.clone()),
},
vec![s.clone(), p.clone(), o.clone()],
),
(
TriplePattern {
subject: VarOrNode::Node(NamedNode(Full(node.clone()))),
predicate: VarOrNode::Variable(p.clone()),
object: VarOrNodeOrLiteral::Variable(o.clone()),
},
vec![p.clone(), o.clone()],
),
(
TriplePattern {
subject: VarOrNode::Node(NamedNode(Prefixed(prefixed.clone()))),
predicate: VarOrNode::Variable(p.clone()),
object: VarOrNodeOrLiteral::Variable(o.clone()),
},
vec![p.clone(), o.clone()],
),
(
TriplePattern {
subject: VarOrNode::Node(BlankNode(node.clone())),
predicate: VarOrNode::Variable(p.clone()),
object: VarOrNodeOrLiteral::Variable(o.clone()),
},
vec![p.clone(), o.clone()],
),
(
TriplePattern {
subject: VarOrNode::Variable(s.clone()),
predicate: VarOrNode::Node(NamedNode(Full(node.clone()))),
object: VarOrNodeOrLiteral::Variable(o.clone()),
},
vec![s.clone(), o],
),
(
TriplePattern {
subject: VarOrNode::Variable(s.clone()),
predicate: VarOrNode::Variable(p.clone()),
object: VarOrNodeOrLiteral::Literal(Simple(literal.clone())),
},
vec![s, p],
),
(
TriplePattern {
subject: VarOrNode::Node(BlankNode(node)),
predicate: VarOrNode::Node(NamedNode(Prefixed(prefixed))),
object: VarOrNodeOrLiteral::Literal(Simple(literal)),
},
vec![],
),
];

for (triple_pattern, expected) in cases {
assert_eq!(triple_pattern.variables(), expected);
}
}
}
Loading
Loading