Search in sources :

Example 86 with Match

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

the class MatchTest method testMoviesReleasedBeforeTheMuppets.

@Test
public void testMoviesReleasedBeforeTheMuppets() {
    Match query = qb.match(x.has("release-date", lt(r)), var().has("title", "The Muppets").has("release-date", r));
    assertThat(query, variable(x, contains(godfather)));
}
Also used : Match(ai.grakn.graql.Match) Test(org.junit.Test)

Example 87 with Match

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

the class MatchTest method testRobertDeNiroNotRelatedToSelf.

@Test
public void testRobertDeNiroNotRelatedToSelf() {
    Match query = qb.match(var().rel(x).rel(y).isa("has-cast"), y.has("name", "Robert de Niro"));
    assertThat(query, variable(x, containsInAnyOrder(heat, neilMcCauley)));
}
Also used : Match(ai.grakn.graql.Match) Test(org.junit.Test)

Example 88 with Match

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

the class MatchTest method testMatchAllResourcesUsingResourceName.

@Test
public void testMatchAllResourcesUsingResourceName() {
    Match match = qb.match(var().has("title", "Godfather").has(Schema.MetaSchema.ATTRIBUTE.getLabel().getValue(), x));
    Thing godfather = movieKB.tx().getAttributeType("title").getAttribute("Godfather").owner();
    Set<Attribute<?>> expected = godfather.attributes().collect(toSet());
    Set<Attribute<?>> results = match.get(x).map(Concept::asAttribute).collect(toSet());
    assertEquals(expected, results);
}
Also used : Attribute(ai.grakn.concept.Attribute) Thing(ai.grakn.concept.Thing) Match(ai.grakn.graql.Match) Test(org.junit.Test)

Example 89 with Match

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

the class MatchTest method testDistinctTuple.

@Test
public void testDistinctTuple() {
    int size = (int) movieKB.tx().graql().match(x.isa("genre")).stream().count();
    size *= size;
    Match match1 = movieKB.tx().graql().match(x.isa("genre"), x.isa("genre"), x.isa("genre"), y.isa("genre"));
    assertThat(match1, iterableWithSize(size));
    Match match2 = movieKB.tx().graql().match(var().isa("genre"), var().isa("genre"), var().isa("genre"), var().isa("genre"), var().isa("genre"));
    assertThat(match2, iterableWithSize(1));
    Match match3 = movieKB.tx().graql().match(x.isa("genre"), y.isa("genre"));
    assertThat(match3, iterableWithSize(size));
    Match match4 = movieKB.tx().graql().match(var().isa("genre"), x.isa("genre"), y.isa("genre"));
    assertThat(match4, iterableWithSize(size));
}
Also used : Match(ai.grakn.graql.Match) Test(org.junit.Test)

Example 90 with Match

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

the class MatchTest method testAssertionQuery.

@Test
public void testAssertionQuery() {
    Match query = qb.match(var("a").rel("production-with-cast", x).rel(y), y.has("name", "Miss Piggy"), var("a").isa("has-cast"));
    assertThat(query, variable(x, contains(theMuppets)));
}
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