use of com.vaticle.typedb.core.pattern.Disjunction in project grakn by graknlabs.
the class TypeInferenceTest method iid_inference.
@Test
public void iid_inference() throws IOException {
define_standard_schema("basic-schema");
transaction.commit();
session.close();
session = databaseMgr.session(database, DATA);
transaction = session.transaction(WRITE);
Entity person = transaction.concepts().getEntityType("person").create();
TypeInference typeInference = transaction.logic().typeInference();
// using a person IID, the attribute can only be a name or email, but not a dog label
String queryString = "match $p iid " + person.getIID().toHexString() + "; $p has $a;";
Disjunction disjunction = createDisjunction(queryString);
typeInference.applyCombination(disjunction);
Map<String, Set<String>> expected = new HashMap<>() {
{
put("$p", set("person"));
put("$a", set("name", "email"));
}
};
assertEquals(expected, resolvedTypeMap(disjunction.conjunctions().get(0)));
}
use of com.vaticle.typedb.core.pattern.Disjunction in project grakn by graknlabs.
the class TypeInferenceTest method nested_negation_is_satisfiable.
/**
* If the type resolver conflates anonymous or generated variables between the inner or outer nestings,
* we will see it here
*/
@Test
public void nested_negation_is_satisfiable() {
define_custom_schema("define session sub entity,\n" + " plays reported-fault:parent-session,\n" + " plays unanswered-question:parent-session;\n" + " fault sub entity,\n" + " plays reported-fault:relevant-fault,\n" + " plays fault-identification:identified-fault;\n" + " question sub entity,\n" + " plays fault-identification:identifying-question,\n" + " plays unanswered-question:question-not-answered;\n" + " reported-fault sub relation,\n" + " relates relevant-fault,\n" + " relates parent-session;\n" + " unanswered-question sub relation,\n" + " relates question-not-answered,\n" + " relates parent-session;\n" + " fault-identification sub relation,\n" + " relates identifying-question,\n" + " relates identified-fault;\n");
String query = "match (relevant-fault: $flt, parent-session: $ts) isa reported-fault;\n" + " not {\n" + " (question-not-answered: $ques, parent-session: $ts) isa unanswered-question;\n" + " ($flt, $ques) isa fault-identification;" + " };";
Disjunction disjunction = createDisjunction(query);
transaction.logic().typeInference().applyCombination(disjunction);
assertTrue(disjunction.conjunctions().get(0).negations().iterator().next().disjunction().conjunctions().get(0).isCoherent());
}
use of com.vaticle.typedb.core.pattern.Disjunction in project grakn by graknlabs.
the class TypeInferenceTest method infer_from_value_type.
@Test
public void infer_from_value_type() {
define_custom_schema("define" + " dog sub entity, owns weight;" + " person sub entity, owns name;" + " weight sub attribute, value double;" + " name sub attribute, value string;");
TypeInference typeInference = transaction.logic().typeInference();
String queryString = "match" + " $p has $a;" + " $a = 'bob';";
Disjunction disjunction = createDisjunction(queryString);
typeInference.applyCombination(disjunction);
Map<String, Set<String>> expected = new HashMap<>() {
{
put("$p", set("person"));
put("$a", set("name"));
}
};
assertEquals(expected, resolvedTypeMap(disjunction.conjunctions().get(0)));
}
use of com.vaticle.typedb.core.pattern.Disjunction in project grakn by graknlabs.
the class TypeInferenceTest method nested_negation_outer_scope_correctly_reduces_resolved_types.
@Test
public void nested_negation_outer_scope_correctly_reduces_resolved_types() {
define_custom_schema("define " + "person sub entity, plays marriage:spouse;" + "woman sub person;" + "marriage sub relation, relates spouse;");
String minimallyRestricted = "match $x isa person; not { ($x) isa marriage; };";
Disjunction disjunction = createDisjunction(minimallyRestricted);
transaction.logic().typeInference().applyCombination(disjunction);
HashMap<String, Set<String>> expected = new HashMap<>() {
{
put("$x", set("person", "woman"));
put("$_0", set("marriage"));
put("$_marriage", set("marriage"));
}
};
// test the inner negation
assertEquals(expected, resolvedTypeMap(disjunction.conjunctions().get(0).negations().iterator().next().disjunction().conjunctions().get(0)));
String restricted = "match $x isa woman; not { ($x) isa marriage; };";
Disjunction restrictedDisjunction = createDisjunction(restricted);
transaction.logic().typeInference().applyCombination(restrictedDisjunction);
expected = new HashMap<>() {
{
put("$x", set("woman"));
put("$_0", set("marriage"));
put("$_marriage", set("marriage"));
}
};
// test the inner negation
assertEquals(expected, resolvedTypeMap(restrictedDisjunction.conjunctions().get(0).negations().iterator().next().disjunction().conjunctions().get(0)));
}
use of com.vaticle.typedb.core.pattern.Disjunction in project grakn by graknlabs.
the class TypeInferenceTest method relation_variable_role_variable_relation_named_variable.
@Test
public void relation_variable_role_variable_relation_named_variable() throws IOException {
define_standard_schema("basic-schema");
TypeInference typeInference = transaction.logic().typeInference();
String queryString = "match $r (wife: $yoko) isa $m;";
Disjunction disjunction = createDisjunction(queryString);
typeInference.applyCombination(disjunction);
Map<String, Set<String>> expected = new HashMap<>() {
{
put("$yoko", set("woman"));
put("$r", set("marriage"));
put("$m", set("marriage", "relation", "thing"));
put("$_relation:wife", set("marriage:wife"));
}
};
assertEquals(expected, resolvedTypeMap(disjunction.conjunctions().get(0)));
}
Aggregations