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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations