Search in sources :

Example 1 with TypeVariable

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

the class Definer method validateTypeHierarchyIsNotCyclic.

private void validateTypeHierarchyIsNotCyclic(Set<TypeVariable> variables) {
    Set<TypeVariable> visited = new HashSet<>();
    for (TypeVariable variable : variables) {
        if (visited.contains(variable))
            continue;
        assert variable.label().isPresent();
        LinkedHashSet<String> hierarchy = new LinkedHashSet<>();
        hierarchy.add(variable.label().get().scopedLabel());
        visited.add(variable);
        while (variable.sub().isPresent()) {
            variable = variable.sub().get().type();
            assert variable.label().isPresent();
            if (!hierarchy.add(variable.label().get().scopedLabel())) {
                throw TypeDBException.of(CYCLIC_TYPE_HIERARCHY, hierarchy);
            }
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) TypeVariable(com.vaticle.typedb.core.pattern.variable.TypeVariable) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 2 with TypeVariable

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

the class OwnsConstraint method of.

static OwnsConstraint of(TypeVariable owner, OwnsConstraint clone, VariableCloner cloner) {
    TypeVariable attributeType = cloner.clone(clone.attribute());
    TypeVariable overriddenType = clone.overridden().map(cloner::clone).orElse(null);
    return new OwnsConstraint(owner, attributeType, overriddenType, clone.isKey());
}
Also used : TypeVariable(com.vaticle.typedb.core.pattern.variable.TypeVariable)

Example 3 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, PlaysConstraint role, VariableCloner cloner) {
    TypeVariable roleType = cloner.clone(role.role());
    TypeVariable relationType = role.relation().map(cloner::clone).orElse(null);
    TypeVariable overriddenType = role.overridden().map(cloner::clone).orElse(null);
    return new PlaysConstraint(owner, relationType, roleType, overriddenType);
}
Also used : TypeVariable(com.vaticle.typedb.core.pattern.variable.TypeVariable)

Example 4 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, RelatesConstraint constraint, VariableCloner cloner) {
    TypeVariable roleType = cloner.clone(constraint.role());
    TypeVariable overriddenRoleType = constraint.overridden().map(cloner::clone).orElse(null);
    return new RelatesConstraint(owner, roleType, overriddenRoleType);
}
Also used : TypeVariable(com.vaticle.typedb.core.pattern.variable.TypeVariable)

Example 5 with TypeVariable

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

the class OwnsConstraint method of.

static OwnsConstraint of(TypeVariable owner, com.vaticle.typeql.lang.pattern.constraint.TypeConstraint.Owns constraint, VariableRegistry registry) {
    TypeVariable attributeType = registry.register(constraint.attribute());
    TypeVariable overriddenType = constraint.overridden().map(registry::register).orElse(null);
    return new OwnsConstraint(owner, attributeType, overriddenType, constraint.isKey());
}
Also used : TypeVariable(com.vaticle.typedb.core.pattern.variable.TypeVariable)

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