Search in sources :

Example 31 with Disjunction

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

the class TypeInferenceTest method matching_rp_in_relation_that_cant_play_that_role_sets_conjunction_not_satisfiable.

@Test
public void matching_rp_in_relation_that_cant_play_that_role_sets_conjunction_not_satisfiable() throws IOException {
    define_standard_schema("test-type-inference");
    TypeInference typeInference = transaction.logic().typeInference();
    String queryString = "match " + " $x isa company;" + " ($x) isa friendship;";
    Disjunction disjunction = createDisjunction(queryString);
    typeInference.applyCombination(disjunction);
    assertFalse(disjunction.isCoherent());
}
Also used : TypeInference(com.vaticle.typedb.core.logic.tool.TypeInference) Disjunction(com.vaticle.typedb.core.pattern.Disjunction) Test(org.junit.Test)

Example 32 with Disjunction

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

the class Util method resolvedDisjunction.

public static Disjunction resolvedDisjunction(String query, LogicManager logicMgr) {
    Disjunction disjunction = Disjunction.create(TypeQL.parsePattern(query).asConjunction().normalise());
    logicMgr.typeInference().applyCombination(disjunction);
    return disjunction;
}
Also used : Disjunction(com.vaticle.typedb.core.pattern.Disjunction)

Example 33 with Disjunction

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

the class ResolutionTest method createRootAndAssertResponses.

private void createRootAndAssertResponses(CoreTransaction transaction, Disjunction disjunction, Set<Identifier.Variable.Retrievable> filter, long answerCount, long explainableAnswers) throws InterruptedException {
    ResolverRegistry registry = transaction.reasoner().resolverRegistry();
    LinkedBlockingQueue<Match.Finished> responses = new LinkedBlockingQueue<>();
    AtomicLong doneReceived = new AtomicLong(0L);
    Actor.Driver<RootResolver.Disjunction> root;
    try {
        root = registry.root(disjunction, responses::add, iterDone -> doneReceived.incrementAndGet(), (throwable) -> fail());
    } catch (TypeDBException e) {
        fail();
        return;
    }
    assertResponses(root, filter, responses, doneReceived, answerCount, explainableAnswers);
}
Also used : Util.resolvedConjunction(com.vaticle.typedb.core.reasoner.resolution.Util.resolvedConjunction) Collections.set(com.vaticle.typedb.common.collection.Collections.set) Variable(com.vaticle.typedb.core.pattern.variable.Variable) Identifier(com.vaticle.typedb.core.traversal.common.Identifier) MB(com.vaticle.typedb.core.common.collection.Bytes.MB) Arguments(com.vaticle.typedb.core.common.parameters.Arguments) HashSet(java.util.HashSet) Root(com.vaticle.typedb.core.reasoner.resolution.answer.AnswerState.Partial.Compound.Root) Util.resolvedDisjunction(com.vaticle.typedb.core.reasoner.resolution.Util.resolvedDisjunction) After(org.junit.After) InitialImpl(com.vaticle.typedb.core.reasoner.resolution.answer.AnswerStateImpl.TopImpl.MatchImpl.InitialImpl) Assert.fail(org.junit.Assert.fail) Path(java.nio.file.Path) Before(org.junit.Before) Conjunction(com.vaticle.typedb.core.pattern.Conjunction) TypeQL(com.vaticle.typeql.lang.TypeQL) CoreDatabaseManager(com.vaticle.typedb.core.database.CoreDatabaseManager) Set(java.util.Set) ConceptMap(com.vaticle.typedb.core.concept.answer.ConceptMap) Test(org.junit.Test) IOException(java.io.IOException) RootResolver(com.vaticle.typedb.core.reasoner.resolution.resolver.RootResolver) Actor(com.vaticle.typedb.core.concurrent.actor.Actor) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Disjunction(com.vaticle.typedb.core.pattern.Disjunction) TimeUnit(java.util.concurrent.TimeUnit) CoreSession(com.vaticle.typedb.core.database.CoreSession) AtomicLong(java.util.concurrent.atomic.AtomicLong) Stream(java.util.stream.Stream) NamedThreadFactory(com.vaticle.typedb.common.concurrent.NamedThreadFactory) Paths(java.nio.file.Paths) TestCase.assertTrue(junit.framework.TestCase.assertTrue) ActorExecutorGroup(com.vaticle.typedb.core.concurrent.actor.ActorExecutorGroup) Database(com.vaticle.typedb.core.common.parameters.Options.Database) Iterators.iterate(com.vaticle.typedb.core.common.iterator.Iterators.iterate) TypeDBException(com.vaticle.typedb.core.common.exception.TypeDBException) Request(com.vaticle.typedb.core.reasoner.resolution.framework.Request) CoreTransaction(com.vaticle.typedb.core.database.CoreTransaction) Match(com.vaticle.typedb.core.reasoner.resolution.answer.AnswerState.Top.Match) Resolver(com.vaticle.typedb.core.reasoner.resolution.framework.Resolver) Util(com.vaticle.typedb.core.test.integration.util.Util) TestCase.assertEquals(junit.framework.TestCase.assertEquals) AtomicLong(java.util.concurrent.atomic.AtomicLong) Util.resolvedDisjunction(com.vaticle.typedb.core.reasoner.resolution.Util.resolvedDisjunction) Disjunction(com.vaticle.typedb.core.pattern.Disjunction) Actor(com.vaticle.typedb.core.concurrent.actor.Actor) TypeDBException(com.vaticle.typedb.core.common.exception.TypeDBException) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Example 34 with Disjunction

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

the class TypeInferenceTest method branched_isa.

@Test
public void branched_isa() throws IOException {
    define_custom_schema("define" + "  person sub entity;" + "  man sub person, owns man-name;" + "  woman sub person, owns woman-name;" + "  man-name sub attribute, value string;" + "  woman-name sub attribute, value string;" + "");
    TypeInference typeInference = transaction.logic().typeInference();
    String queryString = "match $x isa $t; $y isa $t; $x has man-name 'bob'; $y has woman-name 'alice';";
    Disjunction disjunction = createDisjunction(queryString);
    typeInference.applyCombination(disjunction);
    Map<String, Set<String>> expectedExhaustive = new HashMap<>() {

        {
            put("$x", set("man"));
            put("$y", set("woman"));
            put("$t", set("thing", "entity", "person"));
            put("$_0", set("man-name"));
            put("$_1", set("woman-name"));
            put("$_man-name", set("man-name"));
            put("$_woman-name", set("woman-name"));
        }
    };
    assertEquals(expectedExhaustive, resolvedTypeMap(disjunction.conjunctions().get(0)));
}
Also used : TypeInference(com.vaticle.typedb.core.logic.tool.TypeInference) Disjunction(com.vaticle.typedb.core.pattern.Disjunction) Set(java.util.Set) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 35 with Disjunction

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

the class TypeInferenceTest method infer_is_attribute_from_having_value.

@Test
public void infer_is_attribute_from_having_value() throws IOException {
    define_standard_schema("test-type-inference");
    TypeInference typeInference = transaction.logic().typeInference();
    String queryString = "match $x = $y;";
    Disjunction disjunction = createDisjunction(queryString);
    typeInference.applyCombination(disjunction);
    Map<String, Set<String>> expected = new HashMap<>() {

        {
            put("$x", set("name", "age", "ref"));
            put("$y", set("name", "age", "ref"));
        }
    };
    assertEquals(expected, resolvedTypeMap(disjunction.conjunctions().get(0)));
}
Also used : TypeInference(com.vaticle.typedb.core.logic.tool.TypeInference) Disjunction(com.vaticle.typedb.core.pattern.Disjunction) Set(java.util.Set) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

Disjunction (com.vaticle.typedb.core.pattern.Disjunction)57 Test (org.junit.Test)50 Set (java.util.Set)44 HashMap (java.util.HashMap)43 TypeInference (com.vaticle.typedb.core.logic.tool.TypeInference)42 Conjunction (com.vaticle.typedb.core.pattern.Conjunction)5 TypeDBException (com.vaticle.typedb.core.common.exception.TypeDBException)4 Identifier (com.vaticle.typedb.core.traversal.common.Identifier)4 Collections.set (com.vaticle.typedb.common.collection.Collections.set)3 FunctionalIterator (com.vaticle.typedb.core.common.iterator.FunctionalIterator)3 Iterators.iterate (com.vaticle.typedb.core.common.iterator.Iterators.iterate)3 ConceptMap (com.vaticle.typedb.core.concept.answer.ConceptMap)3 CoreTransaction (com.vaticle.typedb.core.database.CoreTransaction)3 Variable (com.vaticle.typedb.core.pattern.variable.Variable)3 Collections.list (com.vaticle.typedb.common.collection.Collections.list)2 Iterators (com.vaticle.typedb.core.common.iterator.Iterators)2 Arguments (com.vaticle.typedb.core.common.parameters.Arguments)2 Context (com.vaticle.typedb.core.common.parameters.Context)2 Label (com.vaticle.typedb.core.common.parameters.Label)2 ConceptManager (com.vaticle.typedb.core.concept.ConceptManager)2