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