Search in sources :

Example 26 with Thing

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

the class AdmissionsKB method buildInstances.

@Override
protected void buildInstances(GraknTx tx) {
    Thing Alice = putEntityWithResource(tx, "Alice", applicant, key.getLabel());
    Thing Bob = putEntityWithResource(tx, "Bob", applicant, key.getLabel());
    Thing Charlie = putEntityWithResource(tx, "Charlie", applicant, key.getLabel());
    Thing Denis = putEntityWithResource(tx, "Denis", applicant, key.getLabel());
    Thing Eva = putEntityWithResource(tx, "Eva", applicant, key.getLabel());
    Thing Frank = putEntityWithResource(tx, "Frank", applicant, key.getLabel());
    putResource(Alice, TOEFL, 470L);
    putResource(Alice, degreeOrigin, "nonUS");
    putResource(Bob, priorGraduateWork, "none");
    putResource(Bob, TOEFL, 520L);
    putResource(Bob, degreeOrigin, "US");
    putResource(Bob, transcript, "unavailable");
    putResource(Bob, specialHonours, "none");
    putResource(Bob, GRE, 1100L);
    putResource(Charlie, priorGraduateWork, "none");
    putResource(Charlie, TOEFL, 600L);
    putResource(Charlie, degreeOrigin, "US");
    putResource(Charlie, transcript, "available");
    putResource(Charlie, specialHonours, "none");
    putResource(Charlie, GRE, 1100L);
    putResource(Charlie, vGRE, 400L);
    putResource(Charlie, GPR, 2.99);
    putResource(Denis, priorGraduateWork, "none");
    putResource(Denis, degreeOrigin, "US");
    putResource(Denis, transcript, "available");
    putResource(Denis, specialHonours, "none");
    putResource(Denis, GRE, 900L);
    putResource(Denis, vGRE, 350L);
    putResource(Denis, GPR, 2.5);
    putResource(Eva, priorGraduateWork, "completed");
    putResource(Eva, specialHonours, "valedictorian");
    putResource(Eva, GPR, 3.0);
    putResource(Frank, TOEFL, 550L);
    putResource(Frank, degreeOrigin, "US");
    putResource(Frank, transcript, "unavailable");
    putResource(Frank, specialHonours, "none");
    putResource(Frank, GRE, 100L);
}
Also used : Thing(ai.grakn.concept.Thing)

Example 27 with Thing

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

the class LinearTransitivityMatrixKB method buildExtensionalDB.

private void buildExtensionalDB(GraknTx graph, int n, int m) {
    Role Qfrom = graph.getRole("Q-from");
    Role Qto = graph.getRole("Q-to");
    EntityType aEntity = graph.getEntityType("a-entity");
    RelationshipType Q = graph.getRelationshipType("Q");
    ConceptId[][] aInstancesIds = new ConceptId[n + 1][m + 1];
    Thing aInst = putEntityWithResource(graph, "a", graph.getEntityType("entity2"), key);
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            aInstancesIds[i][j] = putEntityWithResource(graph, "a" + i + "," + j, aEntity, key).getId();
        }
    }
    Q.addRelationship().addRolePlayer(Qfrom, aInst).addRolePlayer(Qto, graph.getConcept(aInstancesIds[1][1]));
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (i < n) {
                Q.addRelationship().addRolePlayer(Qfrom, graph.getConcept(aInstancesIds[i][j])).addRolePlayer(Qto, graph.getConcept(aInstancesIds[i + 1][j]));
            }
            if (j < m) {
                Q.addRelationship().addRolePlayer(Qfrom, graph.getConcept(aInstancesIds[i][j])).addRolePlayer(Qto, graph.getConcept(aInstancesIds[i][j + 1]));
            }
        }
    }
}
Also used : Role(ai.grakn.concept.Role) EntityType(ai.grakn.concept.EntityType) RelationshipType(ai.grakn.concept.RelationshipType) Thing(ai.grakn.concept.Thing) ConceptId(ai.grakn.concept.ConceptId)

Example 28 with Thing

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

the class GrpcServerIT method whenGettingAThing_TheInformationOnTheThingIsCorrect.

@Test
public void whenGettingAThing_TheInformationOnTheThingIsCorrect() {
    try (GraknTx remoteTx = remoteSession.open(GraknTxType.READ);
        GraknTx localTx = localSession.open(GraknTxType.READ)) {
        GetQuery query = remoteTx.graql().match(var("x").has("name", "crime")).get();
        Thing remoteConcept = query.stream().findAny().get().get("x").asThing();
        Thing localConcept = localTx.getConcept(remoteConcept.getId()).asThing();
        assertEquals(localConcept.isInferred(), remoteConcept.isInferred());
        assertEquals(localConcept.type().getId(), remoteConcept.type().getId());
        assertEqualConcepts(localConcept, remoteConcept, Thing::attributes);
        assertEqualConcepts(localConcept, remoteConcept, Thing::keys);
        // assertEqualConcepts(localConcept, remoteConcept, Thing::plays); // TODO: re-enable when #19630 is fixed
        assertEqualConcepts(localConcept, remoteConcept, Thing::relationships);
    }
}
Also used : GraknTx(ai.grakn.GraknTx) GetQuery(ai.grakn.graql.GetQuery) Thing(ai.grakn.concept.Thing) Test(org.junit.Test)

Example 29 with Thing

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

the class RemoteConceptsTest method whenCallingAllRolePlayers_GetTheExpectedResult.

@Test
public void whenCallingAllRolePlayers_GetTheExpectedResult() {
    Role foo = RemoteConcepts.createRole(tx, ConceptId.of("foo"));
    Role bar = RemoteConcepts.createRole(tx, ConceptId.of("bar"));
    Thing a = RemoteConcepts.createEntity(tx, A);
    Thing b = RemoteConcepts.createRelationship(tx, B);
    Thing c = RemoteConcepts.createAttribute(tx, C);
    Stream<RolePlayer> mockedResponse = Stream.of(RolePlayer.create(foo, a), RolePlayer.create(bar, b), RolePlayer.create(bar, c));
    TxResponse response = GET_ROLE_PLAYERS.createTxResponse(server.grpcIterators(), mockedResponse);
    server.setResponse(GrpcUtil.runConceptMethodRequest(ID, GET_ROLE_PLAYERS), response);
    Map<Role, Set<Thing>> allRolePlayers = relationship.allRolePlayers();
    Map<Role, Set<Thing>> expected = ImmutableMap.of(foo, ImmutableSet.of(a), bar, ImmutableSet.of(b, c));
    assertEquals(expected, allRolePlayers);
}
Also used : Role(ai.grakn.concept.Role) Collectors.toSet(java.util.stream.Collectors.toSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) TxResponse(ai.grakn.rpc.generated.GrpcGrakn.TxResponse) RolePlayer(ai.grakn.grpc.RolePlayer) Thing(ai.grakn.concept.Thing) Test(org.junit.Test)

Example 30 with Thing

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

the class RemoteConceptsTest method whenCallingRemoveRolePlayer_ExecuteAConceptMethod.

@Test
public void whenCallingRemoveRolePlayer_ExecuteAConceptMethod() {
    Role role = RemoteConcepts.createRole(tx, A);
    Thing thing = RemoteConcepts.createEntity(tx, B);
    relationship.removeRolePlayer(role, thing);
    verifyConceptMethodCalled(ConceptMethods.removeRolePlayer(RolePlayer.create(role, thing)));
}
Also used : Role(ai.grakn.concept.Role) Thing(ai.grakn.concept.Thing) Test(org.junit.Test)

Aggregations

Thing (ai.grakn.concept.Thing)47 Role (ai.grakn.concept.Role)30 Test (org.junit.Test)29 RelationshipType (ai.grakn.concept.RelationshipType)17 EntityType (ai.grakn.concept.EntityType)14 Relationship (ai.grakn.concept.Relationship)12 HashSet (java.util.HashSet)9 Set (java.util.Set)9 GraknTx (ai.grakn.GraknTx)7 Attribute (ai.grakn.concept.Attribute)7 ConceptId (ai.grakn.concept.ConceptId)7 AttributeType (ai.grakn.concept.AttributeType)6 Concept (ai.grakn.concept.Concept)6 Entity (ai.grakn.concept.Entity)6 Collectors (java.util.stream.Collectors)5 Label (ai.grakn.concept.Label)4 Schema (ai.grakn.util.Schema)4 Collection (java.util.Collection)4 Map (java.util.Map)4 GraknSession (ai.grakn.GraknSession)3