Search in sources :

Example 56 with Match

use of ai.grakn.graql.Match in project grakn by graknlabs.

the class MatchTest method testSelectRuleTypes.

@Test
public void testSelectRuleTypes() {
    Match query = qb.match(x.sub(RULE.getLabel().getValue()));
    assertThat(query, variable(x, containsInAnyOrder(rule, materializeRule, expectationRule)));
}
Also used : Match(ai.grakn.graql.Match) Test(org.junit.Test)

Example 57 with Match

use of ai.grakn.graql.Match in project grakn by graknlabs.

the class MatchTest method testRegexResourceType.

@Test
public void testRegexResourceType() {
    Match query = qb.match(x.regex("(fe)?male"));
    assertThat(query, variable(x, contains(gender)));
}
Also used : Match(ai.grakn.graql.Match) Test(org.junit.Test)

Example 58 with Match

use of ai.grakn.graql.Match 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)

Example 59 with Match

use of ai.grakn.graql.Match in project grakn by graknlabs.

the class MatchTest method testVariableAsRoleType.

@Test
public void testVariableAsRoleType() {
    Match query = qb.match(var().rel(var().label("genre-of-production"), y));
    assertThat(query, variable(y, containsInAnyOrder(crime, drama, war, action, comedy, family, musical, fantasy)));
}
Also used : Match(ai.grakn.graql.Match) Test(org.junit.Test)

Example 60 with Match

use of ai.grakn.graql.Match in project grakn by graknlabs.

the class MatchTest method testMatchAllDistinctPairs.

@Test
public void testMatchAllDistinctPairs() {
    int numConcepts = (int) qb.match(x).stream().count();
    Match pairs = qb.match(x.neq(y));
    // We expect there to be a result for every distinct pair of concepts
    assertThat(pairs, iterableWithSize(numConcepts * (numConcepts - 1)));
}
Also used : Match(ai.grakn.graql.Match) Test(org.junit.Test)

Aggregations

Match (ai.grakn.graql.Match)103 Test (org.junit.Test)98 Var (ai.grakn.graql.Var)8 ConceptId (ai.grakn.concept.ConceptId)5 Concept (ai.grakn.concept.Concept)4 SchemaConcept (ai.grakn.concept.SchemaConcept)4 PatternAdmin (ai.grakn.graql.admin.PatternAdmin)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 AttributeType (ai.grakn.concept.AttributeType)3 Label (ai.grakn.concept.Label)3 Relationship (ai.grakn.concept.Relationship)3 Printer (ai.grakn.graql.Printer)3 QueryBuilder (ai.grakn.graql.QueryBuilder)3 Answer (ai.grakn.graql.admin.Answer)3 MatchableConcept (ai.grakn.matcher.MatchableConcept)3 Matcher (org.hamcrest.Matcher)3 RelationshipType (ai.grakn.concept.RelationshipType)2 Role (ai.grakn.concept.Role)2 Thing (ai.grakn.concept.Thing)2 GraqlQueryException (ai.grakn.exception.GraqlQueryException)2