use of com.vaticle.typedb.core.pattern.Disjunction in project grakn by graknlabs.
the class TypeInferenceTest method no_role_type.
@Test
public void no_role_type() throws IOException {
define_standard_schema("basic-schema");
TypeInference typeInference = transaction.logic().typeInference();
String queryString = "match ($yoko) isa marriage;";
Disjunction disjunction = createDisjunction(queryString);
typeInference.applyCombination(disjunction);
Map<String, Set<String>> expected = new HashMap<>() {
{
put("$yoko", set("man", "woman", "person"));
put("$_0", set("marriage"));
put("$_marriage", set("marriage"));
}
};
assertEquals(expected, resolvedTypeMap(disjunction.conjunctions().get(0)));
Map<String, Set<String>> expectedRPTypes = new HashMap<>() {
{
put("$yoko", set("marriage:spouse", "marriage:wife", "marriage:husband"));
}
};
assertEquals(expectedRPTypes, resolvedRoleTypeMap(disjunction.conjunctions().get(0)));
}
use of com.vaticle.typedb.core.pattern.Disjunction in project grakn by graknlabs.
the class TypeInferenceTest method has_with_minimal_cycle.
@Test
public void has_with_minimal_cycle() {
define_custom_schema("define " + "unit sub attribute, value string, owns unit, owns ref;" + "ref sub attribute, value long;");
TypeInference typeInference = transaction.logic().typeInference();
String queryString = "match" + " $a has $a;";
Disjunction disjunction = createDisjunction(queryString);
typeInference.applyCombination(disjunction);
Map<String, Set<String>> expectedExhaustive = new HashMap<>() {
{
put("$a", set("unit"));
}
};
assertEquals(expectedExhaustive, resolvedTypeMap(disjunction.conjunctions().get(0)));
}
use of com.vaticle.typedb.core.pattern.Disjunction in project grakn by graknlabs.
the class TypeInferenceTest method has_with_cycle.
@Test
public void has_with_cycle() {
define_custom_schema("define" + " person sub entity, owns name, owns height;" + " name sub attribute, value string, owns nickname;" + " nickname sub attribute, value string, owns name;" + " surname sub attribute, value string, owns name;" + " name sub attribute, value string;" + " surname sub attribute, value string;" + " nickname sub attribute, value string;" + " height sub attribute, value double;" + " ");
TypeInference typeInference = transaction.logic().typeInference();
String queryString = "match" + " $a has $b;" + " $b has $a;";
Disjunction disjunction = createDisjunction(queryString);
typeInference.applyCombination(disjunction);
Map<String, Set<String>> expected = new HashMap<>() {
{
put("$a", set("nickname", "name"));
put("$b", set("nickname", "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 has_with_big_cycle.
@Test
public void has_with_big_cycle() {
define_custom_schema("define" + " person sub entity, owns name, owns height;" + " name sub attribute, value string, owns nickname;" + " nickname sub attribute, value string, owns surname;" + " surname sub attribute, value string, owns middlename;" + " middlename sub attribute, value string, owns name;" + " weight sub attribute, value double, owns measure-system;" + " measure-system sub attribute, value string, owns conversion-rate;" + " conversion-rate sub attribute, value double;" + " height sub attribute, value double;");
TypeInference typeInference = transaction.logic().typeInference();
String queryString = "match" + " $a has $b;" + " $b has $c;" + " $c has $d;" + " $d has $a;";
Disjunction disjunction = createDisjunction(queryString);
typeInference.applyCombination(disjunction);
Map<String, Set<String>> expectedExhaustive = new HashMap<>() {
{
put("$a", set("name", "surname", "nickname", "middlename"));
put("$b", set("name", "surname", "nickname", "middlename"));
put("$c", set("name", "surname", "nickname", "middlename"));
put("$d", set("name", "surname", "nickname", "middlename"));
}
};
assertEquals(expectedExhaustive, resolvedTypeMap(disjunction.conjunctions().get(0)));
}
use of com.vaticle.typedb.core.pattern.Disjunction in project grakn by graknlabs.
the class TypeInferenceTest method has_hierarchy.
@Test
public void has_hierarchy() {
define_custom_schema("define" + " animal sub entity, abstract, owns weight;" + " person sub animal, owns leg-weight as weight;" + " chair sub entity, owns leg-weight;" + " dog sub animal;" + " weight sub attribute, value long, abstract;" + " leg-weight sub weight;");
TypeInference typeInference = transaction.logic().typeInference();
String queryString = "match" + " $a has weight $c;" + " $b has leg-weight 5;" + " $p has weight $c;";
Disjunction disjunction = createDisjunction(queryString);
typeInference.applyCombination(disjunction);
Map<String, Set<String>> expected = new HashMap<>() {
{
put("$a", set("person", "chair"));
put("$b", set("person", "chair"));
put("$c", set("leg-weight"));
put("$p", set("person", "chair"));
put("$_0", set("leg-weight"));
put("$_weight", set("weight"));
put("$_leg-weight", set("leg-weight"));
}
};
assertEquals(expected, resolvedTypeMap(disjunction.conjunctions().get(0)));
}
Aggregations