Similarity.SorensenDice (Similarity v0.5.1)

Copy Markdown View Source

String similarity comparison with the Sorensen-Dice algorithm.

Wikipedia

Summary

Functions

Calculates the similarity between the left and right attributes, using Sorensen-Dice coefficient.

Functions

sorensen_dice(string1, string2, options \\ [])

Calculates the similarity between the left and right attributes, using Sorensen-Dice coefficient.

Attribute can be a string, list or a MapSet.

Raises ArgumentError when :ngram_size is not a positive integer or either string is shorter than it, including when the strings are identical.

Examples

iex> Similarity.SorensenDice.sorensen_dice("alma", "korte")
0.0

iex> Similarity.SorensenDice.sorensen_dice("alma", "alma")
1.0

iex> Similarity.SorensenDice.sorensen_dice("just letters", "letters just", ngram_size: 1)
1.0

iex> Similarity.SorensenDice.sorensen_dice("this that", "just that")
0.42857142857142855

iex> Similarity.SorensenDice.sorensen_dice([1, 2, 3], [1, 2, 3])
1.0

iex> Similarity.SorensenDice.sorensen_dice([1, 2, 3], [1, 2, 3, 4])
0.8571428571428571