Back to problems

Compute and Rank by Jaccard Similarity

Algorithm · Yelp · Hard

Implement two routines for comparing short text reviews by set-based similarity. A text should first be normalized to lowercase. Then split it on every character that is not a letter or digit, and remove empty pieces. The remaining tokens are treated as a set, so duplicate tokens count only once. jaccard_similarity(s1, s2): Convert s1 and s2 into token sets A and B. Return $$J(A,B)=\frac{ A \cap B }{ A \cup B }$$. If both token sets are empty, return 0.0.…

Checking your access…