use of com.vaticle.typedb.core.logic.tool.TypeInference 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.logic.tool.TypeInference 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.logic.tool.TypeInference 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)));
}
use of com.vaticle.typedb.core.logic.tool.TypeInference in project grakn by graknlabs.
the class TypeInferenceTest method negations_ignored.
@Test
public void negations_ignored() throws IOException {
define_standard_schema("basic-schema");
TypeInference typeInference = transaction.logic().typeInference();
String queryString = "match" + " $p isa person;" + " not {$p isa man;};";
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 has_inference_variable_without_attribute_type.
@Test
public void has_inference_variable_without_attribute_type() throws IOException {
define_standard_schema("basic-schema");
TypeInference typeInference = transaction.logic().typeInference();
String queryString = "match" + " $p isa shape;" + " $p has $a;";
Disjunction disjunction = createDisjunction(queryString);
typeInference.applyCombination(disjunction);
Map<String, Set<String>> expected = new HashMap<>() {
{
put("$p", set("triangle", "right-angled-triangle", "square"));
put("$a", set("perimeter", "area", "label", "hypotenuse-length"));
put("$_shape", set("shape"));
}
};
assertEquals(expected, resolvedTypeMap(disjunction.conjunctions().get(0)));
}
Aggregations