use of ai.grakn.graql.VarPattern in project grakn by graknlabs.
the class RelationshipConverter method pattern.
public Pattern pattern(Relationship concept) {
VarPattern relationPattern = Graql.var();
Set<Pattern> idPatterns = new HashSet<>();
for (Map.Entry<Role, Set<Thing>> entry : concept.allRolePlayers().entrySet()) {
for (Thing var : entry.getValue()) {
Var rolePlayer = Graql.var();
relationPattern = relationPattern.rel(Graql.label(entry.getKey().getLabel()), rolePlayer);
idPatterns.add(rolePlayer.asUserDefined().id(var.getId()));
}
}
relationPattern = relationPattern.isa(Graql.label(concept.type().getLabel()));
Pattern pattern = relationPattern;
for (Pattern idPattern : idPatterns) {
pattern = pattern.and(idPattern);
}
return pattern;
}
use of ai.grakn.graql.VarPattern in project grakn by graknlabs.
the class PatternTest method whenConjunctionPassedVarAndNull_Throw.
@Test(expected = Exception.class)
public void whenConjunctionPassedVarAndNull_Throw() {
VarPattern var = null;
// noinspection ResultOfMethodCallIgnored,ConstantConditions
and(var(), var);
}
use of ai.grakn.graql.VarPattern in project grakn by graknlabs.
the class PatternTest method whenDisjunctionPassedVarAndNull_Throw.
@Test(expected = Exception.class)
public void whenDisjunctionPassedVarAndNull_Throw() {
VarPattern var = null;
// noinspection ResultOfMethodCallIgnored,ConstantConditions
or(var(), var);
}
use of ai.grakn.graql.VarPattern in project grakn by graknlabs.
the class PatternTest method whenNegationPassedNull_Throw.
@Test(expected = Exception.class)
public void whenNegationPassedNull_Throw() {
VarPattern var = null;
// noinspection ConstantConditions,ResultOfMethodCallIgnored
neq(var);
}
use of ai.grakn.graql.VarPattern in project grakn by graknlabs.
the class MatchTest method whenReferringToImplicitRelationsAndRoles_DontHideResults.
@Test
public void whenReferringToImplicitRelationsAndRoles_DontHideResults() {
VarPattern hasTitle = label(HAS.getLabel("title"));
VarPattern titleOwner = label(HAS_OWNER.getLabel("title"));
VarPattern titleValue = label(HAS_VALUE.getLabel("title"));
Match hasQuery = qb.match(y.has("title", z));
Match explicitQuery = qb.match(var().isa(hasTitle).rel(titleOwner, y).rel(titleValue, z));
assertEquals(hasQuery.stream().collect(toSet()), explicitQuery.stream().collect(toSet()));
}
Aggregations