use of ai.grakn.graql.VarPattern in project grakn by graknlabs.
the class PatternPropertyTests method theDisjunctionOfTwoPatterns_ShouldBeContainedInTheResultingPattern.
@Property
public void theDisjunctionOfTwoPatterns_ShouldBeContainedInTheResultingPattern(Pattern pattern1, Pattern pattern2) {
Set<VarPattern> union = Sets.union(pattern1.admin().varPatterns(), pattern2.admin().varPatterns());
Pattern disjunction = pattern1.or(pattern2);
assertEquals(union, disjunction.admin().varPatterns());
}
use of ai.grakn.graql.VarPattern in project grakn by graknlabs.
the class GraqlTraversalTest method testRolePlayerOptimisationWithRoles.
@Test
public void testRolePlayerOptimisationWithRoles() {
VarPattern rel = var("x").rel("y").rel("wife", "z");
GraqlTraversal graqlTraversal = semiOptimal(rel);
assertThat(graqlTraversal, anyOf(matches(".*§x-\\[" + ROLE_PLAYER_EDGE + ":#.* roles:wife]->§.* §x-\\[" + ROLE_PLAYER_EDGE + ":#.*]->§.* #.*\\[neq:#.*].*"), matches(".*§.*<-\\[" + ROLE_PLAYER_EDGE + ":#.* roles:wife]-§x-\\[" + ROLE_PLAYER_EDGE + ":#.*]->§.* #.*\\[neq:#.*].*")));
}
use of ai.grakn.graql.VarPattern in project grakn by graknlabs.
the class GraqlTraversalTest method testAllTraversalsSimpleQuery.
@Test
public void testAllTraversalsSimpleQuery() {
IdProperty titanicId = IdProperty.of(ConceptId.of("Titanic"));
IdProperty movieId = IdProperty.of(ConceptId.of("movie"));
SubProperty subProperty = SubProperty.of(Patterns.varPattern(y, ImmutableSet.of(movieId)));
VarPattern pattern = Patterns.varPattern(x, ImmutableSet.of(titanicId, subProperty));
Set<GraqlTraversal> traversals = allGraqlTraversals(pattern).collect(toSet());
assertEquals(12, traversals.size());
Fragment xId = id(titanicId, x, ConceptId.of("Titanic"));
Fragment yId = id(movieId, y, ConceptId.of("movie"));
Fragment xSubY = outSub(subProperty, x, y);
Fragment ySubX = inSub(subProperty, y, x);
Set<GraqlTraversal> expected = ImmutableSet.of(traversal(xId, xSubY, yId), traversal(xId, ySubX, yId), traversal(xId, yId, xSubY), traversal(xId, yId, ySubX), traversal(xSubY, xId, yId), traversal(xSubY, yId, xId), traversal(ySubX, xId, yId), traversal(ySubX, yId, xId), traversal(yId, xId, xSubY), traversal(yId, xId, ySubX), traversal(yId, xSubY, xId), traversal(yId, ySubX, xId));
assertEquals(expected, traversals);
}
use of ai.grakn.graql.VarPattern in project grakn by graknlabs.
the class GraqlTraversalTest method whenPlanningSimpleUnaryRelation_ApplyRolePlayerOptimisation.
@Test
public void whenPlanningSimpleUnaryRelation_ApplyRolePlayerOptimisation() {
VarPattern rel = var("x").rel("y");
GraqlTraversal graqlTraversal = semiOptimal(rel);
// I know this is horrible, unfortunately I can't think of a better way...
// The issue is that some things we want to inspect are not public, mainly:
// 1. The variable name assigned to the casting
// 2. The role-player fragment classes
// Both of these things should not be made public if possible, so I see this regex as the lesser evil
assertThat(graqlTraversal, anyOf(matches("\\{§x-\\[" + ROLE_PLAYER_EDGE + ":#.*]->§y}"), matches("\\{§y<-\\[" + ROLE_PLAYER_EDGE + ":#.*]-§x}")));
}
use of ai.grakn.graql.VarPattern in project grakn by graknlabs.
the class DefineQueryTest method whenDefiningARule_SubRuleDeclarationsCanBeSkipped.
@Test
public void whenDefiningARule_SubRuleDeclarationsCanBeSkipped() {
Pattern when = qb.parser().parsePattern("$x isa entity");
Pattern then = qb.parser().parsePattern("$x isa entity");
VarPattern vars = label("my-rule").when(when).then(then);
qb.define(vars).execute();
assertNotNull(movies.tx().getRule("my-rule"));
}
Aggregations