Search in sources :

Example 6 with Concludable

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));
}
Also used : Concludable(com.vaticle.typedb.core.logic.resolvable.Concludable) Resolvable(com.vaticle.typedb.core.logic.resolvable.Resolvable) Test(org.junit.Test)

Example 7 with Concludable

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));
}
Also used : Concludable(com.vaticle.typedb.core.logic.resolvable.Concludable) Resolvable(com.vaticle.typedb.core.logic.resolvable.Resolvable) Test(org.junit.Test)

Example 8 with Concludable

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));
}
Also used : Concludable(com.vaticle.typedb.core.logic.resolvable.Concludable) Actor(com.vaticle.typedb.core.concurrent.actor.Actor) AlphaEquivalence(com.vaticle.typedb.core.pattern.equivalence.AlphaEquivalence) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcludableResolver(com.vaticle.typedb.core.reasoner.resolution.resolver.ConcludableResolver)

Example 9 with 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;
}
Also used : Concludable(com.vaticle.typedb.core.logic.resolvable.Concludable) Retrievable(com.vaticle.typedb.core.logic.resolvable.Retrievable) Negation(com.vaticle.typedb.core.pattern.Negation) Negated(com.vaticle.typedb.core.logic.resolvable.Negated) TypeDBException(com.vaticle.typedb.core.common.exception.TypeDBException)

Aggregations

Concludable (com.vaticle.typedb.core.logic.resolvable.Concludable)9 Resolvable (com.vaticle.typedb.core.logic.resolvable.Resolvable)7 Test (org.junit.Test)7 Retrievable (com.vaticle.typedb.core.logic.resolvable.Retrievable)4 TypeDBException (com.vaticle.typedb.core.common.exception.TypeDBException)1 AttributeType (com.vaticle.typedb.core.concept.type.AttributeType)1 EntityType (com.vaticle.typedb.core.concept.type.EntityType)1 Actor (com.vaticle.typedb.core.concurrent.actor.Actor)1 Negated (com.vaticle.typedb.core.logic.resolvable.Negated)1 Negation (com.vaticle.typedb.core.pattern.Negation)1 AlphaEquivalence (com.vaticle.typedb.core.pattern.equivalence.AlphaEquivalence)1 ConcludableResolver (com.vaticle.typedb.core.reasoner.resolution.resolver.ConcludableResolver)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Collectors.toMap (java.util.stream.Collectors.toMap)1