Search in sources :

Example 1 with EquivalentFragmentSet

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

the class RelatesProperty method match.

@Override
public Collection<EquivalentFragmentSet> match(Var start) {
    VarPatternAdmin superRole = superRole();
    EquivalentFragmentSet relates = relates(this, start, role().var());
    if (superRole == null) {
        return ImmutableSet.of(relates);
    } else {
        return ImmutableSet.of(relates, sub(this, role().var(), superRole.var()));
    }
}
Also used : VarPatternAdmin(ai.grakn.graql.admin.VarPatternAdmin) EquivalentFragmentSet(ai.grakn.graql.internal.gremlin.EquivalentFragmentSet)

Example 2 with EquivalentFragmentSet

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

the class RolePlayerFragmentSetTest method whenRelationTypeIsNotInGraph_DoNotApplyRelationTypeOptimisation.

@Test
public void whenRelationTypeIsNotInGraph_DoNotApplyRelationTypeOptimisation() {
    Label magician = Label.of("magician");
    Collection<EquivalentFragmentSet> fragmentSets = Sets.newHashSet(EquivalentFragmentSets.rolePlayer(null, a, b, c, null), EquivalentFragmentSets.isa(null, a, d, true), EquivalentFragmentSets.label(null, d, ImmutableSet.of(magician)));
    Collection<EquivalentFragmentSet> expected = Sets.newHashSet(fragmentSets);
    RolePlayerFragmentSet.RELATION_TYPE_OPTIMISATION.apply(fragmentSets, sampleKB.tx());
    assertEquals(expected, fragmentSets);
}
Also used : Label(ai.grakn.concept.Label) EquivalentFragmentSet(ai.grakn.graql.internal.gremlin.EquivalentFragmentSet) Test(org.junit.Test)

Example 3 with EquivalentFragmentSet

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

the class RolePlayerFragmentSetTest method whenApplyingRoleOptimisation_ExpandRoleToAllSubs.

@Test
public void whenApplyingRoleOptimisation_ExpandRoleToAllSubs() {
    Label author = Label.of("author");
    Label director = Label.of("director");
    EquivalentFragmentSet authorLabelFragmentSet = EquivalentFragmentSets.label(null, d, ImmutableSet.of(author));
    Collection<EquivalentFragmentSet> fragmentSets = Sets.newHashSet(EquivalentFragmentSets.rolePlayer(null, a, b, c, d), authorLabelFragmentSet);
    RolePlayerFragmentSet.ROLE_OPTIMISATION.apply(fragmentSets, sampleKB.tx());
    HashSet<EquivalentFragmentSet> expected = Sets.newHashSet(RolePlayerFragmentSet.of(null, a, b, c, null, ImmutableSet.of(author, director), null), authorLabelFragmentSet);
    assertEquals(expected, fragmentSets);
}
Also used : Label(ai.grakn.concept.Label) EquivalentFragmentSet(ai.grakn.graql.internal.gremlin.EquivalentFragmentSet) Test(org.junit.Test)

Example 4 with EquivalentFragmentSet

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

the class RolePlayerFragmentSetTest method whenApplyingRoleOptimisationToMetaRole_DoNotExpandRoleToAllSubs.

@Test
public void whenApplyingRoleOptimisationToMetaRole_DoNotExpandRoleToAllSubs() {
    Label role = Label.of("role");
    EquivalentFragmentSet authorLabelFragmentSet = EquivalentFragmentSets.label(null, d, ImmutableSet.of(role));
    Collection<EquivalentFragmentSet> fragmentSets = Sets.newHashSet(EquivalentFragmentSets.rolePlayer(null, a, b, c, d), authorLabelFragmentSet);
    RolePlayerFragmentSet.ROLE_OPTIMISATION.apply(fragmentSets, sampleKB.tx());
    HashSet<EquivalentFragmentSet> expected = Sets.newHashSet(RolePlayerFragmentSet.of(null, a, b, c, null, null, null), authorLabelFragmentSet);
    assertEquals(expected, fragmentSets);
}
Also used : Label(ai.grakn.concept.Label) EquivalentFragmentSet(ai.grakn.graql.internal.gremlin.EquivalentFragmentSet) Test(org.junit.Test)

Example 5 with EquivalentFragmentSet

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

the class RolePlayerFragmentSetTest method whenLabelDoesNotReferToARole_DoNotApplyRoleOptimisation.

@Test
public void whenLabelDoesNotReferToARole_DoNotApplyRoleOptimisation() {
    Label movie = Label.of("movie");
    Collection<EquivalentFragmentSet> fragmentSets = Sets.newHashSet(EquivalentFragmentSets.rolePlayer(null, a, b, c, d), EquivalentFragmentSets.label(null, d, ImmutableSet.of(movie)));
    Collection<EquivalentFragmentSet> expected = Sets.newHashSet(fragmentSets);
    RolePlayerFragmentSet.ROLE_OPTIMISATION.apply(fragmentSets, sampleKB.tx());
    assertEquals(expected, fragmentSets);
}
Also used : Label(ai.grakn.concept.Label) EquivalentFragmentSet(ai.grakn.graql.internal.gremlin.EquivalentFragmentSet) Test(org.junit.Test)

Aggregations

EquivalentFragmentSet (ai.grakn.graql.internal.gremlin.EquivalentFragmentSet)8 Test (org.junit.Test)7 Label (ai.grakn.concept.Label)6 VarPatternAdmin (ai.grakn.graql.admin.VarPatternAdmin)1