use of ai.grakn.graql.VarPattern in project grakn by graknlabs.
the class DefineQueryTest method assertDefine.
private void assertDefine(VarPattern... vars) {
// Make sure vars don't exist
for (VarPattern var : vars) {
assertNotExists(qb, var);
}
// Define all vars
qb.define(vars).execute();
// Make sure all vars exist
for (VarPattern var : vars) {
assertExists(qb, var);
}
// Undefine all vars
qb.undefine(vars).execute();
// Make sure vars don't exist
for (VarPattern var : vars) {
assertNotExists(qb, var);
}
}
use of ai.grakn.graql.VarPattern in project grakn by graknlabs.
the class ReasoningTests method whenReasoningWithResourcesWithRelationVar_ResultsAreComplete.
@Test
public void whenReasoningWithResourcesWithRelationVar_ResultsAreComplete() {
QueryBuilder qb = testSet14.tx().graql().infer(true);
VarPattern has = var("x").has(Label.of("resource"), var("y"), var("r"));
List<Answer> answers = qb.match(has).get().execute();
assertEquals(answers.size(), 3);
answers.forEach(a -> assertTrue(a.vars().contains(var("r"))));
}
use of ai.grakn.graql.VarPattern in project grakn by graknlabs.
the class RelationshipAtom method rewriteWithRelationVariable.
@Override
public RelationshipAtom rewriteWithRelationVariable() {
VarPattern newVar = Graql.var().asUserDefined();
VarPattern relVar = getPattern().admin().getProperty(IsaProperty.class).map(prop -> newVar.isa(prop.type())).orElse(newVar);
for (RelationPlayer c : getRelationPlayers()) {
VarPatternAdmin roleType = c.getRole().orElse(null);
if (roleType != null) {
relVar = relVar.rel(roleType, c.getRolePlayer());
} else {
relVar = relVar.rel(c.getRolePlayer());
}
}
return create(relVar.admin(), getPredicateVariable(), getTypeId(), getParentQuery());
}
use of ai.grakn.graql.VarPattern in project grakn by graknlabs.
the class InsertQueryTest method testMatchInsertQuery.
@Test
public void testMatchInsertQuery() {
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);
qb.match(var("x").isa("language")).insert(var("x").has("name", "HELLO")).execute();
assertExists(qb, var().isa("language").has("name", "123").has("name", "HELLO"));
assertExists(qb, var().isa("language").has("name", "456").has("name", "HELLO"));
qb.match(var("x").isa("language")).delete("x").execute();
assertNotExists(qb, language1);
assertNotExists(qb, language2);
}
use of ai.grakn.graql.VarPattern in project grakn by graknlabs.
the class InsertQueryTest method whenInsertingAResourceWithMultipleValues_Throw.
@Test
public void whenInsertingAResourceWithMultipleValues_Throw() {
VarPattern varPattern = var().val("123").val("456").isa("title");
exception.expect(GraqlQueryException.class);
exception.expectMessage(isOneOf(GraqlQueryException.insertMultipleProperties(varPattern, "val", "123", "456").getMessage(), GraqlQueryException.insertMultipleProperties(varPattern, "val", "456", "123").getMessage()));
qb.insert(varPattern).execute();
}
Aggregations