use of ai.grakn.graql.Pattern in project grakn by graknlabs.
the class QueryPlannerTest method inferRelationshipTypeWithMoreThan2Roles.
@Test
public void inferRelationshipTypeWithMoreThan2Roles() {
Pattern pattern;
ImmutableList<Fragment> plan;
pattern = and(x.isa(thingy1), y.isa(thingy2), z.isa(thingy3), var().rel(x).rel(y).rel(z));
plan = getPlan(pattern);
assertEquals(3L, plan.stream().filter(LabelFragment.class::isInstance).count());
pattern = and(x.isa(thingy1), y.isa(thingy2), z.isa(thingy4), var().rel(x).rel(y).rel(z));
plan = getPlan(pattern);
// Relationship type can now be inferred, so one more relationship type label
assertEquals(4L, plan.stream().filter(LabelFragment.class::isInstance).count());
assertEquals(4L, plan.stream().filter(fragment -> fragment instanceof OutIsaFragment || fragment instanceof InIsaFragment).count());
}
use of ai.grakn.graql.Pattern in project grakn by graknlabs.
the class InsertQueryTest method testInsertRelation.
@Test
public void testInsertRelation() {
VarPattern rel = var("r").isa("has-genre").rel("genre-of-production", "x").rel("production-with-genre", "y");
VarPattern x = var("x").has("title", "Godfather").isa("movie");
VarPattern y = var("y").has("name", "comedy").isa("genre");
VarPattern[] vars = new VarPattern[] { rel, x, y };
Pattern[] patterns = new Pattern[] { rel, x, y };
assertNotExists(qb.match(patterns));
qb.insert(vars).execute();
assertExists(qb, patterns);
qb.match(patterns).delete("r").execute();
assertNotExists(qb, patterns);
}
use of ai.grakn.graql.Pattern in project grakn by graknlabs.
the class DefineQueryTest method whenDefiningARule_TheRuleIsInTheKB.
@Test
public void whenDefiningARule_TheRuleIsInTheKB() {
Pattern when = qb.parser().parsePattern("$x isa entity");
Pattern then = qb.parser().parsePattern("$x isa entity");
VarPattern vars = label("my-rule").sub(label(RULE.getLabel())).when(when).then(then);
qb.define(vars).execute();
assertNotNull(movies.tx().getRule("my-rule"));
}
use of ai.grakn.graql.Pattern in project grakn by graknlabs.
the class GeoKB method buildRules.
@Override
public void buildRules(GraknTx tx) {
Pattern transitivity_LHS = tx.graql().parser().parsePattern("{(geo-entity: $x, entity-location: $y) isa is-located-in;" + "(geo-entity: $y, entity-location: $z) isa is-located-in;}");
Pattern transitivity_RHS = tx.graql().parser().parsePattern("{(geo-entity: $x, entity-location: $z) isa is-located-in;}");
tx.putRule("Geo Rule", transitivity_LHS, transitivity_RHS);
}
use of ai.grakn.graql.Pattern in project grakn by graknlabs.
the class MovieKB method buildRules.
@Override
protected void buildRules(GraknTx tx) {
// These rules are totally made up for testing purposes and don't work!
Pattern when = tx.graql().parser().parsePattern("$x has name 'expectation-when'");
Pattern then = tx.graql().parser().parsePattern("$x has name 'expectation-then'");
tx.putRule("expectation-rule", when, then);
when = tx.graql().parser().parsePattern("$x has name 'materialize-when'");
then = tx.graql().parser().parsePattern("$x has name 'materialize-then'");
tx.putRule("materialize-rule", when, then);
}
Aggregations