Search in sources :

Example 36 with TypeInference

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

the class TypeInferenceTest method has_with_cycle.

@Test
public void has_with_cycle() {
    define_custom_schema("define" + "  person sub entity, owns name, owns height;" + "  name sub attribute, value string, owns nickname;" + "  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;" + "  ");
    TypeInference typeInference = transaction.logic().typeInference();
    String queryString = "match" + "  $a has $b;" + "  $b has $a;";
    Disjunction disjunction = createDisjunction(queryString);
    typeInference.applyCombination(disjunction);
    Map<String, Set<String>> expected = new HashMap<>() {

        {
            put("$a", set("nickname", "name"));
            put("$b", 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 37 with TypeInference

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

the class TypeInferenceTest method has_with_big_cycle.

@Test
public void has_with_big_cycle() {
    define_custom_schema("define" + "  person sub entity, owns name, owns height;" + "  name sub attribute, value string, owns nickname;" + "  nickname sub attribute, value string, owns surname;" + "  surname sub attribute, value string, owns middlename;" + "  middlename sub attribute, value string, owns name;" + "  weight sub attribute, value double, owns measure-system;" + "  measure-system sub attribute, value string, owns conversion-rate;" + "  conversion-rate sub attribute, value double;" + "  height sub attribute, value double;");
    TypeInference typeInference = transaction.logic().typeInference();
    String queryString = "match" + "  $a has $b;" + "  $b has $c;" + "  $c has $d;" + "  $d has $a;";
    Disjunction disjunction = createDisjunction(queryString);
    typeInference.applyCombination(disjunction);
    Map<String, Set<String>> expectedExhaustive = new HashMap<>() {

        {
            put("$a", set("name", "surname", "nickname", "middlename"));
            put("$b", set("name", "surname", "nickname", "middlename"));
            put("$c", set("name", "surname", "nickname", "middlename"));
            put("$d", set("name", "surname", "nickname", "middlename"));
        }
    };
    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 38 with TypeInference

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

the class TypeInferenceTest method has_hierarchy.

@Test
public void has_hierarchy() {
    define_custom_schema("define" + "  animal sub entity, abstract, owns weight;" + "  person sub animal, owns leg-weight as weight;" + "  chair sub entity, owns leg-weight;" + "  dog sub animal;" + "  weight sub attribute, value long, abstract;" + "  leg-weight sub weight;");
    TypeInference typeInference = transaction.logic().typeInference();
    String queryString = "match" + "  $a has weight $c;" + "  $b has leg-weight 5;" + "  $p has weight $c;";
    Disjunction disjunction = createDisjunction(queryString);
    typeInference.applyCombination(disjunction);
    Map<String, Set<String>> expected = new HashMap<>() {

        {
            put("$a", set("person", "chair"));
            put("$b", set("person", "chair"));
            put("$c", set("leg-weight"));
            put("$p", set("person", "chair"));
            put("$_0", set("leg-weight"));
            put("$_weight", set("weight"));
            put("$_leg-weight", set("leg-weight"));
        }
    };
    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 39 with TypeInference

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

the class TypeInferenceTest method negations_ignored.

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

        {
            put("$p", set("person", "man", "woman"));
            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 40 with TypeInference

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

the class TypeInferenceTest method has_inference_variable_without_attribute_type.

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

        {
            put("$p", set("triangle", "right-angled-triangle", "square"));
            put("$a", set("perimeter", "area", "label", "hypotenuse-length"));
            put("$_shape", set("shape"));
        }
    };
    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