Maintainer | hapytexeu+gh@gmail.com |
---|---|
Stability | experimental |
Portability | POSIX |
Safe Haskell | Safe |
Language | Haskell2010 |
The Levenshtein distance is the minimal number of additions, removals, and updates one has to make to
convert one list of items into another list of items. In this module we provide some functions that makes
it convenient to calculate the distance and the sequence of Edit
s, and furthermore ways to alter the score
for an addition, removal, edit that can depend on what item is modified.
Synopsis
- genericLevenshteinDistance :: (Foldable f, Foldable g, Eq a, Num b, Ord b) => (a -> b) -> (a -> b) -> (a -> a -> b) -> f a -> g a -> b
- genericLevenshteinDistance' :: (Foldable f, Foldable g, Num b, Ord b) => (a -> a -> Bool) -> (a -> b) -> (a -> b) -> (a -> a -> b) -> f a -> g a -> b
- levenshteinDistance :: (Foldable f, Foldable g, Eq a, Num b, Ord b) => f a -> g a -> b
- levenshteinDistance' :: (Foldable f, Foldable g, Num b, Ord b) => (a -> a -> Bool) -> f a -> g a -> b
- genericLevenshtein :: (Foldable f, Foldable g, Eq a, Num b, Ord b) => (a -> b) -> (a -> b) -> (a -> a -> b) -> f a -> g a -> (b, [Edit a])
- genericLevenshtein' :: (Foldable f, Foldable g, Num b, Ord b) => (a -> a -> Bool) -> (a -> b) -> (a -> b) -> (a -> a -> b) -> f a -> g a -> (b, [Edit a])
- levenshtein :: (Foldable f, Foldable g, Eq a, Num b, Ord b) => f a -> g a -> (b, [Edit a])
- levenshtein' :: (Foldable f, Foldable g, Num b, Ord b) => (a -> a -> Bool) -> f a -> g a -> (b, [Edit a])
- genericReversedLevenshtein :: (Foldable f, Foldable g, Eq a, Num b, Ord b) => (a -> b) -> (a -> b) -> (a -> a -> b) -> f a -> g a -> (b, [Edit a])
- genericReversedLevenshtein' :: (Foldable f, Foldable g, Num b, Ord b) => (a -> a -> Bool) -> (a -> b) -> (a -> b) -> (a -> a -> b) -> f a -> g a -> (b, [Edit a])
- reversedLevenshtein :: (Foldable f, Foldable g, Eq a, Num b, Ord b) => f a -> g a -> (b, [Edit a])
- reversedLevenshtein' :: (Foldable f, Foldable g, Num b, Ord b) => (a -> a -> Bool) -> f a -> g a -> (b, [Edit a])
- data Edit a
- applyEdits :: Eq a => [Edit a] -> [a] -> Maybe [a]
Calculate the Levenshtein distance
genericLevenshteinDistance Source #
:: (Foldable f, Foldable g, Eq a, Num b, Ord b) | |
=> (a -> b) | The cost of adding the given item. The return value should be positive. |
-> (a -> b) | The cost of removing the given item. The return value should be positive. |
-> (a -> a -> b) | The cost that it takes to replace an item of the first parameter with one of the second parameter. The return value should be positive. |
-> f a | The given original sequence. |
-> g a | The given target sequence. |
-> b | The edit distance between the two |
A function to determine the Levenshtein distance by specifying the cost functions of adding, removing and editing characters. This function returns
the sum of the costs to transform the first Foldable
(as list) into the second Foldable
(as list). The (==)
function is used
to determine if two items are equivalent.
genericLevenshteinDistance' Source #
:: (Foldable f, Foldable g, Num b, Ord b) | |
=> (a -> a -> Bool) | The given equivalence relation to work with. |
-> (a -> b) | The cost of adding the given item. The return value should be positive. |
-> (a -> b) | The cost of removing the given item. The return value should be positive. |
-> (a -> a -> b) | The cost that it takes to replace an item of the first parameter with one of the second parameter. The return value should be positive. |
-> f a | The given original sequence. |
-> g a | The given target sequence. |
-> b | The edit distance between the two |
A function to determine the Levenshtein distance by specifying the cost functions of adding, removing and editing characters. This function returns
the sum of the costs to transform the first Foldable
(as list) into the second Foldable
(as list). The first parameter is an equivalence relation
to determine if two items are considered equivalent.
:: (Foldable f, Foldable g, Eq a, Num b, Ord b) | |
=> f a | The given original sequence. |
-> g a | The given target sequence. |
-> b | The edit distance between the two |
Determine the edit distance where an addition, removal, and change all count as one, and where
the Eq
instance is used to determine whether two items are equivalent, this is for example useful
for case-insensitve matching.
Obtain the Levenshtein distance together with the path of Edit
s
:: (Foldable f, Foldable g, Eq a, Num b, Ord b) | |
=> (a -> b) | The cost of adding the given item. The return value should be positive. |
-> (a -> b) | The cost of removing the given item. The return value should be positive. |
-> (a -> a -> b) | The cost that it takes to replace an item of the first parameter with one of the second parameter. The return value should be positive. |
-> f a | The given original sequence. |
-> g a | The given target sequence. |
-> (b, [Edit a]) | A 2-tuple with the edit score as first item, and a list of modifications in normal order as second item to transform the first sequence to the second one. |
A function to determine the Levenshtein distance together with a list of Edit
s
to apply to convert the first Foldable
(as list) into the second item (as list)
The cost functions of adding, removing and editing characters will be used to minimize
the total edit distance. The (==)
function is used to determine if two items of the
Foldable
s are considered equivalent.
:: (Foldable f, Foldable g, Num b, Ord b) | |
=> (a -> a -> Bool) | The given equivalence relation to work with. |
-> (a -> b) | The cost of adding the given item. The return value should be positive. |
-> (a -> b) | The cost of removing the given item. The return value should be positive. |
-> (a -> a -> b) | The cost that it takes to replace an item of the first parameter with one of the second parameter. The return value should be positive. |
-> f a | The given original sequence. |
-> g a | The given target sequence. |
-> (b, [Edit a]) | A 2-tuple with the edit score as first item, and a list of modifications in normal order as second item to transform the first sequence to the second one. |
A function to determine the Levenshtein distance together with a list of Edit
s
to apply to convert the first Foldable
(as list) into the second item (as list)
The cost functions of adding, removing and editing characters will be used to minimize
the total edit distance. The first parameter is an equivalence relation that is used
to determine if two items of the Foldable
s are considered equivalent.
:: (Foldable f, Foldable g, Num b, Ord b) | |
=> (a -> a -> Bool) | The given equivalence relation to work with. |
-> f a | The given original sequence. |
-> g a | The given target sequence. |
-> (b, [Edit a]) | The edit distance between the two |
Obtain the Levenshtein distance together with a reversed path of Edit
s
genericReversedLevenshtein Source #
:: (Foldable f, Foldable g, Eq a, Num b, Ord b) | |
=> (a -> b) | The cost of adding the given item. The return value should be positive. |
-> (a -> b) | The cost of removing the given item. The return value should be positive. |
-> (a -> a -> b) | The cost that it takes to replace an item of the first parameter with one of the second parameter. The return value should be positive. |
-> f a | The given original sequence. |
-> g a | The given target sequence. |
-> (b, [Edit a]) | A 2-tuple with the edit score as first item, and a list of modifications in reversed order as second item to transform the first |
A function to determine the Levenshtein distance together with a list of Edit
s
to apply to convert the first Foldable
(as list) into the second item (as list)
in reversed order. The cost functions of adding, removing and editing characters
will be used to minimize the total edit distance. The (==)
function is used
to determine if two items of the Foldable
s are considered equivalent.
genericReversedLevenshtein' Source #
:: (Foldable f, Foldable g, Num b, Ord b) | |
=> (a -> a -> Bool) | The given equivalence relation to work with. |
-> (a -> b) | The cost of adding the given item. The return value should be positive. |
-> (a -> b) | The cost of removing the given item. The return value should be positive. |
-> (a -> a -> b) | The cost that it takes to replace an item of the first parameter with one of the second parameter. The return value should be positive. |
-> f a | The given original sequence. |
-> g a | The given target sequence. |
-> (b, [Edit a]) | A 2-tuple with the edit score as first item, and a list of modifications in reversed order as second item to transform the first |
A function to determine the Levenshtein distance together with a list of Edit
s
to apply to convert the first Foldable
(as list) into the second item (as list)
in reversed order. The cost functions of adding, removing and editing characters
will be used to minimize the total edit distance. The first parameter is an
equivalence relation that is used to determine if two items of the Foldable
s are considered equivalent.
:: (Foldable f, Foldable g, Num b, Ord b) | |
=> (a -> a -> Bool) | The given equivalence relation to work with. |
-> f a | The given original sequence. |
-> g a | The given target sequence. |
-> (b, [Edit a]) | The edit distance between the two |
Data type to present modifications from one Foldable
to the other.a
A data type that is used to list how to edit a sequence to form another sequence.
Add a | We add the given element to the sequence. |
Rem a | We remove the given element to the sequence. |
Copy a | We copy an element from the sequence, this basically act as a no-op. |
Swap a a | We modify the given first item into the second item, this thus denotes a replacement. |