Search in sources :

Example 31 with VarPattern

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;
}
Also used : Role(ai.grakn.concept.Role) VarPattern(ai.grakn.graql.VarPattern) Pattern(ai.grakn.graql.Pattern) HashSet(java.util.HashSet) Set(java.util.Set) Var(ai.grakn.graql.Var) VarPattern(ai.grakn.graql.VarPattern) Map(java.util.Map) Thing(ai.grakn.concept.Thing) HashSet(java.util.HashSet)

Example 32 with VarPattern

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);
}
Also used : VarPattern(ai.grakn.graql.VarPattern) Test(org.junit.Test)

Example 33 with VarPattern

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);
}
Also used : VarPattern(ai.grakn.graql.VarPattern) Test(org.junit.Test)

Example 34 with VarPattern

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);
}
Also used : VarPattern(ai.grakn.graql.VarPattern) Test(org.junit.Test)

Example 35 with VarPattern

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()));
}
Also used : VarPattern(ai.grakn.graql.VarPattern) Match(ai.grakn.graql.Match) Test(org.junit.Test)

Aggregations

VarPattern (ai.grakn.graql.VarPattern)46 Test (org.junit.Test)28 Var (ai.grakn.graql.Var)12 Pattern (ai.grakn.graql.Pattern)11 Answer (ai.grakn.graql.admin.Answer)9 GraknTx (ai.grakn.GraknTx)8 Role (ai.grakn.concept.Role)8 Label (ai.grakn.concept.Label)7 RelationshipType (ai.grakn.concept.RelationshipType)7 Graql (ai.grakn.graql.Graql)7 Set (java.util.Set)7 ConceptId (ai.grakn.concept.ConceptId)6 EntityType (ai.grakn.concept.EntityType)6 List (java.util.List)6 Collectors.toSet (java.util.stream.Collectors.toSet)6 SchemaConcept (ai.grakn.concept.SchemaConcept)5 GraqlQueryException (ai.grakn.exception.GraqlQueryException)5 QueryBuilder (ai.grakn.graql.QueryBuilder)5 RelationPlayer (ai.grakn.graql.admin.RelationPlayer)5 VarPatternAdmin (ai.grakn.graql.admin.VarPatternAdmin)5