Search in sources :

Example 71 with EntityType

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));
}
Also used : Role(ai.grakn.concept.Role) EntityType(ai.grakn.concept.EntityType) Test(org.junit.Test)

Example 72 with EntityType

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);
    }
}
Also used : EntityType(ai.grakn.concept.EntityType) Role(ai.grakn.concept.Role) InvalidKBException(ai.grakn.exception.InvalidKBException) GraknTestUtil(ai.grakn.util.GraknTestUtil) Role(ai.grakn.concept.Role) Assume.assumeFalse(org.junit.Assume.assumeFalse) Concept(ai.grakn.concept.Concept) Entity(ai.grakn.concept.Entity) Graql(ai.grakn.graql.Graql) EntityType(ai.grakn.concept.EntityType) ArrayList(java.util.ArrayList) Attribute(ai.grakn.concept.Attribute) SessionContext(ai.grakn.test.rule.SessionContext) HashSet(java.util.HashSet) Assert.assertThat(org.junit.Assert.assertThat) Lists(com.google.common.collect.Lists) Label(ai.grakn.concept.Label) AttributeType(ai.grakn.concept.AttributeType) RelationshipType(ai.grakn.concept.RelationshipType) GraknTx(ai.grakn.GraknTx) ConceptId(ai.grakn.concept.ConceptId) ClassRule(org.junit.ClassRule) Before(org.junit.Before) GraknTxType(ai.grakn.GraknTxType) Matchers.empty(org.hamcrest.Matchers.empty) GraqlQueryException(ai.grakn.exception.GraqlQueryException) Utility.getResourceEdgeId(ai.grakn.graql.internal.analytics.Utility.getResourceEdgeId) GraknSession(ai.grakn.GraknSession) Set(java.util.Set) Test(org.junit.Test) Collectors(java.util.stream.Collectors) List(java.util.List) Optional(java.util.Optional) Schema(ai.grakn.util.Schema) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) GraknTx(ai.grakn.GraknTx) Entity(ai.grakn.concept.Entity) RelationshipType(ai.grakn.concept.RelationshipType) ArrayList(java.util.ArrayList) List(java.util.List) ConceptId(ai.grakn.concept.ConceptId) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 73 with EntityType

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());
}
Also used : EntityType(ai.grakn.concept.EntityType) Label(ai.grakn.concept.Label) Test(org.junit.Test)

Example 74 with EntityType

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();
}
Also used : EntityType(ai.grakn.concept.EntityType) Concept(ai.grakn.concept.Concept) Test(org.junit.Test)

Example 75 with EntityType

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();
}
Also used : EntityType(ai.grakn.concept.EntityType) VarPattern(ai.grakn.graql.VarPattern) Test(org.junit.Test)

Aggregations

EntityType (ai.grakn.concept.EntityType)168 Test (org.junit.Test)141 Role (ai.grakn.concept.Role)83 RelationshipType (ai.grakn.concept.RelationshipType)82 Entity (ai.grakn.concept.Entity)74 GraknTx (ai.grakn.GraknTx)45 Relationship (ai.grakn.concept.Relationship)21 Attribute (ai.grakn.concept.Attribute)19 AttributeType (ai.grakn.concept.AttributeType)17 ConceptId (ai.grakn.concept.ConceptId)17 Label (ai.grakn.concept.Label)17 Set (java.util.Set)16 HashSet (java.util.HashSet)15 Thing (ai.grakn.concept.Thing)14 GraknTxType (ai.grakn.GraknTxType)8 ArrayList (java.util.ArrayList)8 GraknSession (ai.grakn.GraknSession)7 Concept (ai.grakn.concept.Concept)7 HashMap (java.util.HashMap)7 Before (org.junit.Before)7