use of com.vaticle.typedb.core.pattern.Disjunction in project grakn by graknlabs.
the class TypeInferenceTest method overridden_relates_are_valid.
@Test
public void overridden_relates_are_valid() {
define_custom_schema("define" + " marriage sub relation, relates spouse;" + " hetero-marriage sub marriage," + " relates husband as spouse, relates wife as spouse;" + " person sub entity, plays marriage:spouse, plays hetero-marriage:husband," + " plays hetero-marriage:wife;");
TypeInference typeInference = transaction.logic().typeInference();
String queryString = "match $m (spouse: $x, spouse: $y) isa marriage;";
Disjunction disjunction = createDisjunction(queryString);
typeInference.applyCombination(disjunction);
Map<String, Set<String>> expected = new HashMap<>() {
{
put("$x", set("person"));
put("$y", set("person"));
put("$m", set("marriage", "hetero-marriage"));
put("$_marriage:spouse", set("marriage:spouse"));
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 multiple_anonymous_vars.
@Test
public void multiple_anonymous_vars() throws IOException {
define_standard_schema("basic-schema");
String queryString = "match $a has name 'fido'; $a has label 'poodle';";
TypeInference typeInference = transaction.logic().typeInference();
Disjunction disjunction = createDisjunction(queryString);
typeInference.applyCombination(disjunction);
Map<String, Set<String>> expected = new HashMap<>() {
{
put("$a", set("dog"));
put("$_name", set("name"));
put("$_label", set("label"));
put("$_0", set("name"));
put("$_1", set("label"));
}
};
assertEquals(expected, resolvedTypeMap(disjunction.conjunctions().get(0)));
}
use of com.vaticle.typedb.core.pattern.Disjunction in project grakn by graknlabs.
the class Reasoner method mayReason.
private boolean mayReason(Disjunction disjunction) {
for (Conjunction conj : disjunction.conjunctions()) {
Set<Variable> vars = conj.variables();
List<Negation> negs = conj.negations();
if (iterate(vars).flatMap(v -> iterate(v.inferredTypes())).distinct().anyMatch(this::hasRule))
return true;
if (!negs.isEmpty() && iterate(negs).anyMatch(n -> mayReason(n.disjunction())))
return true;
}
return false;
}
use of com.vaticle.typedb.core.pattern.Disjunction 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.pattern.Disjunction 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)));
}
Aggregations