implementing clustering algorithm to assign terms colors