use of ai.grakn.graql.VarPattern in project grakn by graknlabs.
the class DefineQueryTest method whenDefiningANonRuleWithAWhenPattern_Throw.
@Test
public void whenDefiningANonRuleWithAWhenPattern_Throw() {
VarPattern rule = label("yes").sub(label(ENTITY.getLabel())).when(var("x"));
exception.expect(GraqlQueryException.class);
exception.expectMessage(anyOf(// Either we see "entity" and an unexpected "when"...
allOf(containsString("unexpected property"), containsString("when")), // ...or we see "when" and don't find the expected "then"
containsString(GraqlQueryException.insertNoExpectedProperty("then", rule.admin()).getMessage())));
qb.define(rule).execute();
}
use of ai.grakn.graql.VarPattern in project grakn by graknlabs.
the class UndefineQueryTest method whenUndefiningComplexSchema_TheEntireSchemaIsRemoved.
@Test
public void whenUndefiningComplexSchema_TheEntireSchemaIsRemoved() {
Collection<VarPattern> schema = ImmutableList.of(label("pokemon").sub(ENTITY).has("pokedex-no").plays("ancestor").plays("descendant"), label("pokedex-no").sub(ATTRIBUTE).datatype(INTEGER), label("evolution").sub(RELATIONSHIP).relates("ancestor").relates("descendant"), label("ancestor").sub(ROLE), label("descendant").sub(ROLE));
qb.define(schema).execute();
EntityType pokemon = tx.getEntityType("pokemon");
RelationshipType evolution = tx.getRelationshipType("evolution");
AttributeType<Long> pokedexNo = tx.getAttributeType("pokedex-no");
Role ancestor = tx.getRole("ancestor");
Role descendant = tx.getRole("descendant");
assertThat(pokemon.attributes().toArray(), arrayContaining(pokedexNo));
assertThat(evolution.relates().toArray(), arrayContainingInAnyOrder(ancestor, descendant));
assertThat(pokemon.plays().filter(r -> !r.isImplicit()).toArray(), arrayContainingInAnyOrder(ancestor, descendant));
qb.undefine(schema).execute();
assertNull(tx.getEntityType("pokemon"));
assertNull(tx.getEntityType("evolution"));
assertNull(tx.getAttributeType("pokedex-no"));
assertNull(tx.getRole("ancestor"));
assertNull(tx.getRole("descendant"));
}
use of ai.grakn.graql.VarPattern in project grakn by graknlabs.
the class InsertQueryTest method testInsertRepeat.
@Test
public void testInsertRepeat() {
VarPattern language = var("x").has("name", "123").isa("language");
InsertQuery query = qb.insert(language);
assertEquals(0, qb.match(language).stream().count());
query.execute();
assertEquals(1, qb.match(language).stream().count());
query.execute();
assertEquals(2, qb.match(language).stream().count());
query.execute();
assertEquals(3, qb.match(language).stream().count());
qb.match(language).delete("x").execute();
assertEquals(0, qb.match(language).stream().count());
}
use of ai.grakn.graql.VarPattern 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.VarPattern 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"));
}
Aggregations