Search in sources :

Example 36 with Concept

use of ai.grakn.concept.Concept in project grakn by graknlabs.

the class MatchTest method testGraqlPlaysSemanticsMatchGraphAPI.

@Test
public void testGraqlPlaysSemanticsMatchGraphAPI() {
    GraknTx tx = emptyKB.tx();
    QueryBuilder qb = tx.graql();
    Label a = Label.of("a");
    Label b = Label.of("b");
    Label c = Label.of("c");
    Label d = Label.of("d");
    Label e = Label.of("e");
    Label f = Label.of("f");
    qb.define(Graql.label(c).sub(Graql.label(b).sub(Graql.label(a).sub("entity"))), Graql.label(f).sub(Graql.label(e).sub(Graql.label(d).sub("role"))), Graql.label(b).plays(Graql.label(e))).execute();
    Stream.of(a, b, c, d, e, f).forEach(type -> {
        Set<Concept> graqlPlays = qb.match(Graql.label(type).plays(x)).get(x).collect(Collectors.toSet());
        Collection<Role> graphAPIPlays;
        SchemaConcept schemaConcept = tx.getSchemaConcept(type);
        if (schemaConcept.isType()) {
            graphAPIPlays = schemaConcept.asType().plays().collect(toSet());
        } else {
            graphAPIPlays = Collections.EMPTY_SET;
        }
        assertEquals(graqlPlays, graphAPIPlays);
    });
    Stream.of(d, e, f).forEach(type -> {
        Set<Concept> graqlPlayedBy = qb.match(x.plays(Graql.label(type))).get(x).collect(toSet());
        Collection<Type> graphAPIPlayedBy = tx.<Role>getSchemaConcept(type).playedByTypes().collect(toSet());
        assertEquals(graqlPlayedBy, graphAPIPlayedBy);
    });
}
Also used : Concept(ai.grakn.concept.Concept) MatchableConcept(ai.grakn.matcher.MatchableConcept) SchemaConcept(ai.grakn.concept.SchemaConcept) Role(ai.grakn.concept.Role) GraknTx(ai.grakn.GraknTx) EntityType(ai.grakn.concept.EntityType) RelationshipType(ai.grakn.concept.RelationshipType) AttributeType(ai.grakn.concept.AttributeType) GraknMatchers.hasType(ai.grakn.matcher.GraknMatchers.hasType) Type(ai.grakn.concept.Type) Label(ai.grakn.concept.Label) SchemaConcept(ai.grakn.concept.SchemaConcept) QueryBuilder(ai.grakn.graql.QueryBuilder) Test(org.junit.Test)

Example 37 with Concept

use of ai.grakn.concept.Concept in project grakn by graknlabs.

the class MatchTest method whenExecutingGraqlTraversalFromGraph_ReturnExpectedResults.

@Test
public void whenExecutingGraqlTraversalFromGraph_ReturnExpectedResults() {
    EntityType type = movieKB.tx().putEntityType("Concept Type");
    Entity entity = type.addEntity();
    Collection<Concept> results = movieKB.tx().graql().match(x.isa(type.getLabel().getValue())).stream().findAny().get().concepts();
    assertThat(results, containsInAnyOrder(entity));
}
Also used : EntityType(ai.grakn.concept.EntityType) Concept(ai.grakn.concept.Concept) MatchableConcept(ai.grakn.matcher.MatchableConcept) SchemaConcept(ai.grakn.concept.SchemaConcept) Entity(ai.grakn.concept.Entity) Test(org.junit.Test)

Example 38 with Concept

use of ai.grakn.concept.Concept in project grakn by graknlabs.

the class MatchTest method testDistinctRoleplayers.

@Test
public void testDistinctRoleplayers() {
    Match query = qb.match(var().rel(x).rel(y).rel(z).isa("has-cast"));
    assertNotEquals(0, query.stream().count());
    // Make sure none of the resulting relationships have 3 role-players all the same
    query.forEach(result -> {
        Concept cx = result.get(x);
        Concept cy = result.get(y);
        Concept cz = result.get(z);
        assertThat(cx, not(allOf(is(cy), is(cz))));
    });
}
Also used : Concept(ai.grakn.concept.Concept) MatchableConcept(ai.grakn.matcher.MatchableConcept) SchemaConcept(ai.grakn.concept.SchemaConcept) Match(ai.grakn.graql.Match) Test(org.junit.Test)

Example 39 with Concept

use of ai.grakn.concept.Concept in project grakn by graknlabs.

the class AggregateTest method testGroupCount.

@Test
public void testGroupCount() {
    AggregateQuery<Map<Concept, Long>> groupCountQuery = qb.match(var("x").isa("movie"), var("r").rel("x")).aggregate(group("x", count()));
    Map<Concept, Long> groupCount = groupCountQuery.execute();
    Thing godfather = rule.tx().getAttributeType("title").getAttribute("Godfather").owner();
    assertEquals(new Long(9), groupCount.get(godfather));
}
Also used : Concept(ai.grakn.concept.Concept) Map(java.util.Map) Thing(ai.grakn.concept.Thing) Test(org.junit.Test)

Example 40 with Concept

use of ai.grakn.concept.Concept in project grakn by graknlabs.

the class UndefineQueryTest method whenUndefiningAnInstanceProperty_Throw.

@Test
public void whenUndefiningAnInstanceProperty_Throw() {
    Concept movie = qb.insert(x.isa("movie")).execute().get(0).get(x);
    exception.expect(GraqlQueryException.class);
    exception.expectMessage(GraqlQueryException.defineUnsupportedProperty(IsaProperty.NAME).getMessage());
    qb.undefine(var().id(movie.getId()).isa("movie")).execute();
}
Also used : Concept(ai.grakn.concept.Concept) Test(org.junit.Test)

Aggregations

Concept (ai.grakn.concept.Concept)91 Test (org.junit.Test)56 ConceptId (ai.grakn.concept.ConceptId)26 GraknTx (ai.grakn.GraknTx)25 Answer (ai.grakn.graql.admin.Answer)25 SchemaConcept (ai.grakn.concept.SchemaConcept)19 Label (ai.grakn.concept.Label)18 GrpcConcept (ai.grakn.rpc.generated.GrpcConcept)18 QueryBuilder (ai.grakn.graql.QueryBuilder)17 Var (ai.grakn.graql.Var)15 Set (java.util.Set)15 Role (ai.grakn.concept.Role)14 QueryAnswer (ai.grakn.graql.internal.query.QueryAnswer)14 HashSet (java.util.HashSet)13 List (java.util.List)12 AttributeType (ai.grakn.concept.AttributeType)11 EntityType (ai.grakn.concept.EntityType)11 Schema (ai.grakn.util.Schema)10 Collectors (java.util.stream.Collectors)10 Stream (java.util.stream.Stream)10