use of ai.grakn.graql.VarPattern in project grakn by graknlabs.
the class InsertQueryTest method testIterateMatchInsertResults.
@Test
public void testIterateMatchInsertResults() {
VarPattern language1 = var().isa("language").has("name", "123");
VarPattern language2 = var().isa("language").has("name", "456");
qb.insert(language1, language2).execute();
assertExists(qb, language1);
assertExists(qb, language2);
InsertQuery query = qb.match(var("x").isa("language")).insert(var("x").has("name", "HELLO"));
Iterator<Answer> results = query.iterator();
assertNotExists(qb, var().isa("language").has("name", "123").has("name", "HELLO"));
assertNotExists(qb, var().isa("language").has("name", "456").has("name", "HELLO"));
Answer result1 = results.next();
assertEquals(ImmutableSet.of(var("x")), result1.vars());
boolean query123 = qb.match(var().isa("language").has("name", "123").has("name", "HELLO")).iterator().hasNext();
boolean query456 = qb.match(var().isa("language").has("name", "456").has("name", "HELLO")).iterator().hasNext();
// Check if one of the matches have had the insert executed correctly
boolean oneExists = query123 != query456;
assertTrue("A match insert was not executed correctly for only one match", oneExists);
// Check that both are inserted correctly
Answer result2 = results.next();
assertEquals(ImmutableSet.of(var("x")), result1.vars());
assertExists(qb, var().isa("language").has("name", "123").has("name", "HELLO"));
assertExists(qb, var().isa("language").has("name", "456").has("name", "HELLO"));
assertFalse(results.hasNext());
assertNotEquals(result1.get("x"), result2.get("x"));
}
use of ai.grakn.graql.VarPattern in project grakn by graknlabs.
the class InsertQueryTest method whenSettingTwoTypes_Throw.
@Test
public void whenSettingTwoTypes_Throw() {
EntityType movie = movieKB.tx().getEntityType("movie");
EntityType person = movieKB.tx().getEntityType("person");
// We have to construct it this way because you can't have two `isa`s normally
// TODO: less bad way?
VarPattern varPattern = Patterns.varPattern(var("x"), ImmutableSet.of(IsaProperty.of(label("movie").admin()), IsaProperty.of(label("person").admin())));
// We don't know in what order the message will be
exception.expect(GraqlQueryException.class);
exception.expectMessage(isOneOf(GraqlQueryException.insertMultipleProperties(varPattern, "isa", movie, person).getMessage(), GraqlQueryException.insertMultipleProperties(varPattern, "isa", person, movie).getMessage()));
movieKB.tx().graql().insert(var("x").isa("movie"), var("x").isa("person")).execute();
}
use of ai.grakn.graql.VarPattern in project grakn by graknlabs.
the class PatternPropertyTests method theConjunctionOfTwoPatterns_ShouldBeContainedInTheResultingPattern.
@Property
public void theConjunctionOfTwoPatterns_ShouldBeContainedInTheResultingPattern(Pattern pattern1, Pattern pattern2) {
Set<VarPattern> union = Sets.union(pattern1.admin().varPatterns(), pattern2.admin().varPatterns());
Pattern conjunction = pattern1.and(pattern2);
assertEquals(union, conjunction.admin().varPatterns());
}
use of ai.grakn.graql.VarPattern in project grakn by graknlabs.
the class GraqlTraversalTest method whenPlanningSimpleBinaryRelationQuery_ApplyRolePlayerOptimisation.
@Test
public void whenPlanningSimpleBinaryRelationQuery_ApplyRolePlayerOptimisation() {
VarPattern rel = var("x").rel("y").rel("z");
GraqlTraversal graqlTraversal = semiOptimal(rel);
assertThat(graqlTraversal, anyOf(matches("\\{§x-\\[" + ROLE_PLAYER_EDGE + ":#.*]->§.* §x-\\[" + ROLE_PLAYER_EDGE + ":#.*]->§.* #.*\\[neq:#.*]}"), matches("\\{§.*<-\\[" + ROLE_PLAYER_EDGE + ":#.*]-§x-\\[" + ROLE_PLAYER_EDGE + ":#.*]->§.* #.*\\[neq:#.*]}")));
}
use of ai.grakn.graql.VarPattern in project grakn by graknlabs.
the class GraqlTraversalTest method whenPlanningBinaryRelationQueryWithType_ApplyRolePlayerOptimisation.
@Test
public void whenPlanningBinaryRelationQueryWithType_ApplyRolePlayerOptimisation() {
VarPattern rel = var("x").rel("y").rel("z").isa("marriage");
GraqlTraversal graqlTraversal = semiOptimal(rel);
assertThat(graqlTraversal, anyOf(matches(".*§x-\\[" + ROLE_PLAYER_EDGE + ":#.* rels:marriage]->§.* §x-\\[" + ROLE_PLAYER_EDGE + ":#.* rels:marriage]->§.* #.*\\[neq:#.*].*"), matches(".*§.*<-\\[" + ROLE_PLAYER_EDGE + ":#.* rels:marriage]-§x-\\[" + ROLE_PLAYER_EDGE + ":#.* rels:marriage]->§.* #.*\\[neq:#.*].*")));
}
Aggregations