Search in sources :

Example 1 with ResolutionPlan

use of ai.grakn.graql.internal.reasoner.plan.ResolutionPlan in project grakn by graknlabs.

the class ResolutionPlanTest method prioritiseSubbedRelationsOverNonSubbedOnes.

@Test
public void prioritiseSubbedRelationsOverNonSubbedOnes() {
    EmbeddedGraknTx<?> testTx = testContext.tx();
    String queryString = "{" + "(role1:$x, role2: $y) isa relation;" + "(role1:$y, role2: $z) isa anotherRelation;" + "(role1:$z, role2: $w) isa yetAnotherRelation;" + "$w id 'sampleId';" + "}";
    ReasonerQueryImpl query = ReasonerQueries.create(conjunction(queryString, testTx), testTx);
    ImmutableList<Atom> correctPlan = ImmutableList.of(getAtom(query, "yetAnotherRelation", testTx), getAtom(query, "anotherRelation", testTx), getAtom(query, "relation", testTx));
    ImmutableList<Atom> plan = new ResolutionPlan(query).plan();
    assertEquals(plan, correctPlan);
}
Also used : Atom(ai.grakn.graql.internal.reasoner.atom.Atom) ReasonerQueryImpl(ai.grakn.graql.internal.reasoner.query.ReasonerQueryImpl) ResolutionPlan(ai.grakn.graql.internal.reasoner.plan.ResolutionPlan) Test(org.junit.Test)

Example 2 with ResolutionPlan

use of ai.grakn.graql.internal.reasoner.plan.ResolutionPlan in project grakn by graknlabs.

the class ResolutionPlanTest method prioritiseSpecificResourcesOverNonSpecific.

@Test
public void prioritiseSpecificResourcesOverNonSpecific() {
    EmbeddedGraknTx<?> testTx = testContext.tx();
    String queryString = "{" + "(role1:$x, role2: $y) isa relation;" + "(role1:$y, role2: $z) isa anotherRelation;" + "(role1:$z, role2: $w) isa yetAnotherRelation;" + "$x has anotherResource $r;" + "$w has resource 'test';" + "}";
    ReasonerQueryImpl query = ReasonerQueries.create(conjunction(queryString, testTx), testTx);
    ImmutableList<Atom> correctPlan = ImmutableList.of(getAtom(query, "resource", testTx), getAtom(query, "yetAnotherRelation", testTx), getAtom(query, "anotherRelation", testTx), getAtom(query, "relation", testTx), getAtom(query, "anotherResource", testTx));
    ImmutableList<Atom> plan = new ResolutionPlan(query).plan();
    assertEquals(plan, correctPlan);
}
Also used : Atom(ai.grakn.graql.internal.reasoner.atom.Atom) ReasonerQueryImpl(ai.grakn.graql.internal.reasoner.query.ReasonerQueryImpl) ResolutionPlan(ai.grakn.graql.internal.reasoner.plan.ResolutionPlan) Test(org.junit.Test)

Example 3 with ResolutionPlan

use of ai.grakn.graql.internal.reasoner.plan.ResolutionPlan in project grakn by graknlabs.

the class ResolutionPlanTest method makeSureOptimalOrderPickedWhenResourcesWithSubstitutionsArePresent.

@Test
public void makeSureOptimalOrderPickedWhenResourcesWithSubstitutionsArePresent() {
    EmbeddedGraknTx<?> testTx = testContext.tx();
    Concept concept = testTx.graql().match(var("x").isa("baseEntity")).get("x").findAny().orElse(null);
    String basePatternString = "(role1:$x, role2: $y) isa relation;" + "$x has resource 'this';" + "$y has anotherResource 'that';";
    String xPatternString = "{" + "$x id '" + concept.getId() + "';" + basePatternString + "}";
    String yPatternString = "{" + "$y id '" + concept.getId() + "';" + basePatternString + "}";
    ReasonerQueryImpl queryX = ReasonerQueries.create(conjunction(xPatternString, testTx), testTx);
    ReasonerQueryImpl queryY = ReasonerQueries.create(conjunction(yPatternString, testTx), testTx);
    assertNotEquals(new ResolutionPlan(queryX).plan().get(0), getAtom(queryX, "anotherResource", testTx));
    assertNotEquals(new ResolutionPlan(queryY).plan().get(0), getAtom(queryX, "resource", testTx));
}
Also used : Concept(ai.grakn.concept.Concept) ReasonerQueryImpl(ai.grakn.graql.internal.reasoner.query.ReasonerQueryImpl) ResolutionPlan(ai.grakn.graql.internal.reasoner.plan.ResolutionPlan) Test(org.junit.Test)

Example 4 with ResolutionPlan

use of ai.grakn.graql.internal.reasoner.plan.ResolutionPlan in project grakn by graknlabs.

the class ResolutionPlanTest method prioritiseMostSubbedRelations.

@Test
public void prioritiseMostSubbedRelations() {
    EmbeddedGraknTx<?> testTx = testContext.tx();
    String queryString = "{" + "(role1:$x, role2: $y) isa relation;" + "(role1:$y, role2: $z) isa anotherRelation;" + "(role1:$z, role2: $w) isa yetAnotherRelation;" + "$z id 'sampleId';" + "$w id 'sampleId2';" + "}";
    ReasonerQueryImpl query = ReasonerQueries.create(conjunction(queryString, testTx), testTx);
    ImmutableList<Atom> correctPlan = ImmutableList.of(getAtom(query, "yetAnotherRelation", testTx), getAtom(query, "anotherRelation", testTx), getAtom(query, "relation", testTx));
    ImmutableList<Atom> plan = new ResolutionPlan(query).plan();
    assertEquals(plan, correctPlan);
}
Also used : Atom(ai.grakn.graql.internal.reasoner.atom.Atom) ReasonerQueryImpl(ai.grakn.graql.internal.reasoner.query.ReasonerQueryImpl) ResolutionPlan(ai.grakn.graql.internal.reasoner.plan.ResolutionPlan) Test(org.junit.Test)

Example 5 with ResolutionPlan

use of ai.grakn.graql.internal.reasoner.plan.ResolutionPlan in project grakn by graknlabs.

the class ResolutionPlanTest method prioritiseSpecificResourcesOverRelations.

@Test
public void prioritiseSpecificResourcesOverRelations() {
    EmbeddedGraknTx<?> testTx = testContext.tx();
    String queryString = "{" + "(role1:$x, role2: $y) isa relation;" + "(role1:$y, role2: $z) isa anotherRelation;" + "(role1:$z, role2: $w) isa yetAnotherRelation;" + "$w has resource 'test';" + "}";
    ReasonerQueryImpl query = ReasonerQueries.create(conjunction(queryString, testTx), testTx);
    ImmutableList<Atom> correctPlan = ImmutableList.of(getAtom(query, "resource", testTx), getAtom(query, "yetAnotherRelation", testTx), getAtom(query, "anotherRelation", testTx), getAtom(query, "relation", testTx));
    ImmutableList<Atom> plan = new ResolutionPlan(query).plan();
    assertEquals(plan, correctPlan);
}
Also used : Atom(ai.grakn.graql.internal.reasoner.atom.Atom) ReasonerQueryImpl(ai.grakn.graql.internal.reasoner.query.ReasonerQueryImpl) ResolutionPlan(ai.grakn.graql.internal.reasoner.plan.ResolutionPlan) Test(org.junit.Test)

Aggregations

ResolutionPlan (ai.grakn.graql.internal.reasoner.plan.ResolutionPlan)8 Atom (ai.grakn.graql.internal.reasoner.atom.Atom)7 ReasonerQueryImpl (ai.grakn.graql.internal.reasoner.query.ReasonerQueryImpl)7 Test (org.junit.Test)7 Var (ai.grakn.graql.Var)3 HashSet (java.util.HashSet)3 Concept (ai.grakn.concept.Concept)2 ConceptId (ai.grakn.concept.ConceptId)1 Type (ai.grakn.concept.Type)1 GraqlQueryException (ai.grakn.exception.GraqlQueryException)1 GetQuery (ai.grakn.graql.GetQuery)1 Graql.var (ai.grakn.graql.Graql.var)1 Answer (ai.grakn.graql.admin.Answer)1 Atomic (ai.grakn.graql.admin.Atomic)1 Conjunction (ai.grakn.graql.admin.Conjunction)1 MultiUnifier (ai.grakn.graql.admin.MultiUnifier)1 PatternAdmin (ai.grakn.graql.admin.PatternAdmin)1 ReasonerQuery (ai.grakn.graql.admin.ReasonerQuery)1 Unifier (ai.grakn.graql.admin.Unifier)1 UnifierComparison (ai.grakn.graql.admin.UnifierComparison)1