use of com.vaticle.typedb.core.pattern.variable.TypeVariable in project grakn by graknlabs.
the class PlaysConstraint method of.
static PlaysConstraint of(TypeVariable owner, com.vaticle.typeql.lang.pattern.constraint.TypeConstraint.Plays constraint, VariableRegistry registry) {
TypeVariable roleType = registry.register(constraint.role());
TypeVariable relationType = constraint.relation().map(registry::register).orElse(null);
TypeVariable overriddenType = constraint.overridden().map(registry::register).orElse(null);
return new PlaysConstraint(owner, relationType, roleType, overriddenType);
}
use of com.vaticle.typedb.core.pattern.variable.TypeVariable in project grakn by graknlabs.
the class RelatesConstraint method of.
static RelatesConstraint of(TypeVariable owner, com.vaticle.typeql.lang.pattern.constraint.TypeConstraint.Relates constraint, VariableRegistry registry) {
TypeVariable roleType = registry.register(constraint.role());
TypeVariable overriddenRoleType = constraint.overridden().map(registry::register).orElse(null);
return new RelatesConstraint(owner, roleType, overriddenRoleType);
}
use of com.vaticle.typedb.core.pattern.variable.TypeVariable in project grakn by graknlabs.
the class Util method getRoleType.
public static RoleType getRoleType(Relation relation, Thing player, RelationConstraint.RolePlayer rolePlayer) {
try (FactoryTracingThreadStatic.ThreadTrace ignored = traceOnThread(TRACE_PREFIX + "get_role_type")) {
RoleType roleType;
Set<? extends RoleType> inferred;
if (rolePlayer.roleType().isPresent()) {
RelationType relationType = relation.getType();
TypeVariable var = rolePlayer.roleType().get();
if ((roleType = relationType.getRelates(var.label().get().label())) == null) {
throw TypeDBException.of(TYPE_NOT_FOUND, Label.of(var.label().get().label(), relationType.getLabel().name()));
}
} else if ((inferred = player.getType().getPlays().filter(rt -> rt.getRelationType().equals(relation.getType())).toSet()).size() == 1) {
roleType = inferred.iterator().next();
} else if (inferred.size() > 1) {
throw TypeDBException.of(ROLE_TYPE_AMBIGUOUS, rolePlayer.player().reference());
} else {
throw TypeDBException.of(ROLE_TYPE_MISSING, rolePlayer.player().reference());
}
return roleType;
}
}
Aggregations