rewritten TextClustering using Scala