Search in sources :

Example 41 with Disjunction

use of com.vaticle.typedb.core.pattern.Disjunction 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)

Example 42 with Disjunction

use of com.vaticle.typedb.core.pattern.Disjunction 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 43 with Disjunction

use of com.vaticle.typedb.core.pattern.Disjunction 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 44 with Disjunction

use of com.vaticle.typedb.core.pattern.Disjunction 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 45 with Disjunction

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

the class TypeInferenceTest method variable_types_are_inferred.

@Test
public void variable_types_are_inferred() {
    define_custom_schema("define " + "person sub entity," + "    owns first-name," + "    owns last-name," + "    owns age," + "    plays employment:employee;" + "company sub entity," + "    plays employment:employer;" + "employment sub relation," + "    relates employee," + "    relates employer;" + "name sub attribute, value string, abstract;" + "first-name sub name;" + "last-name sub name;" + "age sub attribute, value long;");
    String query = "match $x isa $rel-type; $rel-type relates $role-type; $role-type type employment:employee;";
    Disjunction disjunction = createDisjunction(query);
    transaction.logic().typeInference().applyCombination(disjunction);
    HashMap<String, Set<String>> expected = new HashMap<>() {

        {
            put("$x", set("employment"));
            put("$rel-type", set("employment"));
            put("$role-type", set("employment:employee"));
        }
    };
    assertEquals(expected, resolvedTypeMap(disjunction.conjunctions().get(0)));
    query = "match $x isa $t; $t plays $role-type; $role-type type employment:employee;";
    disjunction = createDisjunction(query);
    transaction.logic().typeInference().applyCombination(disjunction);
    expected = new HashMap<>() {

        {
            put("$x", set("person"));
            put("$t", set("person"));
            put("$role-type", set("employment:employee"));
        }
    };
    assertEquals(expected, resolvedTypeMap(disjunction.conjunctions().get(0)));
}
Also used : 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