Search in sources :

Example 31 with TypeInference

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

the class TypeInferenceTest method test_type_var_with_label.

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

        {
            put("$t", 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)

Example 32 with TypeInference

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

the class TypeInferenceTest method relation_multiple_roles.

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

        {
            put("$yoko", set("person", "man", "woman"));
            put("$john", set("man"));
            put("$role", set("marriage:husband", "marriage:wife", "marriage:spouse", "relation:role"));
            put("$r", set("marriage"));
            put("$a", set("person", "man", "woman"));
            put("$_marriage:husband", set("marriage:husband"));
            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 33 with TypeInference

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

the class TypeInferenceTest method hierarchy_hint_gap.

// When a hint label exists, it can "skip" a generation, meaning a hint and the hint's descendent is possible, yet
// none of the hint's direct children are possible.
// We show this below on the hint labels of $t
// We also show on $a that hints can be isolated form each other completely hierarchy-wise.
@Test
// TODO: ignored as the gap doesn't appear. Unclear if this is a resolver or traversal bug.
@Ignore
public void hierarchy_hint_gap() throws IOException {
    define_custom_schema("define " + "  animal sub entity;" + "  left-attr sub attribute, value boolean;" + "  right-attr sub attribute, value boolean;" + "  ownership-attr sub attribute, value boolean;" + "  marriage-attr sub attribute, value boolean;" + "  animal sub entity, owns ownership-attr; " + "  mammal sub animal; " + "  person sub mammal, plays ownership:owner, owns marriage-attr; " + "  man sub person, plays marriage:husband, owns left-attr; " + "  woman sub person, plays marriage:wife, owns right-attr; " + "  tortoise sub animal, plays ownership:pet, owns left-attr; " + "  marriage sub relation, relates husband, relates wife, owns marriage-attr; " + "  ownership sub relation, relates pet, relates owner, owns ownership-attr;");
    TypeInference typeInference = transaction.logic().typeInference();
    String queryString = "match " + "  $a isa $t; " + "  $b isa $t; " + "  $t owns $c; " + "  $t sub entity; " + "  ($a, $b) isa $rel; " + "  $rel owns $c; " + "  $a has left-attr true; " + "  $b has right-attr true;";
    Disjunction disjunction = createDisjunction(queryString);
    typeInference.applyCombination(disjunction);
    Map<String, Set<String>> expected = new HashMap<>() {

        {
            put("$t", set("animal", "person"));
            put("$a", set("tortoise", "man"));
            put("$b", set("woman"));
            put("$rel", set("ownership", "marriage"));
            put("$c", set("ownership-attr", "marriage-attr"));
        }
    };
    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) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 34 with TypeInference

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

the class TypeInferenceTest method no_role_type.

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

        {
            put("$yoko", set("man", "woman", "person"));
            put("$_0", set("marriage"));
            put("$_marriage", set("marriage"));
        }
    };
    assertEquals(expected, resolvedTypeMap(disjunction.conjunctions().get(0)));
    Map<String, Set<String>> expectedRPTypes = new HashMap<>() {

        {
            put("$yoko", set("marriage:spouse", "marriage:wife", "marriage:husband"));
        }
    };
    assertEquals(expectedRPTypes, resolvedRoleTypeMap(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 TypeInference

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

the class TypeInferenceTest method has_with_minimal_cycle.

@Test
public void has_with_minimal_cycle() {
    define_custom_schema("define " + "unit sub attribute, value string, owns unit, owns ref;" + "ref sub attribute, value long;");
    TypeInference typeInference = transaction.logic().typeInference();
    String queryString = "match" + "  $a has $a;";
    Disjunction disjunction = createDisjunction(queryString);
    typeInference.applyCombination(disjunction);
    Map<String, Set<String>> expectedExhaustive = new HashMap<>() {

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

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