Search in sources :

Example 1 with TypeInference

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

the class TypeInferenceTest method infers_value_type_recursively.

@Test
public void infers_value_type_recursively() throws IOException {
    define_standard_schema("basic-schema");
    TypeInference typeInference = transaction.logic().typeInference();
    String queryString = "match " + " $x = $y;" + " $y = $z;" + " $z = $w;" + " $w = 1;";
    Disjunction disjunction = createDisjunction(queryString);
    typeInference.applyCombination(disjunction);
    Map<String, Set<String>> expected = new HashMap<>() {

        {
            put("$x", set("perimeter", "area", "hypotenuse-length"));
            put("$y", set("perimeter", "area", "hypotenuse-length"));
            put("$z", set("perimeter", "area", "hypotenuse-length"));
            put("$w", set("perimeter", "area", "hypotenuse-length"));
        }
    };
    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 2 with TypeInference

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

the class TypeInferenceTest method all_things_is_empty_set.

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

        {
            put("$x", set("animal", "mammal", "reptile", "tortoise", "person", "man", "woman", "dog", "name", "email", "marriage", "triangle", "right-angled-triangle", "square", "perimeter", "area", "hypotenuse-length", "label"));
            put("$_thing", set("thing"));
        }
    };
    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 3 with TypeInference

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

the class TypeInferenceTest method multiple_value_types_returns_unsatisfiable_error.

@Test
public void multiple_value_types_returns_unsatisfiable_error() throws IOException {
    define_standard_schema("basic-schema");
    TypeInference typeInference = transaction.logic().typeInference();
    String queryString = "match $x = 2; $x = 'bob';";
    Disjunction disjunction = createDisjunction(queryString);
    assertThrows(() -> typeInference.applyCombination(disjunction));
}
Also used : TypeInference(com.vaticle.typedb.core.logic.tool.TypeInference) Disjunction(com.vaticle.typedb.core.pattern.Disjunction) Test(org.junit.Test)

Example 4 with TypeInference

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

the class TypeInferenceTest method converts_root_types.

@Test
public void converts_root_types() throws IOException {
    define_standard_schema("test-type-inference");
    TypeInference typeInference = transaction.logic().typeInference();
    String relationString = "match $x isa relation;";
    Disjunction relationDisjunction = createDisjunction(relationString);
    typeInference.applyCombination(relationDisjunction);
    Map<String, Set<String>> relationExpected = new HashMap<>() {

        {
            put("$x", set("friendship", "employment"));
            put("$_relation", set("relation"));
        }
    };
    assertEquals(relationExpected, resolvedTypeMap(relationDisjunction.conjunctions().get(0)));
    String attributeString = "match $x isa attribute;";
    Disjunction attributeDisjunction = createDisjunction(attributeString);
    typeInference.applyCombination(attributeDisjunction);
    Map<String, Set<String>> attributeExpected = new HashMap<>() {

        {
            put("$x", set("name", "age", "ref"));
            put("$_attribute", set("attribute"));
        }
    };
    assertEquals(attributeExpected, resolvedTypeMap(attributeDisjunction.conjunctions().get(0)));
    String entityString = "match $x isa entity;";
    Disjunction entityDisjunction = createDisjunction(entityString);
    typeInference.applyCombination(entityDisjunction);
    Map<String, Set<String>> entityExpected = new HashMap<>() {

        {
            put("$x", set("person", "company"));
            put("$_entity", set("entity"));
        }
    };
    assertEquals(entityExpected, resolvedTypeMap(entityDisjunction.conjunctions().get(0)));
    String roleString = "match ($role: $x) isa relation;";
    Disjunction roleDisjunction = createDisjunction(roleString);
    typeInference.applyCombination(roleDisjunction);
    Map<String, Set<String>> roleExpected = new HashMap<>() {

        {
            put("$role", set("friendship:friend", "employment:employer", "employment:employee", "relation:role"));
            put("$x", set("person", "company"));
            put("$_0", set("friendship", "employment"));
            put("$_relation", set("relation"));
        }
    };
    assertEquals(roleExpected, resolvedTypeMap(roleDisjunction.conjunctions().get(0)));
    String thingString = "match $x isa thing;";
    Disjunction thingDisjunction = createDisjunction(thingString);
    typeInference.applyCombination(thingDisjunction);
    Map<String, Set<String>> thingExpected = new HashMap<>() {

        {
            put("$x", set("person", "company", "friendship", "employment", "name", "age", "ref"));
            put("$_thing", set("thing"));
        }
    };
    assertEquals(thingExpected, resolvedTypeMap(thingDisjunction.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 5 with TypeInference

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

the class TypeInferenceTest method up_down_hierarchy_isa.

@Test
public void up_down_hierarchy_isa() {
    define_custom_schema("define" + "  animal sub entity;" + "  person sub animal;" + "  man sub person;" + "  greek sub man;" + "  socrates sub greek;");
    TypeInference typeInference = transaction.logic().typeInference();
    String queryString = "match" + "  $p isa man;" + "  man sub $q;";
    Disjunction disjunction = createDisjunction(queryString);
    typeInference.applyCombination(disjunction);
    Map<String, Set<String>> expected = new HashMap<>() {

        {
            put("$p", set("man", "greek", "socrates"));
            put("$q", set("thing", "entity", "animal", "person", "man"));
            put("$_man", set("man"));
        }
    };
    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