Search in sources :

Example 21 with Match

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

the class MatchTest method testMatchAllInstances.

@Test
public void testMatchAllInstances() {
    Match query = qb.match(x.isa(Schema.MetaSchema.THING.getLabel().getValue()));
    // Make sure there a reasonable number of results
    assertThat(query, iterableWithSize(greaterThan(10)));
    assertThat(query, variable(x, everyItem(isInstance())));
}
Also used : Match(ai.grakn.graql.Match) Test(org.junit.Test)

Example 22 with Match

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

the class MatchTest method testRoleOnlyQuery.

@Test
public void testRoleOnlyQuery() {
    Match query = qb.match(var().rel("actor", x));
    assertThat(query, variable(x, containsInAnyOrder(marlonBrando, alPacino, missPiggy, kermitTheFrog, martinSheen, robertDeNiro, judeLaw, mirandaHeart, betteMidler, sarahJessicaParker)));
}
Also used : Match(ai.grakn.graql.Match) Test(org.junit.Test)

Example 23 with Match

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

the class MatchTest method testRelationshipQuery.

@Test
public void testRelationshipQuery() {
    Match query = qb.match(x.isa("movie"), y.isa("person"), z.isa("character").has("name", "Don Vito Corleone"), var().rel(x).rel(y).rel(z));
    assertThat(query, allOf(variable(x, contains(godfather)), variable(y, contains(marlonBrando))));
}
Also used : Match(ai.grakn.graql.Match) Test(org.junit.Test)

Example 24 with Match

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

the class MatchTest method testKermitIsRelatedToSelfWhenMetaRoleIsSpecified.

@Test
public void testKermitIsRelatedToSelfWhenMetaRoleIsSpecified() {
    Match query = qb.match(var().rel("role", x).rel(y).isa("has-cast"), y.has("name", "Kermit The Frog"));
    assertThat(query, variable(x, (Matcher) hasItem(kermitTheFrog)));
}
Also used : Matcher(org.hamcrest.Matcher) Match(ai.grakn.graql.Match) Test(org.junit.Test)

Example 25 with Match

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

the class MatchTest method testAllLessThanAttachedResource.

@Test
public void testAllLessThanAttachedResource() {
    Match query = qb.match(var("p").has("release-date", x), x.val(lte(y)));
    assertThat(query, iterableWithSize(greaterThan(5)));
    query.forEach(result -> {
        Comparable cx = (Comparable) result.get(x).asAttribute().getValue();
        Comparable cy = (Comparable) result.get(y).asAttribute().getValue();
        assertThat(cx, lessThanOrEqualTo(cy));
    });
}
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