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);
});
}
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));
}
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))));
});
}
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));
}
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();
}
Aggregations