use of com.vaticle.typedb.core.logic.resolvable.Concludable in project grakn by graknlabs.
the class PlannerTest method test_planner_two_circular_has_dependencies.
@Test
public void test_planner_two_circular_has_dependencies() {
Concludable concludable = Concludable.create(resolvedConjunction("{ $a has $b; }", logicMgr)).iterator().next();
Concludable concludable2 = Concludable.create(resolvedConjunction("{ $b has $a; }", logicMgr)).iterator().next();
Set<Resolvable<?>> resolvables = set(concludable, concludable2);
List<Resolvable<?>> plan = Planner.plan(resolvables, new HashMap<>(), set());
assertEquals(2, plan.size());
assertEquals(set(concludable, concludable2), set(plan));
}
use of com.vaticle.typedb.core.logic.resolvable.Concludable in project grakn by graknlabs.
the class PlannerTest method test_planner_disconnected_conjunction.
@Test
public void test_planner_disconnected_conjunction() {
Concludable concludable = Concludable.create(resolvedConjunction("{ $a($b); }", logicMgr)).iterator().next();
Concludable concludable2 = Concludable.create(resolvedConjunction("{ $c($d); }", logicMgr)).iterator().next();
Set<Resolvable<?>> resolvables = set(concludable, concludable2);
List<Resolvable<?>> plan = Planner.plan(resolvables, new HashMap<>(), set());
assertEquals(2, plan.size());
assertEquals(set(concludable, concludable2), set(plan));
}
use of com.vaticle.typedb.core.logic.resolvable.Concludable in project grakn by graknlabs.
the class ResolverRegistry method registerConcludable.
// note: must be thread safe. We could move to a ConcurrentHashMap if we create an alpha-equivalence wrapper
private synchronized ResolverView.MappedConcludable registerConcludable(Concludable concludable) {
LOG.debug("Register ConcludableResolver: '{}'", concludable.pattern());
for (Map.Entry<Concludable, Actor.Driver<ConcludableResolver>> c : concludableResolvers.entrySet()) {
// TODO: This needs to be optimised from a linear search to use an alpha hash
AlphaEquivalence alphaEquality = concludable.alphaEquals(c.getKey());
if (alphaEquality.isValid()) {
return ResolverView.concludable(c.getValue(), alphaEquality.asValid().idMapping());
}
}
Actor.Driver<ConcludableResolver> resolver = Actor.driver(driver -> new ConcludableResolver(driver, concludable, this, traversalEngine, conceptMgr, logicMgr, resolutionTracing), executorService);
concludableResolvers.put(concludable, resolver);
resolvers.add(resolver);
// guard races without synchronized
if (terminated.get())
throw TypeDBException.of(RESOLUTION_TERMINATED);
return ResolverView.concludable(resolver, identity(concludable));
}
use of com.vaticle.typedb.core.logic.resolvable.Concludable in project grakn by graknlabs.
the class ConjunctionResolver method initialiseDownstreamResolvers.
@Override
protected void initialiseDownstreamResolvers() {
LOG.debug("{}: initialising downstream resolvers", name());
Set<Concludable> concludables = concludablesTriggeringRules();
Set<Retrievable> retrievables = Retrievable.extractFrom(conjunction(), concludables);
resolvables.addAll(concludables);
resolvables.addAll(retrievables);
iterate(resolvables).forEachRemaining(resolvable -> {
try {
downstreamResolvers.put(resolvable, registry.registerResolvable(resolvable));
} catch (TypeDBException e) {
terminate(e);
}
});
for (Negation negation : conjunction().negations()) {
Negated negated = new Negated(negation);
try {
downstreamResolvers.put(negated, registry.negated(negated, conjunction()));
negateds.add(negated);
} catch (TypeDBException e) {
terminate(e);
}
}
if (!isTerminated())
isInitialised = true;
}
Aggregations