Refactor TermWeight and TermSimilarity and added test for it