Search in sources :

Example 6 with VarPattern

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());
}
Also used : VarPattern(ai.grakn.graql.VarPattern) Pattern(ai.grakn.graql.Pattern) VarPattern(ai.grakn.graql.VarPattern) Property(com.pholser.junit.quickcheck.Property) VarProperty(ai.grakn.graql.admin.VarProperty)

Example 7 with VarPattern

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:#.*].*")));
}
Also used : VarPattern(ai.grakn.graql.VarPattern) Test(org.junit.Test)

Example 8 with VarPattern

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);
}
Also used : IdProperty(ai.grakn.graql.internal.pattern.property.IdProperty) SubProperty(ai.grakn.graql.internal.pattern.property.SubProperty) VarPattern(ai.grakn.graql.VarPattern) Fragment(ai.grakn.graql.internal.gremlin.fragment.Fragment) Test(org.junit.Test)

Example 9 with VarPattern

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}")));
}
Also used : VarPattern(ai.grakn.graql.VarPattern) Test(org.junit.Test)

Example 10 with VarPattern

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"));
}
Also used : VarPattern(ai.grakn.graql.VarPattern) Pattern(ai.grakn.graql.Pattern) VarPattern(ai.grakn.graql.VarPattern) Test(org.junit.Test)

Aggregations

VarPattern (ai.grakn.graql.VarPattern)46 Test (org.junit.Test)28 Var (ai.grakn.graql.Var)12 Pattern (ai.grakn.graql.Pattern)11 Answer (ai.grakn.graql.admin.Answer)9 GraknTx (ai.grakn.GraknTx)8 Role (ai.grakn.concept.Role)8 Label (ai.grakn.concept.Label)7 RelationshipType (ai.grakn.concept.RelationshipType)7 Graql (ai.grakn.graql.Graql)7 Set (java.util.Set)7 ConceptId (ai.grakn.concept.ConceptId)6 EntityType (ai.grakn.concept.EntityType)6 List (java.util.List)6 Collectors.toSet (java.util.stream.Collectors.toSet)6 SchemaConcept (ai.grakn.concept.SchemaConcept)5 GraqlQueryException (ai.grakn.exception.GraqlQueryException)5 QueryBuilder (ai.grakn.graql.QueryBuilder)5 RelationPlayer (ai.grakn.graql.admin.RelationPlayer)5 VarPatternAdmin (ai.grakn.graql.admin.VarPatternAdmin)5