Search in sources :

Example 1 with UnboundVariable

use of com.vaticle.typeql.lang.pattern.variable.UnboundVariable 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 UnboundVariable

use of com.vaticle.typeql.lang.pattern.variable.UnboundVariable 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)

Aggregations

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