Search in sources :

Example 1 with BoundVariable

use of com.vaticle.typeql.lang.pattern.variable.BoundVariable in project grakn by graknlabs.

the class Conjunction method create.

public static Conjunction create(com.vaticle.typeql.lang.pattern.Conjunction<Conjunctable> typeql, @Nullable VariableRegistry bounds) {
    try (ThreadTrace ignored = traceOnThread(TRACE_PREFIX + "create")) {
        List<BoundVariable> typeQLVariables = new ArrayList<>();
        List<com.vaticle.typeql.lang.pattern.Negation<?>> typeQLNegations = new ArrayList<>();
        typeql.patterns().forEach(conjunctable -> {
            if (conjunctable.isVariable())
                typeQLVariables.add(conjunctable.asVariable());
            else if (conjunctable.isNegation())
                typeQLNegations.add(conjunctable.asNegation());
            else
                throw TypeDBException.of(ILLEGAL_STATE);
        });
        if (typeQLVariables.isEmpty() && !typeQLNegations.isEmpty())
            throw TypeDBException.of(UNBOUNDED_NEGATION);
        VariableRegistry registry = VariableRegistry.createFromVariables(typeQLVariables, bounds);
        List<Negation> typeDBNegations = typeQLNegations.isEmpty() ? list() : typeQLNegations.stream().map(n -> Negation.create(n, registry)).collect(toList());
        return new Conjunction(registry.variables(), typeDBNegations);
    }
}
Also used : BoundVariable(com.vaticle.typeql.lang.pattern.variable.BoundVariable) ArrayList(java.util.ArrayList) VariableRegistry(com.vaticle.typedb.core.pattern.variable.VariableRegistry) ThreadTrace(com.vaticle.factory.tracing.client.FactoryTracingThreadStatic.ThreadTrace)

Aggregations

ThreadTrace (com.vaticle.factory.tracing.client.FactoryTracingThreadStatic.ThreadTrace)1 VariableRegistry (com.vaticle.typedb.core.pattern.variable.VariableRegistry)1 BoundVariable (com.vaticle.typeql.lang.pattern.variable.BoundVariable)1 ArrayList (java.util.ArrayList)1