use of ai.grakn.concept.EntityType in project grakn by graknlabs.
the class EntityTypeTest method whenGettingTheRolesPlayedByType_ReturnTheRoles.
@Test
public void whenGettingTheRolesPlayedByType_ReturnTheRoles() throws Exception {
Role monster = tx.putRole("monster");
Role animal = tx.putRole("animal");
Role monsterEvil = tx.putRole("evil monster").sup(monster);
EntityType creature = tx.putEntityType("creature").plays(monster).plays(animal);
EntityType creatureMysterious = tx.putEntityType("mysterious creature").sup(creature).plays(monsterEvil);
assertThat(creature.plays().collect(toSet()), containsInAnyOrder(monster, animal));
assertThat(creatureMysterious.plays().collect(toSet()), containsInAnyOrder(monster, animal, monsterEvil));
}
use of ai.grakn.concept.EntityType in project grakn by graknlabs.
the class ShortestPathTest method testMultiplePathsSharing1Instance.
@Test
public void testMultiplePathsSharing1Instance() throws InvalidKBException {
ConceptId startId;
ConceptId endId;
Set<List<ConceptId>> correctPaths = new HashSet<>();
try (GraknTx graph = session.open(GraknTxType.WRITE)) {
EntityType entityType = graph.putEntityType(thing);
Role role1 = graph.putRole("role1");
Role role2 = graph.putRole("role2");
entityType.plays(role1).plays(role2);
RelationshipType relationshipType1 = graph.putRelationshipType(related).relates(role1).relates(role2);
Role role3 = graph.putRole("role3");
Role role4 = graph.putRole("role4");
entityType.plays(role3).plays(role4);
RelationshipType relationshipType2 = graph.putRelationshipType(veryRelated).relates(role3).relates(role4);
Entity start = entityType.addEntity();
Entity end = entityType.addEntity();
Entity middle = entityType.addEntity();
startId = start.getId();
endId = end.getId();
ConceptId middleId = middle.getId();
ConceptId assertion11 = relationshipType1.addRelationship().addRolePlayer(role1, start).addRolePlayer(role2, middle).getId();
ConceptId assertion12 = relationshipType1.addRelationship().addRolePlayer(role1, middle).addRolePlayer(role2, end).getId();
ConceptId assertion21 = relationshipType2.addRelationship().addRolePlayer(role3, start).addRolePlayer(role4, middle).getId();
ConceptId assertion22 = relationshipType2.addRelationship().addRolePlayer(role3, middle).addRolePlayer(role4, end).getId();
correctPaths.add(Lists.newArrayList(startId, assertion11, middleId, assertion12, endId));
correctPaths.add(Lists.newArrayList(startId, assertion11, middleId, assertion22, endId));
correctPaths.add(Lists.newArrayList(startId, assertion21, middleId, assertion12, endId));
correctPaths.add(Lists.newArrayList(startId, assertion21, middleId, assertion22, endId));
graph.commit();
}
try (GraknTx graph = session.open(GraknTxType.READ)) {
List<List<Concept>> allPaths = graph.graql().compute().paths().from(startId).to(endId).execute();
assertEquals(correctPaths.size(), allPaths.size());
Set<List<ConceptId>> computedPaths = allPaths.stream().map(path -> path.stream().map(Concept::getId).collect(Collectors.toList())).collect(Collectors.toSet());
assertEquals(correctPaths, computedPaths);
}
}
use of ai.grakn.concept.EntityType in project grakn by graknlabs.
the class DefineQueryTest method whenSpecifyingLabelOfAnExistingConcept_LabelIsChanged.
@Test
public void whenSpecifyingLabelOfAnExistingConcept_LabelIsChanged() {
movies.tx().putEntityType("a-new-type");
EntityType type = movies.tx().getEntityType("a-new-type");
Label newLabel = Label.of("a-new-new-type");
qb.define(label(newLabel).id(type.getId())).execute();
assertEquals(newLabel, type.getLabel());
}
use of ai.grakn.concept.EntityType in project grakn by graknlabs.
the class InsertQueryTest method whenSpecifyingExistingConceptIdWithIncorrectType_Throw.
@Test
public void whenSpecifyingExistingConceptIdWithIncorrectType_Throw() {
EntityType movie = movieKB.tx().getEntityType("movie");
EntityType person = movieKB.tx().getEntityType("person");
Concept aMovie = movie.instances().iterator().next();
exception.expect(GraqlQueryException.class);
exception.expectMessage(GraqlQueryException.insertPropertyOnExistingConcept("isa", person, aMovie).getMessage());
movieKB.tx().graql().insert(var("x").id(aMovie.getId()).isa("person")).execute();
}
use of ai.grakn.concept.EntityType in project grakn by graknlabs.
the class InsertQueryTest method whenSettingTwoTypes_Throw.
@Test
public void whenSettingTwoTypes_Throw() {
EntityType movie = movieKB.tx().getEntityType("movie");
EntityType person = movieKB.tx().getEntityType("person");
// We have to construct it this way because you can't have two `isa`s normally
// TODO: less bad way?
VarPattern varPattern = Patterns.varPattern(var("x"), ImmutableSet.of(IsaProperty.of(label("movie").admin()), IsaProperty.of(label("person").admin())));
// We don't know in what order the message will be
exception.expect(GraqlQueryException.class);
exception.expectMessage(isOneOf(GraqlQueryException.insertMultipleProperties(varPattern, "isa", movie, person).getMessage(), GraqlQueryException.insertMultipleProperties(varPattern, "isa", person, movie).getMessage()));
movieKB.tx().graql().insert(var("x").isa("movie"), var("x").isa("person")).execute();
}
Aggregations