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()));
}
}
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);
}
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);
}
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);
}
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);
}
Aggregations