use of ai.grakn.graql.internal.reasoner.utils.conversion.TypeConverter in project grakn by graknlabs.
the class RelationshipAtom method inferPossibleRelationConfigurations.
/**
* @return a map of relationships and corresponding roles that could be played by this atom
*/
private Multimap<RelationshipType, Role> inferPossibleRelationConfigurations(Answer sub) {
Set<Role> roles = getExplicitRoles().filter(r -> !Schema.MetaSchema.isMetaLabel(r.getLabel())).collect(toSet());
Map<Var, Type> varTypeMap = getParentQuery().getVarTypeMap(sub);
Set<Type> types = getRolePlayers().stream().filter(varTypeMap::containsKey).map(varTypeMap::get).collect(toSet());
if (roles.isEmpty() && types.isEmpty()) {
RelationshipType metaRelationType = tx().admin().getMetaRelationType();
Multimap<RelationshipType, Role> compatibleTypes = HashMultimap.create();
metaRelationType.subs().filter(rt -> !rt.equals(metaRelationType)).forEach(rt -> compatibleTypes.putAll(rt, rt.relates().collect(toSet())));
return compatibleTypes;
}
// intersect relation types from roles and types
Multimap<RelationshipType, Role> compatibleTypes;
Multimap<RelationshipType, Role> compatibleTypesFromRoles = compatibleRelationTypesWithRoles(roles, new RoleConverter());
Multimap<RelationshipType, Role> compatibleTypesFromTypes = compatibleRelationTypesWithRoles(types, new TypeConverter());
if (roles.isEmpty()) {
compatibleTypes = compatibleTypesFromTypes;
} else // no types from roles -> roles correspond to mutually exclusive relations
if (compatibleTypesFromRoles.isEmpty() || types.isEmpty()) {
compatibleTypes = compatibleTypesFromRoles;
} else {
compatibleTypes = multimapIntersection(compatibleTypesFromTypes, compatibleTypesFromRoles);
}
return compatibleTypes;
}
Aggregations