use of ai.grakn.graql.Var in project grakn by graknlabs.
the class ExplanationTest method explanationConsistentWithAnswer.
private boolean explanationConsistentWithAnswer(Answer ans) {
ReasonerQuery query = ans.getExplanation().getQuery();
Set<Var> vars = query != null ? query.getVarNames() : new HashSet<>();
return vars.containsAll(ans.map().keySet());
}
use of ai.grakn.graql.Var in project grakn by graknlabs.
the class AtomicTest method roleInference.
private void roleInference(String patternString, ImmutableSetMultimap<Role, Var> expectedRoleMAp, EmbeddedGraknTx<?> graph) {
RelationshipAtom atom = (RelationshipAtom) ReasonerQueries.atomic(conjunction(patternString, graph), graph).getAtom();
Multimap<Role, Var> roleMap = roleSetMap(atom.getRoleVarMap());
assertEquals(expectedRoleMAp, roleMap);
}
use of ai.grakn.graql.Var in project grakn by graknlabs.
the class AtomicTest method testRoleInference_RoleMappingUnambiguous.
// entity1 plays role1, entity2 plays 2 roles, entity3 plays 3 roles hence ambiguous and metarole has to be assigned, EXPECTED TO CHANGE WITH CARDINALITY CONSTRAINTS
@Test
public void testRoleInference_RoleMappingUnambiguous() {
EmbeddedGraknTx<?> graph = ruleApplicabilitySet.tx();
String relationString = "{($x, $y, $z) isa ternary;$x isa singleRoleEntity; $y isa twoRoleEntity; $z isa threeRoleEntity;}";
RelationshipAtom relation = (RelationshipAtom) ReasonerQueries.atomic(conjunction(relationString, graph), graph).getAtom();
ImmutableSetMultimap<Role, Var> roleMap = ImmutableSetMultimap.of(graph.getRole("role1"), var("x"), graph.getRole("role"), var("y"), graph.getRole("role"), var("z"));
assertEquals(roleMap, roleSetMap(relation.getRoleVarMap()));
}
use of ai.grakn.graql.Var in project grakn by graknlabs.
the class ResolutionPlanTest method makeSureConnectednessPreservedWhenRelationsWithSameTypesPresent_longerChain.
@Test
public void makeSureConnectednessPreservedWhenRelationsWithSameTypesPresent_longerChain() {
EmbeddedGraknTx<?> testTx = testContext.tx();
String queryString = "{" + "(role1:$x, role2: $y) isa relation;" + "(role1:$y, role2: $z) isa anotherRelation;" + "(role1:$z, role2: $w) isa yetAnotherRelation;" + "(role1:$w, role2: $u) isa relation;" + "(role1:$u, role2: $v) isa anotherRelation;" + "(role1:$v, role2: $q) isa yetAnotherRelation;" + "}";
ReasonerQueryImpl query = ReasonerQueries.create(conjunction(queryString, testTx), testTx);
ImmutableList<Atom> plan = new ResolutionPlan(query).plan();
UnmodifiableIterator<Atom> iterator = plan.iterator();
Set<Var> vars = new HashSet<>();
vars.addAll(iterator.next().getVarNames());
while (iterator.hasNext()) {
Atom next = iterator.next();
Set<Var> varNames = next.getVarNames();
assertTrue(!Sets.intersection(varNames, vars).isEmpty());
vars.addAll(varNames);
}
}
use of ai.grakn.graql.Var in project grakn by graknlabs.
the class ResolutionPlanTest method makeSureConnectednessPreservedWhenRelationsWithSameTypesPresent.
@Test
public void makeSureConnectednessPreservedWhenRelationsWithSameTypesPresent() {
EmbeddedGraknTx<?> testTx = testContext.tx();
String queryString = "{" + "(role1:$x, role2: $y) isa relation;" + "(role1:$y, role2: $z) isa anotherRelation;" + "(role1:$z, role2: $w) isa relation;" + "(role1:$w, role2: $u) isa anotherRelation;" + "(role1:$u, role2: $v) isa relation;" + "}";
ReasonerQueryImpl query = ReasonerQueries.create(conjunction(queryString, testTx), testTx);
ImmutableList<Atom> plan = new ResolutionPlan(query).plan();
UnmodifiableIterator<Atom> iterator = plan.iterator();
Set<Var> vars = new HashSet<>();
vars.addAll(iterator.next().getVarNames());
while (iterator.hasNext()) {
Atom next = iterator.next();
Set<Var> varNames = next.getVarNames();
assertTrue(!Sets.intersection(varNames, vars).isEmpty());
vars.addAll(varNames);
}
}
Aggregations