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)));
}
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)));
}
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)));
}
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)));
}
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)));
}
Aggregations