use of com.vaticle.typedb.core.logic.tool.TypeInference in project grakn by graknlabs.
the class TypeInferenceTest method plays_hierarchy.
@Test
public void plays_hierarchy() throws IOException {
define_standard_schema("basic-schema");
TypeInference typeInference = transaction.logic().typeInference();
String queryString = "match (spouse: $john) isa marriage;";
Disjunction disjunction = createDisjunction(queryString);
typeInference.applyCombination(disjunction);
Map<String, Set<String>> expected = new HashMap<>() {
{
put("$john", set("person", "man", "woman"));
put("$_0", set("marriage"));
put("$_marriage:spouse", set("marriage:spouse"));
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 matching_rp_in_relation_that_cant_play_that_role_sets_conjunction_not_satisfiable.
@Test
public void matching_rp_in_relation_that_cant_play_that_role_sets_conjunction_not_satisfiable() throws IOException {
define_standard_schema("test-type-inference");
TypeInference typeInference = transaction.logic().typeInference();
String queryString = "match " + " $x isa company;" + " ($x) isa friendship;";
Disjunction disjunction = createDisjunction(queryString);
typeInference.applyCombination(disjunction);
assertFalse(disjunction.isCoherent());
}
use of com.vaticle.typedb.core.logic.tool.TypeInference in project grakn by graknlabs.
the class TypeInferenceTest method branched_isa.
@Test
public void branched_isa() throws IOException {
define_custom_schema("define" + " person sub entity;" + " man sub person, owns man-name;" + " woman sub person, owns woman-name;" + " man-name sub attribute, value string;" + " woman-name sub attribute, value string;" + "");
TypeInference typeInference = transaction.logic().typeInference();
String queryString = "match $x isa $t; $y isa $t; $x has man-name 'bob'; $y has woman-name 'alice';";
Disjunction disjunction = createDisjunction(queryString);
typeInference.applyCombination(disjunction);
Map<String, Set<String>> expectedExhaustive = new HashMap<>() {
{
put("$x", set("man"));
put("$y", set("woman"));
put("$t", set("thing", "entity", "person"));
put("$_0", set("man-name"));
put("$_1", set("woman-name"));
put("$_man-name", set("man-name"));
put("$_woman-name", set("woman-name"));
}
};
assertEquals(expectedExhaustive, resolvedTypeMap(disjunction.conjunctions().get(0)));
}
use of com.vaticle.typedb.core.logic.tool.TypeInference in project grakn by graknlabs.
the class TypeInferenceTest method infer_is_attribute_from_having_value.
@Test
public void infer_is_attribute_from_having_value() throws IOException {
define_standard_schema("test-type-inference");
TypeInference typeInference = transaction.logic().typeInference();
String queryString = "match $x = $y;";
Disjunction disjunction = createDisjunction(queryString);
typeInference.applyCombination(disjunction);
Map<String, Set<String>> expected = new HashMap<>() {
{
put("$x", set("name", "age", "ref"));
put("$y", set("name", "age", "ref"));
}
};
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 role_labels_reduced_by_full_type_resolver.
@Test
public void role_labels_reduced_by_full_type_resolver() {
define_custom_schema("define" + " person sub entity, plays partnership:partner;" + " partnership sub relation, relates partner;" + " business sub relation, relates partner;");
TypeInference typeInference = transaction.logic().typeInference();
String queryString = "match (partner: $x);";
Disjunction disjunction = createDisjunction(queryString);
Conjunction conjunction = disjunction.conjunctions().get(0);
typeInference.applyCombination(conjunction, false);
Set<String> expectedResolvedTypes = set("partnership:partner");
assertEquals(expectedResolvedTypes, resolvedTypeMap(disjunction.conjunctions().get(0)).get("$_relation:partner"));
}
Aggregations