Search in sources :

Example 11 with Relation

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;
}
Also used : TYPE_ROOT_MISMATCH(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeRead.TYPE_ROOT_MISMATCH) TypeEdge(com.vaticle.typedb.core.graph.edge.TypeEdge) RELATION_RELATES_ROLE_FROM_SUPERTYPE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.RELATION_RELATES_ROLE_FROM_SUPERTYPE) Order(com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.Order) RelationImpl(com.vaticle.typedb.core.concept.thing.impl.RelationImpl) RelationType(com.vaticle.typedb.core.concept.type.RelationType) ASC(com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.ASC) Forwardable.iterateSorted(com.vaticle.typedb.core.common.iterator.sorted.SortedIterators.Forwardable.iterateSorted) RELATION_NO_ROLE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.RELATION_NO_ROLE) RELATION_ABSTRACT_ROLE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.RELATION_ABSTRACT_ROLE) RELATES(com.vaticle.typedb.core.graph.common.Encoding.Edge.Type.RELATES) RELATION(com.vaticle.typedb.core.graph.common.Encoding.Vertex.Type.Root.RELATION) ROLE(com.vaticle.typedb.core.graph.common.Encoding.Vertex.Type.Root.ROLE) RELATION_RELATES_ROLE_NOT_AVAILABLE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.RELATION_RELATES_ROLE_NOT_AVAILABLE) RELATION_TYPE(com.vaticle.typedb.core.graph.common.Encoding.Vertex.Type.RELATION_TYPE) GraphManager(com.vaticle.typedb.core.graph.GraphManager) FunctionalIterator(com.vaticle.typedb.core.common.iterator.FunctionalIterator) Forwardable(com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.Forwardable) RoleType(com.vaticle.typedb.core.concept.type.RoleType) ThingVertex(com.vaticle.typedb.core.graph.vertex.ThingVertex) Objects(java.util.Objects) List(java.util.List) Relation(com.vaticle.typedb.core.concept.thing.Relation) ROOT_TYPE_MUTATION(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.ROOT_TYPE_MUTATION) Optional(java.util.Optional) TypeDBException(com.vaticle.typedb.core.common.exception.TypeDBException) AttributeType(com.vaticle.typedb.core.concept.type.AttributeType) TypeVertex(com.vaticle.typedb.core.graph.vertex.TypeVertex) TYPE_HAS_INSTANCES_SET_ABSTRACT(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.TYPE_HAS_INSTANCES_SET_ABSTRACT) Type(com.vaticle.typedb.core.concept.type.Type) TypeVertex(com.vaticle.typedb.core.graph.vertex.TypeVertex)

Example 12 with Relation

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);
}
Also used : Relation(com.vaticle.typedb.core.concept.thing.Relation) Attribute(com.vaticle.typedb.core.concept.thing.Attribute) When(io.cucumber.java.en.When)

Example 13 with 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))))));
}
Also used : Relation(com.vaticle.typedb.core.concept.thing.Relation) Then(io.cucumber.java.en.Then)

Example 14 with Relation

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);
}
Also used : Relation(com.vaticle.typedb.core.concept.thing.Relation) Attribute(com.vaticle.typedb.core.concept.thing.Attribute) When(io.cucumber.java.en.When)

Example 15 with 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))))));
}
Also used : Relation(com.vaticle.typedb.core.concept.thing.Relation) Then(io.cucumber.java.en.Then)

Aggregations

Relation (com.vaticle.typedb.core.concept.thing.Relation)15 Thing (com.vaticle.typedb.core.concept.thing.Thing)9 Concept (com.vaticle.typedb.core.concept.Concept)7 ConceptMap (com.vaticle.typedb.core.concept.answer.ConceptMap)7 Variable (com.vaticle.typedb.core.traversal.common.Identifier.Variable)7 HashMap (java.util.HashMap)7 HashSet (java.util.HashSet)7 Test (org.junit.Test)7 RoleType (com.vaticle.typedb.core.concept.type.RoleType)5 RelationType (com.vaticle.typedb.core.concept.type.RelationType)4 Rule (com.vaticle.typedb.core.logic.Rule)4 Util.createRule (com.vaticle.typedb.core.logic.resolvable.Util.createRule)4 Map (java.util.Map)4 TypeDBException (com.vaticle.typedb.core.common.exception.TypeDBException)3 FunctionalIterator (com.vaticle.typedb.core.common.iterator.FunctionalIterator)3 AttributeType (com.vaticle.typedb.core.concept.type.AttributeType)3 Type (com.vaticle.typedb.core.concept.type.Type)3 Set (java.util.Set)3 Lists (com.google.common.collect.Lists)2 Collections.list (com.vaticle.typedb.common.collection.Collections.list)2