Search in sources :

Example 46 with Disjunction

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

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

Example 48 with Disjunction

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

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

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

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