Calculates word distance using HashMap.