Search in sources :

Example 6 with Match

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

the class MatchModifierTest method testLimitQuery.

@Test
public void testLimitQuery() {
    Var t = var("t");
    Match match = qb.match(x.isa("movie").has("title", t)).orderBy(t, asc).offset(1).limit(3);
    assertResultsOrderedByValue(match, t, true);
    assertEquals(3, match.stream().count());
}
Also used : Var(ai.grakn.graql.Var) Match(ai.grakn.graql.Match) Test(org.junit.Test)

Example 7 with Match

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

the class MatchModifierTest method testVoteCountOrderedQuery.

@Test
public void testVoteCountOrderedQuery() {
    Var z = var("z");
    Match match = qb.match(z.isa("movie").has("tmdb-vote-count", var("v"))).orderBy("v", desc);
    // Make sure movies are in the correct order
    assertThat(match, variable(z, contains(godfather, hocusPocus, apocalypseNow, theMuppets, chineseCoffee)));
}
Also used : Var(ai.grakn.graql.Var) Match(ai.grakn.graql.Match) Test(org.junit.Test)

Example 8 with Match

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

the class MatchTest method testNoInstancesOfRoleType.

@Test
public void testNoInstancesOfRoleType() {
    Match query = qb.match(x.isa(y), y.label("actor"));
    assertThat(query, emptyIterable());
}
Also used : Match(ai.grakn.graql.Match) Test(org.junit.Test)

Example 9 with Match

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

the class MatchTest method whenQueryingForAnImplicitRelationById_TheRelationIsReturned.

@Test
public void whenQueryingForAnImplicitRelationById_TheRelationIsReturned() {
    Match match = qb.match(var("x").isa(label(Schema.ImplicitType.HAS.getLabel("name"))));
    Relationship relationship = match.get("x").findAny().get().asRelationship();
    Match queryById = qb.match(var("x").id(relationship.getId()));
    assertThat(queryById, variable(x, contains(MatchableConcept.of(relationship))));
}
Also used : Relationship(ai.grakn.concept.Relationship) Match(ai.grakn.graql.Match) Test(org.junit.Test)

Example 10 with Match

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

the class MatchTest method testAndOrPattern.

@Test
public void testAndOrPattern() {
    Match query = qb.match(x.isa("movie"), or(and(y.isa("genre").has("name", "drama"), var().rel(x).rel(y)), x.has("title", "The Muppets")));
    assertThat(query, variable(x, containsInAnyOrder(godfather, apocalypseNow, heat, theMuppets, chineseCoffee)));
}
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