Search in sources :

Example 6 with TypeVariable

use of com.vaticle.typedb.core.pattern.variable.TypeVariable in project grakn by graknlabs.

the class PlaysConstraint method of.

static PlaysConstraint of(TypeVariable owner, com.vaticle.typeql.lang.pattern.constraint.TypeConstraint.Plays constraint, VariableRegistry registry) {
    TypeVariable roleType = registry.register(constraint.role());
    TypeVariable relationType = constraint.relation().map(registry::register).orElse(null);
    TypeVariable overriddenType = constraint.overridden().map(registry::register).orElse(null);
    return new PlaysConstraint(owner, relationType, roleType, overriddenType);
}
Also used : TypeVariable(com.vaticle.typedb.core.pattern.variable.TypeVariable)

Example 7 with TypeVariable

use of com.vaticle.typedb.core.pattern.variable.TypeVariable in project grakn by graknlabs.

the class RelatesConstraint method of.

static RelatesConstraint of(TypeVariable owner, com.vaticle.typeql.lang.pattern.constraint.TypeConstraint.Relates constraint, VariableRegistry registry) {
    TypeVariable roleType = registry.register(constraint.role());
    TypeVariable overriddenRoleType = constraint.overridden().map(registry::register).orElse(null);
    return new RelatesConstraint(owner, roleType, overriddenRoleType);
}
Also used : TypeVariable(com.vaticle.typedb.core.pattern.variable.TypeVariable)

Example 8 with TypeVariable

use of com.vaticle.typedb.core.pattern.variable.TypeVariable 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

TypeVariable (com.vaticle.typedb.core.pattern.variable.TypeVariable)8 FactoryTracingThreadStatic (com.vaticle.factory.tracing.client.FactoryTracingThreadStatic)1 RelationType (com.vaticle.typedb.core.concept.type.RelationType)1 RoleType (com.vaticle.typedb.core.concept.type.RoleType)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1