use of com.vaticle.typedb.core.concept.thing.Thing in project grakn by graknlabs.
the class UnifyRelationConcludableTest method relation_and_player_unifies_rule_relation_exact.
@Test
public void relation_and_player_unifies_rule_relation_exact() {
Unifier unifier = uniqueUnifier("{ $r (employee: $y) isa employment; }", rule(" (employee: $x) isa employment", "{ $x isa person; }"));
Map<String, Set<String>> result = getStringMapping(unifier.mapping());
Map<String, Set<String>> expected = new HashMap<String, Set<String>>() {
{
put("$y", set("$x"));
put("$r", set("$_0"));
}
};
assertEquals(expected, result);
// test requirements
assertEquals(typeHierarchy("employment"), unifier.requirements().isaExplicit().get(Variable.name("r")));
assertEquals(2, unifier.requirements().isaExplicit().size());
assertEquals(roleHierarchy("employee", "employment"), unifier.requirements().types().get(Variable.label("employment:employee")));
assertEquals(2, unifier.requirements().types().size());
assertEquals(0, unifier.requirements().predicates().size());
// test filter allows a valid answer
// code below tests unifier applied to an answer that is 1) satisfiable, 2) non-satisfiable
Relation employment = instanceOf("employment").asRelation();
Thing person = instanceOf("person");
addRolePlayer(employment, "employee", person);
Map<Variable, Concept> concepts = map(pair(Variable.anon(0), employment), pair(Variable.name("x"), person), pair(Variable.label("employment"), employment.getType()), pair(Variable.label("employment:employee"), employment.getType().getRelates("employee")));
FunctionalIterator<ConceptMap> unified = unifier.unUnify(concepts, new Unifier.Requirements.Instance(map()));
assertTrue(unified.hasNext());
ConceptMap unifiedAnswer = unified.first().get();
assertEquals(2, unifiedAnswer.concepts().size());
assertEquals(employment, unifiedAnswer.get("r"));
assertEquals(person, unifiedAnswer.get("y"));
// filter out invalid types
Relation friendship = instanceOf("friendship").asRelation();
person = instanceOf("person");
addRolePlayer(friendship, "friend", person);
concepts = map(pair(Variable.anon(0), friendship), pair(Variable.name("x"), person), pair(Variable.label("employment"), friendship.getType()), pair(Variable.label("employment:employee"), friendship.getType().getRelates("friend")));
unified = unifier.unUnify(concepts, new Unifier.Requirements.Instance(map()));
assertFalse(unified.hasNext());
}
Aggregations