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

Migrate ReasoningIT to BDD #81

Merged
merged 25 commits into from
Jul 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions behaviour/graql/language/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ exports_files([
"get.feature",
"insert.feature",
"match.feature",
"rule-validation.feature",
"undefine.feature",
])
4 changes: 3 additions & 1 deletion behaviour/graql/language/define.feature
Original file line number Diff line number Diff line change
Expand Up @@ -1253,6 +1253,8 @@ Feature: Graql Define Query
# RULES #
#########

# Note: These tests verify only the ability to create rules, and are not concerned with their application.

Scenario: a rule can infer both an attribute and its ownership
Given graql define
"""
Expand Down Expand Up @@ -1281,7 +1283,7 @@ Feature: Graql Define Query
| RUL |


Scenario: a rule can infer a relation
Scenario: when defining a rule using `sub rule`, the rule is successfully created
Given graql define
"""
define
Expand Down
37 changes: 37 additions & 0 deletions behaviour/graql/language/insert.feature
Original file line number Diff line number Diff line change
Expand Up @@ -1427,6 +1427,43 @@ Feature: Graql Insert Query
| MIC | TAR |


Scenario: match-insert can take an attribute's value and copy it to an attribute of a different type
Given graql define
"""
define
height sub attribute, value long;
person has height;
"""
Given graql insert
"""
insert
$x isa person, has name "Susie", has age 16, has ref 0;
$y isa person, has name "Donald", has age 25, has ref 1;
$z isa person, has name "Ralph", has age 18, has ref 2;
"""
Given the integrity is validated
Given graql insert
"""
match
$x isa person, has age 16;
insert
$x has height 16;
"""
Given the integrity is validated
When get answers of graql query
"""
match
$x has height $z;
get $x;
"""
And concept identifiers are
| | check | value |
| SUS | key | ref:0 |
Then uniquely identify answer concepts
| x |
| SUS |


Scenario: if match-insert matches nothing, then nothing is inserted
Given graql define
"""
Expand Down
102 changes: 100 additions & 2 deletions behaviour/graql/language/match.feature
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,75 @@ Feature: Graql Match Clause
| REF0 | REF1 |


Scenario: relations between distinct concepts are not retrieved when matching concepts that relate to themselves
Given graql insert
"""
insert
$x isa person, has ref 1;
$y isa person, has ref 2;
(friend: $x, friend: $y) isa friendship, has ref 0;
"""
Given the integrity is validated
When get answers of graql query
"""
match (friend: $x, friend: $x) isa friendship; get;
"""
Then answer size is: 0


Scenario: matching a chain of relations only returns answers if there is a chain of the required length
Given graql define
"""
define

gift-delivery sub relation,
relates sender,
relates recipient;

person plays sender,
plays recipient;
"""
Given the integrity is validated
Given graql insert
"""
insert
$x1 isa person, has name "Soroush", has ref 0;
$x2a isa person, has name "Martha", has ref 1;
$x2b isa person, has name "Patricia", has ref 2;
$x2c isa person, has name "Lily", has ref 3;

(sender: $x1, recipient: $x2a) isa gift-delivery;
(sender: $x1, recipient: $x2b) isa gift-delivery;
(sender: $x1, recipient: $x2c) isa gift-delivery;
(sender: $x2a, recipient: $x2b) isa gift-delivery;
"""
Given the integrity is validated
When get answers of graql query
"""
match
(sender: $a, recipient: $b) isa gift-delivery;
(sender: $b, recipient: $c) isa gift-delivery;
get;
"""
When concept identifiers are
| | check | value |
| SOR | key | ref:0 |
| MAR | key | ref:1 |
| PAT | key | ref:2 |
Then uniquely identify answer concepts
| a | b | c |
| SOR | MAR | PAT |
When get answers of graql query
"""
match
(sender: $a, recipient: $b) isa gift-delivery;
(sender: $b, recipient: $c) isa gift-delivery;
(sender: $c, recipient: $d) isa gift-delivery;
get;
"""
Then answer size is: 0


Scenario: an error is thrown when matching an entity type as if it were a role
Then graql get throws
"""
Expand Down Expand Up @@ -1308,14 +1377,43 @@ Feature: Graql Match Clause
| PER |


Scenario: value comparison of unbound variables throws an error
@ignore
# TODO: re-enable when variables used in multiple value predicates are resolvable (grakn#5845)
Scenario: an attribute variable used in both `==` and `>=` predicates is correctly resolved
Given graql insert
"""
insert
$x isa person, has name "Susie", has age 16, has ref 0;
$y isa person, has name "Donald", has age 25, has ref 1;
$z isa person, has name "Ralph", has age 18, has ref 2;
"""
Given the integrity is validated
When get answers of graql query
"""
match
$x has age == $z;
$z >= 17;
$z isa age;
get $x;
"""
And concept identifiers are
| | check | value |
| DON | key | ref:1 |
| RAL | key | ref:2 |
Then uniquely identify answer concepts
| x |
| DON |
| RAL |


Scenario: concept comparison of unbound variables throws an error
Then graql get throws
"""
match $x != $y; get;
"""


Scenario: concept comparison of unbound variables throws an error
Scenario: value comparison of unbound variables throws an error
Then graql get throws
"""
match $x !== $y; get;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

Feature: Graql Reasoner Rule Validation
Feature: Graql Rule Validation

Background: Initialise a session and transaction for each scenario
Given connection has been opened
Expand Down
12 changes: 10 additions & 2 deletions behaviour/graql/reasoner/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@
package(default_visibility = ["//visibility:public"])

exports_files([
"resolution.feature",
"rule-validation.feature",
"attribute-attachment.feature",
"concept-inequality.feature",
"negation.feature",
"relation-inference.feature",
"roleplayer-attachment.feature",
"resolution-test-framework.feature",
"type-generation.feature",
"type-hierarchy.feature",
"value-predicate.feature",
"variable-roles.feature",
])
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ Feature: Concept Inequality Resolution
"""
define

person sub entity,
has name;

ball sub entity,
has name,
plays ball1,
Expand Down Expand Up @@ -395,3 +398,128 @@ Feature: Concept Inequality Resolution
# Then all answers are correct in reasoned keyspace
Then answer size in reasoned keyspace is: 36
# Then materialised and reasoned keyspaces are the same size


@ignore
# TODO: re-enable once grakn#5821 is fixed (in some answers, $typeof_ax is 'base-attribute' which is incorrect)
# TODO: re-enable all steps once implicit attribute variables are resolvable
# TODO: migrate to concept-inequality.feature
Scenario: when restricting concept types of a pair of inferred attributes with `!=`, the answers have distinct types
Given for each session, graql define
"""
define
soft-drink sub entity,
has name,
has retailer;
base-attribute sub attribute, value string, abstract;
string-attribute sub base-attribute;
name sub base-attribute;
retailer sub base-attribute;
person has string-attribute;

tesco-sells-all-soft-drinks sub rule,
when {
$x isa soft-drink;
},
then {
$x has retailer 'Tesco';
};
"""
Given for each session, graql insert
"""
insert
$x isa person, has string-attribute "Tesco";
$y isa soft-drink, has name "Tesco";
"""
When materialised keyspace is completed
Then for graql query
"""
match
$x has base-attribute $ax;
$y has base-attribute $ay;
$ax isa! $typeof_ax;
$ay isa! $typeof_ay;
$typeof_ax != $typeof_ay;
get;
"""
Then all answers are correct in reasoned keyspace
# x | ax | y | ay |
# PER | STA | SOF | NAM |
# PER | STA | SOF | RET |
# SOF | NAM | PER | STA |
# SOF | RET | PER | STA |
# SOF | NAM | SOF | STA |
# SOF | STA | SOF | NAM |
Then answer size in reasoned keyspace is: 6
Then materialised and reasoned keyspaces are the same size

@ignore
# TODO: re-enable once grakn#5821 is fixed
# TODO: re-enable all steps once implicit attribute variables are resolvable
# TODO: migrate to concept-inequality.feature
Scenario: inferred attribute matches can be simultaneously restricted by both concept type and attribute value
Given for each session, graql define
"""
define
soft-drink sub entity,
has name,
has retailer;
base-attribute sub attribute, value string, abstract;
string-attribute sub base-attribute;
retailer sub base-attribute;
person has string-attribute;

transfer-string-attribute-to-other-people sub rule,
when {
$x isa person, has string-attribute $r1;
$y isa person;
},
then {
$y has string-attribute $r1;
};

tesco-sells-all-soft-drinks sub rule,
when {
$x isa soft-drink;
},
then {
$x has retailer 'Tesco';
};

if-ocado-exists-it-sells-all-soft-drinks sub rule,
when {
$x isa retailer;
$x == 'Ocado';
$y isa soft-drink;
},
then {
$y has retailer $x;
};
"""
Given for each session, graql insert
"""
insert
$w isa person, has string-attribute "Ocado";
$x isa person, has string-attribute "Tesco";
$y isa soft-drink, has name "Sprite";
$z "Ocado" isa retailer;
"""
When materialised keyspace is completed
Then for graql query
"""
match
$x has base-attribute $value;
$y has base-attribute $unwantedValue;
$value !== $unwantedValue;
$unwantedValue "Ocado";
$value isa! $type;
$unwantedValue isa! $type;
$type != $unwantedType;
$unwantedType type string-attribute;
get $x, $value, $type;
"""
Then all answers are correct in reasoned keyspace
# x | value | type |
# Sprite | Tesco | retailer |
Then answer size in reasoned keyspace is: 1
# Then materialised and reasoned keyspaces are the same size
Loading