use of ai.grakn.concept.Thing in project grakn by graknlabs.
the class RemoteConceptsTest method whenCallingRolePlayersWithNoArguments_GetTheExpectedResult.
@Test
public void whenCallingRolePlayersWithNoArguments_GetTheExpectedResult() {
Role foo = RemoteConcepts.createRole(tx, ConceptId.of("foo"));
Thing a = RemoteConcepts.createEntity(tx, A);
Thing b = RemoteConcepts.createRelationship(tx, B);
Thing c = RemoteConcepts.createAttribute(tx, C);
Stream<RolePlayer> expected = Stream.of(RolePlayer.create(foo, a), RolePlayer.create(foo, b), RolePlayer.create(foo, c));
mockConceptMethod(ConceptMethods.GET_ROLE_PLAYERS, expected);
assertThat(relationship.rolePlayers().collect(toSet()), containsInAnyOrder(a, b, c));
}
use of ai.grakn.concept.Thing in project grakn by graknlabs.
the class RelationshipReified method innerToString.
@Override
public String innerToString() {
StringBuilder description = new StringBuilder();
description.append("ID [").append(getId()).append("] Type [").append(type().getLabel()).append("] Roles and Role Players: \n");
for (Map.Entry<Role, Set<Thing>> entry : allRolePlayers().entrySet()) {
if (entry.getValue().isEmpty()) {
description.append(" Role [").append(entry.getKey().getLabel()).append("] not played by any instance \n");
} else {
StringBuilder instancesString = new StringBuilder();
for (Thing thing : entry.getValue()) {
instancesString.append(thing.getId()).append(",");
}
description.append(" Role [").append(entry.getKey().getLabel()).append("] played by [").append(instancesString.toString()).append("] \n");
}
}
return description.toString();
}
use of ai.grakn.concept.Thing in project grakn by graknlabs.
the class ValidateGlobalRulesTest method testValidatePlaysStructure.
@Test
public void testValidatePlaysStructure() throws Exception {
EntityTypeImpl wolf = (EntityTypeImpl) tx.putEntityType("wolf");
EntityTypeImpl creature = (EntityTypeImpl) tx.putEntityType("creature");
EntityTypeImpl hunter = (EntityTypeImpl) tx.putEntityType("hunter");
RelationshipType hunts = tx.putRelationshipType("hunts");
RoleImpl witcher = (RoleImpl) tx.putRole("witcher");
RoleImpl monster = (RoleImpl) tx.putRole("monster");
Thing geralt = hunter.addEntity();
ThingImpl werewolf = (ThingImpl) wolf.addEntity();
RelationshipImpl assertion = (RelationshipImpl) hunts.addRelationship().addRolePlayer(witcher, geralt).addRolePlayer(monster, werewolf);
assertion.reified().get().castingsRelation().forEach(rolePlayer -> assertFalse(ValidateGlobalRules.validatePlaysAndRelatesStructure(rolePlayer).isEmpty()));
hunter.plays(witcher);
boolean[] flags = { false, false };
int count = 0;
for (Casting casting : assertion.reified().get().castingsRelation().collect(Collectors.toSet())) {
flags[count] = !ValidateGlobalRules.validatePlaysAndRelatesStructure(casting).isEmpty();
count++;
}
assertTrue(flags[0] && flags[1]);
wolf.sup(creature);
creature.plays(monster);
for (Casting casting : assertion.reified().get().castingsRelation().collect(Collectors.toSet())) {
assertFalse(ValidateGlobalRules.validatePlaysAndRelatesStructure(casting).isEmpty());
}
}
use of ai.grakn.concept.Thing in project grakn by graknlabs.
the class TestKB method putEntityWithResource.
public static Thing putEntityWithResource(GraknTx tx, String id, EntityType type, Label key) {
Thing inst = type.addEntity();
putResource(inst, tx.getSchemaConcept(key), id);
return inst;
}
use of ai.grakn.concept.Thing in project grakn by graknlabs.
the class GrpcServerIT method whenGettingARelationship_TheInformationOnTheRelationshipIsCorrect.
@Test
public void whenGettingARelationship_TheInformationOnTheRelationshipIsCorrect() {
try (GraknTx remoteTx = remoteSession.open(GraknTxType.READ);
GraknTx localTx = localSession.open(GraknTxType.READ)) {
GetQuery query = remoteTx.graql().match(var("x").isa("has-cast")).get();
Relationship remoteConcept = query.stream().findAny().get().get("x").asRelationship();
Relationship localConcept = localTx.getConcept(remoteConcept.getId()).asRelationship();
assertEqualConcepts(localConcept, remoteConcept, Relationship::rolePlayers);
ImmutableMultimap.Builder<ConceptId, ConceptId> localRolePlayers = ImmutableMultimap.builder();
localConcept.allRolePlayers().forEach((role, players) -> {
for (Thing player : players) {
localRolePlayers.put(role.getId(), player.getId());
}
});
ImmutableMultimap.Builder<ConceptId, ConceptId> remoteRolePlayers = ImmutableMultimap.builder();
remoteConcept.allRolePlayers().forEach((role, players) -> {
for (Thing player : players) {
remoteRolePlayers.put(role.getId(), player.getId());
}
});
assertEquals(localRolePlayers.build(), remoteRolePlayers.build());
}
}
Aggregations