use of com.vaticle.typedb.core.concept.thing.Relation in project grakn by graknlabs.
the class RelationTypeImpl method getRelates.
/**
* Get the role type with a given {@code roleLabel} related by this relation type.
*
* First, look up the role type by the given label and it's scope: the relation label.
* If the role type vertex do not exist, then call {@code role()} to get the inherited role types,
* and see if the any of them has the {@code roleLabel} of interest.
*
* @param roleLabel the label of the role
* @return the role type related in this relation
*/
@Override
public RoleTypeImpl getRelates(String roleLabel) {
Optional<RoleTypeImpl> roleType;
TypeVertex roleTypeVertex = graphMgr.schema().getType(roleLabel, vertex.label());
if (roleTypeVertex != null) {
return RoleTypeImpl.of(graphMgr, roleTypeVertex);
} else if ((roleType = getRelates().filter(role -> role.getLabel().name().equals(roleLabel)).first()).isPresent()) {
return roleType.get();
} else
return null;
}
use of com.vaticle.typedb.core.concept.thing.Relation in project grakn by graknlabs.
the class RelationSteps method relation_type_create_new_instance_with_key.
@When("{var} = relation\\( ?{type_label} ?) create new instance with key\\( ?{type_label} ?): {word}")
public void relation_type_create_new_instance_with_key(String var, String type, String keyType, String keyValue) {
Attribute.String key = tx().concepts().getAttributeType(keyType).asString().put(keyValue);
Relation relation = tx().concepts().getRelationType(type).create();
relation.setHas(key);
put(var, relation);
}
use of com.vaticle.typedb.core.concept.thing.Relation in project grakn by graknlabs.
the class RelationSteps method relation_get_players_contain.
@Then("relation {var} get players contain:")
public void relation_get_players_contain(String var, Map<String, String> players) {
Relation relation = get(var).asRelation();
players.forEach((rt, var2) -> assertTrue(relation.getPlayers(relation.getType().getRelates(rt)).anyMatch(p -> p.equals(get(var2.substring(1))))));
}
use of com.vaticle.typedb.core.concept.thing.Relation in project grakn by graknlabs.
the class RelationSteps method relation_type_create_new_instance_with_key.
@When("{var} = relation\\( ?{type_label} ?) create new instance with key\\( ?{type_label} ?): {int}")
public void relation_type_create_new_instance_with_key(String var, String type, String keyType, int keyValue) {
Attribute.Long key = tx().concepts().getAttributeType(keyType).asLong().put(keyValue);
Relation relation = tx().concepts().getRelationType(type).create();
relation.setHas(key);
put(var, relation);
}
use of com.vaticle.typedb.core.concept.thing.Relation in project grakn by graknlabs.
the class RelationSteps method relation_get_players_do_not_contain.
@Then("relation {var} get players do not contain:")
public void relation_get_players_do_not_contain(String var, Map<String, String> players) {
Relation relation = get(var).asRelation();
players.forEach((rt, var2) -> assertTrue(relation.getPlayers(relation.getType().getRelates(rt)).noneMatch(p -> p.equals(get(var2.substring(1))))));
}
Aggregations