use of com.vaticle.typedb.core.logic.tool.TypeInference in project grakn by graknlabs.
the class TypeInferenceTest method relation_staggered_role_hierarchy.
@Test
public void relation_staggered_role_hierarchy() {
define_custom_schema("define" + " person sub entity," + " plays partnership:partner," + " plays marriage:spouse;" + "" + " man sub person," + " plays hetero-marriage:husband;" + "" + " woman sub person," + " plays hetero-marriage:wife;" + "" + " partnership sub relation," + " relates partner;" + "" + " marriage sub partnership," + " relates spouse as partner;" + "" + " hetero-marriage sub marriage," + " relates husband as spouse," + " relates wife as spouse;");
TypeInference typeInference = transaction.logic().typeInference();
String queryString = "match $r (spouse: $yoko, $role: $john) isa $m; $john isa man;";
Disjunction disjunction = createDisjunction(queryString);
typeInference.applyCombination(disjunction);
Map<String, Set<String>> expected = new HashMap<>() {
{
put("$yoko", set("person", "woman", "man"));
put("$john", set("man"));
put("$role", set("hetero-marriage:husband", "marriage:spouse", "partnership:partner", "relation:role"));
put("$r", set("hetero-marriage", "marriage"));
put("$m", set("hetero-marriage", "marriage", "partnership", "relation", "thing"));
put("$_relation:spouse", set("marriage:spouse"));
put("$_man", set("man"));
}
};
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 roles_can_handle_type_constraints.
@Test
public void roles_can_handle_type_constraints() throws IOException {
define_standard_schema("basic-schema");
String queryString = "match ($role: $x) isa $y; $role type marriage:wife;";
TypeInference typeInference = transaction.logic().typeInference();
Disjunction disjunction = createDisjunction(queryString);
typeInference.applyCombination(disjunction);
HashMap<String, Set<String>> expected = new HashMap<>() {
{
put("$y", set("marriage", "relation", "thing"));
put("$x", set("woman"));
put("$role", set("marriage:wife"));
put("$_0", 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 relation_anon_isa.
@Test
public void relation_anon_isa() throws IOException {
define_standard_schema("basic-schema");
TypeInference typeInference = transaction.logic().typeInference();
String queryString = "match (wife: $yoko);";
Disjunction disjunction = createDisjunction(queryString);
typeInference.applyCombination(disjunction);
Map<String, Set<String>> expected = new HashMap<>() {
{
put("$yoko", set("woman"));
put("$_0", set("marriage"));
put("$_relation:wife", set("marriage:wife"));
}
};
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 isa_inference.
@Test
public void isa_inference() throws IOException {
define_standard_schema("basic-schema");
String queryString = "match $p isa person;";
TypeInference typeInference = transaction.logic().typeInference();
Disjunction disjunction = createDisjunction(queryString);
typeInference.applyCombination(disjunction);
Map<String, Set<String>> expected = new HashMap<>() {
{
put("$p", set("person", "man", "woman"));
put("$_person", set("person"));
}
};
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 value_comparision_between_double_long.
@Test
public void value_comparision_between_double_long() throws IOException {
define_custom_schema("define" + " house-number sub attribute, value long;" + " length sub attribute, value double;" + " name sub attribute, value string;");
TypeInference typeInference = transaction.logic().typeInference();
String queryString = "match $x = 1; $y = 1.0; $z = 'bob';";
Disjunction disjunction = createDisjunction(queryString);
typeInference.applyCombination(disjunction);
Map<String, Set<String>> expected = new HashMap<>() {
{
put("$x", set("house-number", "length"));
put("$y", set("house-number", "length"));
put("$z", set("name"));
}
};
assertEquals(expected, resolvedTypeMap(disjunction.conjunctions().get(0)));
}
Aggregations