Search in sources :

Example 1 with OutIsaFragment

use of ai.grakn.graql.internal.gremlin.fragment.OutIsaFragment in project grakn by graknlabs.

the class QueryPlannerTest method avoidImplicitTypes.

@Test
public void avoidImplicitTypes() {
    Pattern pattern;
    ImmutableList<Fragment> plan;
    pattern = and(x.isa(thingy2), y.isa(thingy4), var().rel(x).rel(y));
    plan = getPlan(pattern);
    assertEquals(3L, plan.stream().filter(LabelFragment.class::isInstance).count());
    String relationship = plan.get(4).start().getValue();
    // should start from relationship
    assertNotEquals(relationship, x.getValue());
    assertNotEquals(relationship, y.getValue());
    pattern = and(x.isa(resourceType), y.isa(thingy4), var().rel(x).rel(y));
    plan = getPlan(pattern);
    assertEquals(3L, plan.stream().filter(LabelFragment.class::isInstance).count());
    relationship = plan.get(4).start().getValue();
    // should start from a role player
    assertTrue(relationship.equals(x.getValue()) || relationship.equals(y.getValue()));
    assertTrue(plan.get(5) instanceof OutIsaFragment);
}
Also used : Pattern(ai.grakn.graql.Pattern) LabelFragment(ai.grakn.graql.internal.gremlin.fragment.LabelFragment) OutIsaFragment(ai.grakn.graql.internal.gremlin.fragment.OutIsaFragment) OutIsaFragment(ai.grakn.graql.internal.gremlin.fragment.OutIsaFragment) NeqFragment(ai.grakn.graql.internal.gremlin.fragment.NeqFragment) LabelFragment(ai.grakn.graql.internal.gremlin.fragment.LabelFragment) InIsaFragment(ai.grakn.graql.internal.gremlin.fragment.InIsaFragment) Fragment(ai.grakn.graql.internal.gremlin.fragment.Fragment) Test(org.junit.Test)

Example 2 with OutIsaFragment

use of ai.grakn.graql.internal.gremlin.fragment.OutIsaFragment in project grakn by graknlabs.

the class QueryPlannerTest method inferRelationshipTypeWhereAVarHasTwoTypes.

@Test
public void inferRelationshipTypeWhereAVarHasTwoTypes() {
    Pattern pattern;
    ImmutableList<Fragment> plan;
    pattern = and(x.isa(thingy), x.isa(thingy1), y.isa(thingy4), var().rel(x).rel(y));
    plan = getPlan(pattern);
    // Relationship type can now be inferred, so one more relationship type label plus existing 3 labels
    assertEquals(4L, plan.stream().filter(LabelFragment.class::isInstance).count());
    assertEquals(4L, plan.stream().filter(fragment -> fragment instanceof OutIsaFragment || fragment instanceof InIsaFragment).count());
    // Should start from the inferred relationship type, instead of role players
    String relationship = plan.get(4).start().getValue();
    assertNotEquals(relationship, x.getValue());
    assertNotEquals(relationship, y.getValue());
}
Also used : InIsaFragment(ai.grakn.graql.internal.gremlin.fragment.InIsaFragment) Pattern(ai.grakn.graql.Pattern) LabelFragment(ai.grakn.graql.internal.gremlin.fragment.LabelFragment) OutIsaFragment(ai.grakn.graql.internal.gremlin.fragment.OutIsaFragment) OutIsaFragment(ai.grakn.graql.internal.gremlin.fragment.OutIsaFragment) NeqFragment(ai.grakn.graql.internal.gremlin.fragment.NeqFragment) LabelFragment(ai.grakn.graql.internal.gremlin.fragment.LabelFragment) InIsaFragment(ai.grakn.graql.internal.gremlin.fragment.InIsaFragment) Fragment(ai.grakn.graql.internal.gremlin.fragment.Fragment) Test(org.junit.Test)

Example 3 with OutIsaFragment

use of ai.grakn.graql.internal.gremlin.fragment.OutIsaFragment in project grakn by graknlabs.

the class QueryPlannerTest method inferRelationshipTypeWithARolePlayerWithNoType.

@Test
public void inferRelationshipTypeWithARolePlayerWithNoType() {
    Pattern pattern;
    ImmutableList<Fragment> plan;
    pattern = and(x.isa(thingy1), y.isa(thingy2), var().rel(x).rel(y).rel(z));
    plan = getPlan(pattern);
    assertEquals(2L, plan.stream().filter(LabelFragment.class::isInstance).count());
    pattern = and(y.isa(thingy2), z.isa(thingy4), var().rel(x).rel(y).rel(z));
    plan = getPlan(pattern);
    // Relationship type can now be inferred, so one more relationship type label
    assertEquals(3L, plan.stream().filter(LabelFragment.class::isInstance).count());
    assertEquals(3L, plan.stream().filter(fragment -> fragment instanceof OutIsaFragment || fragment instanceof InIsaFragment).count());
}
Also used : InIsaFragment(ai.grakn.graql.internal.gremlin.fragment.InIsaFragment) Pattern(ai.grakn.graql.Pattern) LabelFragment(ai.grakn.graql.internal.gremlin.fragment.LabelFragment) OutIsaFragment(ai.grakn.graql.internal.gremlin.fragment.OutIsaFragment) OutIsaFragment(ai.grakn.graql.internal.gremlin.fragment.OutIsaFragment) NeqFragment(ai.grakn.graql.internal.gremlin.fragment.NeqFragment) LabelFragment(ai.grakn.graql.internal.gremlin.fragment.LabelFragment) InIsaFragment(ai.grakn.graql.internal.gremlin.fragment.InIsaFragment) Fragment(ai.grakn.graql.internal.gremlin.fragment.Fragment) Test(org.junit.Test)

Example 4 with OutIsaFragment

use of ai.grakn.graql.internal.gremlin.fragment.OutIsaFragment in project grakn by graknlabs.

the class QueryPlannerTest method inferRelationshipTypeWhereRolePlayedBySuperType.

@Test
public void inferRelationshipTypeWhereRolePlayedBySuperType() {
    Pattern pattern;
    ImmutableList<Fragment> plan;
    pattern = and(x.isa(thingy), y.isa(thingy4), var().rel(x).rel(y));
    plan = getPlan(pattern);
    assertEquals(2L, plan.stream().filter(LabelFragment.class::isInstance).count());
    pattern = and(x.isa(thingy), y.isa(thingy2), z.isa(thingy4), var().rel(x).rel(y).rel(z));
    plan = getPlan(pattern);
    // Relationship type can now be inferred, so one more relationship type label
    assertEquals(4L, plan.stream().filter(LabelFragment.class::isInstance).count());
    assertEquals(4L, plan.stream().filter(fragment -> fragment instanceof OutIsaFragment || fragment instanceof InIsaFragment).count());
}
Also used : InIsaFragment(ai.grakn.graql.internal.gremlin.fragment.InIsaFragment) Pattern(ai.grakn.graql.Pattern) LabelFragment(ai.grakn.graql.internal.gremlin.fragment.LabelFragment) OutIsaFragment(ai.grakn.graql.internal.gremlin.fragment.OutIsaFragment) OutIsaFragment(ai.grakn.graql.internal.gremlin.fragment.OutIsaFragment) NeqFragment(ai.grakn.graql.internal.gremlin.fragment.NeqFragment) LabelFragment(ai.grakn.graql.internal.gremlin.fragment.LabelFragment) InIsaFragment(ai.grakn.graql.internal.gremlin.fragment.InIsaFragment) Fragment(ai.grakn.graql.internal.gremlin.fragment.Fragment) Test(org.junit.Test)

Example 5 with OutIsaFragment

use of ai.grakn.graql.internal.gremlin.fragment.OutIsaFragment in project grakn by graknlabs.

the class QueryPlannerTest method inferRelationshipTypeWhereAVarHasIncorrectTypes.

@Test
public void inferRelationshipTypeWhereAVarHasIncorrectTypes() {
    Pattern pattern;
    ImmutableList<Fragment> plan;
    pattern = and(x.isa(veryRelated), x.isa(thingy2), y.isa(thingy4), var().rel(x).rel(y));
    plan = getPlan(pattern);
    assertEquals(3L, plan.stream().filter(LabelFragment.class::isInstance).count());
    assertEquals(3L, plan.stream().filter(fragment -> fragment instanceof OutIsaFragment || fragment instanceof InIsaFragment).count());
    pattern = and(x.isa(veryRelated), y.isa(thingy4), var().rel(x).rel(y));
    plan = getPlan(pattern);
    assertEquals(2L, plan.stream().filter(LabelFragment.class::isInstance).count());
    assertEquals(2L, plan.stream().filter(fragment -> fragment instanceof OutIsaFragment || fragment instanceof InIsaFragment).count());
}
Also used : InIsaFragment(ai.grakn.graql.internal.gremlin.fragment.InIsaFragment) Pattern(ai.grakn.graql.Pattern) LabelFragment(ai.grakn.graql.internal.gremlin.fragment.LabelFragment) OutIsaFragment(ai.grakn.graql.internal.gremlin.fragment.OutIsaFragment) OutIsaFragment(ai.grakn.graql.internal.gremlin.fragment.OutIsaFragment) NeqFragment(ai.grakn.graql.internal.gremlin.fragment.NeqFragment) LabelFragment(ai.grakn.graql.internal.gremlin.fragment.LabelFragment) InIsaFragment(ai.grakn.graql.internal.gremlin.fragment.InIsaFragment) Fragment(ai.grakn.graql.internal.gremlin.fragment.Fragment) Test(org.junit.Test)

Aggregations

Pattern (ai.grakn.graql.Pattern)7 Fragment (ai.grakn.graql.internal.gremlin.fragment.Fragment)7 InIsaFragment (ai.grakn.graql.internal.gremlin.fragment.InIsaFragment)7 LabelFragment (ai.grakn.graql.internal.gremlin.fragment.LabelFragment)7 NeqFragment (ai.grakn.graql.internal.gremlin.fragment.NeqFragment)7 OutIsaFragment (ai.grakn.graql.internal.gremlin.fragment.OutIsaFragment)7 Test (org.junit.Test)7