Search in sources :

Example 16 with Match

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

the class DirectIsaTest method testMatchSyntax.

@Test
public void testMatchSyntax() {
    QueryBuilder queryBuilder = tx.graql();
    Match matchQuery;
    GetQuery getQuery;
    matchQuery = queryBuilder.match(x.directIsa(thingy1));
    assertEquals("match $x isa! thingy1;", matchQuery.toString());
    matchQuery = queryBuilder.match(x.directIsa(y));
    assertEquals("match $x isa! $y;", matchQuery.toString());
    getQuery = queryBuilder.parse("match $x isa! thingy1; get;");
    assertEquals(queryBuilder.match(x.directIsa(thingy1)), getQuery.match());
    getQuery = queryBuilder.parse("match $x isa! $y; get;");
    assertEquals(queryBuilder.match(x.directIsa(y)), getQuery.match());
}
Also used : GetQuery(ai.grakn.graql.GetQuery) QueryBuilder(ai.grakn.graql.QueryBuilder) Match(ai.grakn.graql.Match) Test(org.junit.Test)

Example 17 with Match

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

the class AdminTest method testGetTypesInQuery.

@Test
public void testGetTypesInQuery() {
    Match match = qb.match(var("x").isa(label("movie").sub("production")).has("tmdb-vote-count", 400), var("y").isa("character"), var().rel("production-with-cast", "x").rel("y").isa("has-cast"));
    Set<SchemaConcept> types = Stream.of("movie", "production", "tmdb-vote-count", "character", "production-with-cast", "has-cast").map(t -> rule.tx().<SchemaConcept>getSchemaConcept(Label.of(t))).collect(toSet());
    assertEquals(types, match.admin().getSchemaConcepts());
}
Also used : PatternAdmin(ai.grakn.graql.admin.PatternAdmin) DeleteQuery(ai.grakn.graql.DeleteQuery) SchemaConcept(ai.grakn.concept.SchemaConcept) InsertQuery(ai.grakn.graql.InsertQuery) Graql(ai.grakn.graql.Graql) TestCase.assertNotNull(junit.framework.TestCase.assertNotNull) Label(ai.grakn.concept.Label) ConceptId(ai.grakn.concept.ConceptId) ClassRule(org.junit.ClassRule) Collectors.toSet(java.util.stream.Collectors.toSet) Before(org.junit.Before) QueryBuilder(ai.grakn.graql.QueryBuilder) Graql.var(ai.grakn.graql.Graql.var) Conjunction(ai.grakn.graql.admin.Conjunction) Set(java.util.Set) Test(org.junit.Test) Graql.label(ai.grakn.graql.Graql.label) Sets(com.google.common.collect.Sets) MovieKB(ai.grakn.test.kbs.MovieKB) Match(ai.grakn.graql.Match) Stream(java.util.stream.Stream) Assert.assertFalse(org.junit.Assert.assertFalse) SampleKBContext(ai.grakn.test.rule.SampleKBContext) Optional(java.util.Optional) Assert.assertEquals(org.junit.Assert.assertEquals) SchemaConcept(ai.grakn.concept.SchemaConcept) Match(ai.grakn.graql.Match) Test(org.junit.Test)

Example 18 with Match

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

the class DefineQueryTest method testDefineDataType.

@Test
public void testDefineDataType() {
    qb.define(label("my-type").sub(Schema.MetaSchema.ATTRIBUTE.getLabel().getValue()).datatype(AttributeType.DataType.LONG)).execute();
    Match match = qb.match(var("x").label("my-type"));
    AttributeType.DataType datatype = match.iterator().next().get("x").asAttributeType().getDataType();
    Assert.assertEquals(AttributeType.DataType.LONG, datatype);
}
Also used : AttributeType(ai.grakn.concept.AttributeType) Match(ai.grakn.graql.Match) Test(org.junit.Test)

Example 19 with Match

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

the class MatchTest method testNoInstancesOfRoleTypeUnselectedVariable.

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

Example 20 with Match

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

the class MatchTest method testDisconnectedQuery.

@Test
public void testDisconnectedQuery() {
    Match query = qb.match(x.isa("movie"), y.isa("person"));
    int numPeople = 10;
    assertThat(Sets.newHashSet(query), hasSize(movies.size() * numPeople));
}
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