Search in sources :

Example 56 with Var

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());
}
Also used : Var(ai.grakn.graql.Var) ReasonerQuery(ai.grakn.graql.admin.ReasonerQuery)

Example 57 with Var

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);
}
Also used : Role(ai.grakn.concept.Role) Var(ai.grakn.graql.Var) RelationshipAtom(ai.grakn.graql.internal.reasoner.atom.binary.RelationshipAtom)

Example 58 with Var

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()));
}
Also used : Role(ai.grakn.concept.Role) Var(ai.grakn.graql.Var) RelationshipAtom(ai.grakn.graql.internal.reasoner.atom.binary.RelationshipAtom) Test(org.junit.Test)

Example 59 with Var

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);
    }
}
Also used : Var(ai.grakn.graql.Var) Atom(ai.grakn.graql.internal.reasoner.atom.Atom) ReasonerQueryImpl(ai.grakn.graql.internal.reasoner.query.ReasonerQueryImpl) ResolutionPlan(ai.grakn.graql.internal.reasoner.plan.ResolutionPlan) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 60 with Var

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);
    }
}
Also used : Var(ai.grakn.graql.Var) Atom(ai.grakn.graql.internal.reasoner.atom.Atom) ReasonerQueryImpl(ai.grakn.graql.internal.reasoner.query.ReasonerQueryImpl) ResolutionPlan(ai.grakn.graql.internal.reasoner.plan.ResolutionPlan) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Var (ai.grakn.graql.Var)100 Test (org.junit.Test)29 Answer (ai.grakn.graql.admin.Answer)28 ConceptId (ai.grakn.concept.ConceptId)26 Concept (ai.grakn.concept.Concept)25 Role (ai.grakn.concept.Role)25 VarPatternAdmin (ai.grakn.graql.admin.VarPatternAdmin)24 HashSet (java.util.HashSet)24 Set (java.util.Set)24 VarPattern (ai.grakn.graql.VarPattern)21 IdPredicate (ai.grakn.graql.internal.reasoner.atom.predicate.IdPredicate)21 Sets (com.google.common.collect.Sets)20 Map (java.util.Map)20 Stream (java.util.stream.Stream)20 GraqlQueryException (ai.grakn.exception.GraqlQueryException)19 ImmutableSet (com.google.common.collect.ImmutableSet)19 HashMap (java.util.HashMap)19 QueryAnswer (ai.grakn.graql.internal.query.QueryAnswer)18 List (java.util.List)18 SchemaConcept (ai.grakn.concept.SchemaConcept)17