Search in sources :

Example 1 with VariableRegistry

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

the class Updater method create.

public static Updater create(Reasoner reasoner, ConceptManager conceptMgr, TypeQLUpdate query, Context.Query context) {
    try (FactoryTracingThreadStatic.ThreadTrace ignored = traceOnThread(TRACE_PREFIX + "create")) {
        VariableRegistry deleteRegistry = VariableRegistry.createFromThings(query.deleteVariables(), false);
        deleteRegistry.variables().forEach(Deleter::validate);
        VariableRegistry insertRegistry = VariableRegistry.createFromThings(query.insertVariables());
        insertRegistry.variables().forEach(Inserter::validate);
        assert query.match().namedVariablesUnbound().containsAll(query.namedDeleteVariablesUnbound());
        HashSet<UnboundVariable> filter = new HashSet<>(query.namedDeleteVariablesUnbound());
        filter.addAll(query.namedInsertVariablesUnbound());
        Matcher matcher = Matcher.create(reasoner, query.match().get(list(filter)));
        return new Updater(matcher, conceptMgr, deleteRegistry.things(), insertRegistry.things(), context);
    }
}
Also used : UnboundVariable(com.vaticle.typeql.lang.pattern.variable.UnboundVariable) FactoryTracingThreadStatic(com.vaticle.factory.tracing.client.FactoryTracingThreadStatic) VariableRegistry(com.vaticle.typedb.core.pattern.variable.VariableRegistry) HashSet(java.util.HashSet)

Example 2 with VariableRegistry

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

the class Deleter method create.

public static Deleter create(Reasoner reasoner, TypeQLDelete query, Context.Query context) {
    try (FactoryTracingThreadStatic.ThreadTrace ignored = traceOnThread(TRACE_PREFIX + "create")) {
        VariableRegistry registry = VariableRegistry.createFromThings(query.variables(), false);
        registry.variables().forEach(Deleter::validate);
        assert query.match().namedVariablesUnbound().containsAll(query.namedVariablesUnbound());
        Matcher matcher = Matcher.create(reasoner, query.match().get(query.namedVariablesUnbound()));
        return new Deleter(matcher, registry.things(), context);
    }
}
Also used : FactoryTracingThreadStatic(com.vaticle.factory.tracing.client.FactoryTracingThreadStatic) VariableRegistry(com.vaticle.typedb.core.pattern.variable.VariableRegistry)

Example 3 with VariableRegistry

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

the class Inserter method create.

public static Inserter create(Reasoner reasoner, ConceptManager conceptMgr, TypeQLInsert query, Context.Query context) {
    try (FactoryTracingThreadStatic.ThreadTrace ignored = traceOnThread(TRACE_PREFIX + "create")) {
        VariableRegistry registry = VariableRegistry.createFromThings(query.variables());
        registry.variables().forEach(Inserter::validate);
        Matcher matcher = null;
        if (query.match().isPresent()) {
            TypeQLMatch.Unfiltered match = query.match().get();
            List<UnboundVariable> filter = new ArrayList<>(match.namedVariablesUnbound());
            filter.retainAll(query.namedVariablesUnbound());
            assert !filter.isEmpty();
            matcher = Matcher.create(reasoner, match.get(filter));
        }
        return new Inserter(matcher, conceptMgr, registry.things(), context);
    }
}
Also used : UnboundVariable(com.vaticle.typeql.lang.pattern.variable.UnboundVariable) FactoryTracingThreadStatic(com.vaticle.factory.tracing.client.FactoryTracingThreadStatic) ArrayList(java.util.ArrayList) VariableRegistry(com.vaticle.typedb.core.pattern.variable.VariableRegistry) TypeQLMatch(com.vaticle.typeql.lang.query.TypeQLMatch)

Example 4 with VariableRegistry

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

VariableRegistry (com.vaticle.typedb.core.pattern.variable.VariableRegistry)4 FactoryTracingThreadStatic (com.vaticle.factory.tracing.client.FactoryTracingThreadStatic)3 UnboundVariable (com.vaticle.typeql.lang.pattern.variable.UnboundVariable)2 ArrayList (java.util.ArrayList)2 ThreadTrace (com.vaticle.factory.tracing.client.FactoryTracingThreadStatic.ThreadTrace)1 BoundVariable (com.vaticle.typeql.lang.pattern.variable.BoundVariable)1 TypeQLMatch (com.vaticle.typeql.lang.query.TypeQLMatch)1 HashSet (java.util.HashSet)1