Search in sources :

Example 26 with TypeInference

use of com.vaticle.typedb.core.logic.tool.TypeInference in project grakn by graknlabs.

the class TypeInferenceTest method is_inference.

@Test
public void is_inference() throws IOException {
    define_standard_schema("basic-schema");
    TypeInference typeInference = transaction.logic().typeInference();
    String queryString = "match" + "  $p isa entity;" + "  $p is $q;" + "  $q isa mammal;";
    Disjunction disjunction = createDisjunction(queryString);
    typeInference.applyCombination(disjunction);
    Map<String, Set<String>> expectedExhaustive = new HashMap<>() {

        {
            put("$p", set("mammal", "person", "man", "woman", "dog"));
            put("$q", set("mammal", "person", "man", "woman", "dog"));
            put("$_entity", set("entity"));
            put("$_mammal", set("mammal"));
        }
    };
    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 27 with TypeInference

use of com.vaticle.typedb.core.logic.tool.TypeInference in project grakn by graknlabs.

the class TypeInferenceTest method isa_explicit_inference.

@Test
public void isa_explicit_inference() throws IOException {
    define_standard_schema("basic-schema");
    TypeInference typeInference = transaction.logic().typeInference();
    String queryString = "match $p isa! person; ";
    Disjunction disjunction = createDisjunction(queryString);
    typeInference.applyCombination(disjunction);
    Map<String, Set<String>> expected = new HashMap<>() {

        {
            put("$p", set("person"));
            put("$_person", set("person"));
        }
    };
    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)

Example 28 with TypeInference

use of com.vaticle.typedb.core.logic.tool.TypeInference in project grakn by graknlabs.

the class TypeInferenceTest method relation_concrete_role_concrete.

@Test
public void relation_concrete_role_concrete() throws IOException {
    define_standard_schema("basic-schema");
    TypeInference typeInference = transaction.logic().typeInference();
    String queryString = "match $r (wife: $yoko) isa marriage;";
    Disjunction disjunction = createDisjunction(queryString);
    typeInference.applyCombination(disjunction);
    Map<String, Set<String>> expected = new HashMap<>() {

        {
            put("$yoko", set("woman"));
            put("$r", set("marriage"));
            put("$_marriage:wife", set("marriage:wife"));
            put("$_marriage", set("marriage"));
        }
    };
    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)

Example 29 with TypeInference

use of com.vaticle.typedb.core.logic.tool.TypeInference in project grakn by graknlabs.

the class TypeInferenceTest method infers_value_cycle.

@Test
public void infers_value_cycle() throws IOException {
    define_custom_schema("define" + "  person sub entity, owns name, owns height;" + "  name sub attribute, value string, owns nickname, owns height;" + "  nickname sub attribute, value string, owns name;" + "  surname sub attribute, value string, owns name;" + "  name sub attribute, value string;" + "  surname sub attribute, value string;" + "  nickname sub attribute, value string;" + "  height sub attribute, value double, owns weight, owns name;" + "  weight sub attribute, value double, owns height;" + "  ");
    TypeInference typeInference = transaction.logic().typeInference();
    String queryString = "match " + " $x = 'bob';" + " $y = $x;" + " $x has $y;" + " $y has $x;";
    Disjunction disjunction = createDisjunction(queryString);
    typeInference.applyCombination(disjunction);
    Map<String, Set<String>> expected = new HashMap<>() {

        {
            put("$x", set("nickname", "name"));
            put("$y", set("nickname", "name"));
        }
    };
    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)

Example 30 with TypeInference

use of com.vaticle.typedb.core.logic.tool.TypeInference in project grakn by graknlabs.

the class TypeInferenceTest method schema_query_not_resolved_beyond_labels.

@Test
public void schema_query_not_resolved_beyond_labels() throws IOException {
    define_standard_schema("basic-schema");
    String queryString = "match $p sub person, owns $a;";
    TypeInference typeInference = transaction.logic().typeInference();
    Disjunction disjunction = createDisjunction(queryString);
    typeInference.applyCombination(disjunction);
    assertTrue(disjunction.isCoherent());
    Map<String, Set<String>> expected = new HashMap<>() {

        {
            put("$_person", set("person"));
            put("$p", set());
            put("$a", set());
        }
    };
    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

TypeInference (com.vaticle.typedb.core.logic.tool.TypeInference)42 Disjunction (com.vaticle.typedb.core.pattern.Disjunction)42 Test (org.junit.Test)42 HashMap (java.util.HashMap)39 Set (java.util.Set)39 Entity (com.vaticle.typedb.core.concept.thing.Entity)1 Conjunction (com.vaticle.typedb.core.pattern.Conjunction)1 Ignore (org.junit.Ignore)1