Changeset v0.1.0 Changeset

The Changeset module allows for calculating the Levenshtein distance between two lists, or the actual edit steps required to go from one list to another.

Summary

Functions

Calculate the the minimal steps (insertions, deletions, substitutions and moves) required to turn one given list into another given list

Calculate the the Levenshtein distance between two lists, i.e. how many insertions, deletions or substitutions are required to turn one given list into another

Functions

edits(source, target)

Specs

edits([], []) :: [{atom, any, non_neg_integer}]

Calculate the the minimal steps (insertions, deletions, substitutions and moves) required to turn one given list into another given list.

Examples

iex> taylor_swift_songs = [22, 15, "I Knew You Were Trouble"]
iex> positive_integers = [22, 7, 15, 186, 33]

iex> Changeset.edits(taylor_swift_songs, positive_integers)
[{:insert, 7, 1}, {:substitute, 186, 3}, {:insert, 33, 4}]

iex> Changeset.edits(positive_integers, taylor_swift_songs)
[{:delete, 7, 1}, {:substitute, "I Knew You Were Trouble", 2}, {:delete, 33, 4}]

iex> Changeset.edits(~w( a v e r y ), ~w( g a r v e y))
[{:insert, "g", 0}, {:move, "r", 3, 2}]
levenshtein(source, target)

Specs

levenshtein([], []) :: non_neg_integer

Calculate the the Levenshtein distance between two lists, i.e. how many insertions, deletions or substitutions are required to turn one given list into another.

Examples

iex> taylor_swift_songs = [22, 15, "I Knew You Were Trouble"]
iex> positive_integers = [22, 7, 15, 186, 33]

iex> Changeset.levenshtein(taylor_swift_songs, positive_integers)
3