Search in sources :

Example 16 with RoleType

use of com.vaticle.typedb.core.concept.type.RoleType in project grakn by graknlabs.

the class ThingTypeSteps method thing_type_set_plays_role.

@When("{root_label}\\( ?{type_label} ?) set plays role: {scoped_label}")
public void thing_type_set_plays_role(RootLabel rootLabel, String typeLabel, Parameters.ScopedLabel roleLabel) {
    RoleType roleType = tx().concepts().getRelationType(roleLabel.scope()).getRelates(roleLabel.label());
    get_thing_type(rootLabel, typeLabel).setPlays(roleType);
}
Also used : RoleType(com.vaticle.typedb.core.concept.type.RoleType) When(io.cucumber.java.en.When)

Example 17 with RoleType

use of com.vaticle.typedb.core.concept.type.RoleType in project grakn by graknlabs.

the class ThingTypeSteps method thing_type_set_plays_role_as.

@When("{root_label}\\( ?{type_label} ?) set plays role: {scoped_label} as {scoped_label}")
public void thing_type_set_plays_role_as(RootLabel rootLabel, String typeLabel, Parameters.ScopedLabel roleLabel, Parameters.ScopedLabel overriddenLabel) {
    RoleType roleType = tx().concepts().getRelationType(roleLabel.scope()).getRelates(roleLabel.label());
    RoleType overriddenType = tx().concepts().getRelationType(overriddenLabel.scope()).getRelates(overriddenLabel.label());
    get_thing_type(rootLabel, typeLabel).setPlays(roleType, overriddenType);
}
Also used : RoleType(com.vaticle.typedb.core.concept.type.RoleType) When(io.cucumber.java.en.When)

Example 18 with RoleType

use of com.vaticle.typedb.core.concept.type.RoleType 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 19 with RoleType

use of com.vaticle.typedb.core.concept.type.RoleType in project grakn by graknlabs.

the class RelationTypeImpl method setRelates.

@Override
public void setRelates(String roleLabel) {
    validateIsNotDeleted();
    TypeVertex roleTypeVertex = graphMgr.schema().getType(roleLabel, vertex.label());
    if (roleTypeVertex == null) {
        if (getSupertypes().filter(t -> !t.equals(this) && t.isRelationType()).map(TypeImpl::asRelationType).flatMap(RelationType::getRelates).anyMatch(role -> role.getLabel().name().equals(roleLabel))) {
            throw exception(TypeDBException.of(RELATION_RELATES_ROLE_FROM_SUPERTYPE, roleLabel, getLabel()));
        } else {
            RoleTypeImpl roleType = RoleTypeImpl.of(graphMgr, roleLabel, vertex.label());
            assert roleType.getSupertype() != null;
            if (this.isAbstract())
                roleType.setAbstract();
            vertex.outs().put(RELATES, roleType.vertex);
            vertex.outs().edge(RELATES, roleType.vertex).overridden(((TypeImpl) roleType.getSupertype()).vertex);
        }
    }
}
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 20 with RoleType

use of com.vaticle.typedb.core.concept.type.RoleType in project grakn by graknlabs.

the class Util method getRoleType.

public static RoleType getRoleType(Relation relation, Thing player, RelationConstraint.RolePlayer rolePlayer) {
    try (FactoryTracingThreadStatic.ThreadTrace ignored = traceOnThread(TRACE_PREFIX + "get_role_type")) {
        RoleType roleType;
        Set<? extends RoleType> inferred;
        if (rolePlayer.roleType().isPresent()) {
            RelationType relationType = relation.getType();
            TypeVariable var = rolePlayer.roleType().get();
            if ((roleType = relationType.getRelates(var.label().get().label())) == null) {
                throw TypeDBException.of(TYPE_NOT_FOUND, Label.of(var.label().get().label(), relationType.getLabel().name()));
            }
        } else if ((inferred = player.getType().getPlays().filter(rt -> rt.getRelationType().equals(relation.getType())).toSet()).size() == 1) {
            roleType = inferred.iterator().next();
        } else if (inferred.size() > 1) {
            throw TypeDBException.of(ROLE_TYPE_AMBIGUOUS, rolePlayer.player().reference());
        } else {
            throw TypeDBException.of(ROLE_TYPE_MISSING, rolePlayer.player().reference());
        }
        return roleType;
    }
}
Also used : TypeVariable(com.vaticle.typedb.core.pattern.variable.TypeVariable) RoleType(com.vaticle.typedb.core.concept.type.RoleType) FactoryTracingThreadStatic(com.vaticle.factory.tracing.client.FactoryTracingThreadStatic) RelationType(com.vaticle.typedb.core.concept.type.RelationType)

Aggregations

RoleType (com.vaticle.typedb.core.concept.type.RoleType)21 RelationType (com.vaticle.typedb.core.concept.type.RelationType)11 AttributeType (com.vaticle.typedb.core.concept.type.AttributeType)7 TypeDB (com.vaticle.typedb.core.TypeDB)6 EntityType (com.vaticle.typedb.core.concept.type.EntityType)5 When (io.cucumber.java.en.When)5 List (java.util.List)5 FunctionalIterator (com.vaticle.typedb.core.common.iterator.FunctionalIterator)4 Relation (com.vaticle.typedb.core.concept.thing.Relation)4 ThingType (com.vaticle.typedb.core.concept.type.ThingType)4 Test (org.junit.Test)4 TypeDBException (com.vaticle.typedb.core.common.exception.TypeDBException)3 ThreadTrace (com.vaticle.factory.tracing.client.FactoryTracingThreadStatic.ThreadTrace)2 MB (com.vaticle.typedb.core.common.collection.Bytes.MB)2 TYPE_ROOT_MISMATCH (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeRead.TYPE_ROOT_MISMATCH)2 RELATION_ABSTRACT_ROLE (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.RELATION_ABSTRACT_ROLE)2 RELATION_NO_ROLE (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.RELATION_NO_ROLE)2 RELATION_RELATES_ROLE_FROM_SUPERTYPE (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.RELATION_RELATES_ROLE_FROM_SUPERTYPE)2 RELATION_RELATES_ROLE_NOT_AVAILABLE (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.RELATION_RELATES_ROLE_NOT_AVAILABLE)2 ROOT_TYPE_MUTATION (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.ROOT_TYPE_MUTATION)2