dep-software-0.1.0.0
Maintainerhapytexeu+gh@gmail.com
Stabilityexperimental
PortabilityPOSIX
Safe HaskellSafe
LanguageHaskell2010

Dep.Algorithm.Levenshtein

Description

This module exports functions to help determine how different two sequences are. This is used to guess the name of the command if the command given by the user does not map on an action.

Synopsis

Present edits to a sequence

data Edit a Source #

A data type that is used to list how to edit a sequence to form another sequence.

Constructors

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.

Instances

Instances details
Functor Edit Source # 
Instance details

Defined in Dep.Algorithm.Levenshtein

Methods

fmap :: (a -> b) -> Edit a -> Edit b #

(<$) :: a -> Edit b -> Edit a #

Foldable Edit Source # 
Instance details

Defined in Dep.Algorithm.Levenshtein

Methods

fold :: Monoid m => Edit m -> m #

foldMap :: Monoid m => (a -> m) -> Edit a -> m #

foldMap' :: Monoid m => (a -> m) -> Edit a -> m #

foldr :: (a -> b -> b) -> b -> Edit a -> b #

foldr' :: (a -> b -> b) -> b -> Edit a -> b #

foldl :: (b -> a -> b) -> b -> Edit a -> b #

foldl' :: (b -> a -> b) -> b -> Edit a -> b #

foldr1 :: (a -> a -> a) -> Edit a -> a #

foldl1 :: (a -> a -> a) -> Edit a -> a #

toList :: Edit a -> [a] #

null :: Edit a -> Bool #

length :: Edit a -> Int #

elem :: Eq a => a -> Edit a -> Bool #

maximum :: Ord a => Edit a -> a #

minimum :: Ord a => Edit a -> a #

sum :: Num a => Edit a -> a #

product :: Num a => Edit a -> a #

Traversable Edit Source # 
Instance details

Defined in Dep.Algorithm.Levenshtein

Methods

traverse :: Applicative f => (a -> f b) -> Edit a -> f (Edit b) #

sequenceA :: Applicative f => Edit (f a) -> f (Edit a) #

mapM :: Monad m => (a -> m b) -> Edit a -> m (Edit b) #

sequence :: Monad m => Edit (m a) -> m (Edit a) #

Arbitrary1 Edit Source # 
Instance details

Defined in Dep.Algorithm.Levenshtein

Methods

liftArbitrary :: Gen a -> Gen (Edit a) #

liftShrink :: (a -> [a]) -> Edit a -> [Edit a] #

Eq1 Edit Source # 
Instance details

Defined in Dep.Algorithm.Levenshtein

Methods

liftEq :: (a -> b -> Bool) -> Edit a -> Edit b -> Bool #

Ord1 Edit Source # 
Instance details

Defined in Dep.Algorithm.Levenshtein

Methods

liftCompare :: (a -> b -> Ordering) -> Edit a -> Edit b -> Ordering #

NFData1 Edit Source # 
Instance details

Defined in Dep.Algorithm.Levenshtein

Methods

liftRnf :: (a -> ()) -> Edit a -> () #

Hashable1 Edit Source # 
Instance details

Defined in Dep.Algorithm.Levenshtein

Methods

liftHashWithSalt :: (Int -> a -> Int) -> Int -> Edit a -> Int #

Lift a => Lift (Edit a :: Type) Source # 
Instance details

Defined in Dep.Algorithm.Levenshtein

Methods

lift :: Edit a -> Q Exp #

liftTyped :: Edit a -> Q (TExp (Edit a)) #

Eq a => Eq (Edit a) Source # 
Instance details

Defined in Dep.Algorithm.Levenshtein

Methods

(==) :: Edit a -> Edit a -> Bool #

(/=) :: Edit a -> Edit a -> Bool #

Data a => Data (Edit a) Source # 
Instance details

Defined in Dep.Algorithm.Levenshtein

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Edit a -> c (Edit a) #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Edit a) #

toConstr :: Edit a -> Constr #

dataTypeOf :: Edit a -> DataType #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Edit a)) #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Edit a)) #

gmapT :: (forall b. Data b => b -> b) -> Edit a -> Edit a #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Edit a -> r #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Edit a -> r #

gmapQ :: (forall d. Data d => d -> u) -> Edit a -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Edit a -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Edit a -> m (Edit a) #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Edit a -> m (Edit a) #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Edit a -> m (Edit a) #

Ord a => Ord (Edit a) Source # 
Instance details

Defined in Dep.Algorithm.Levenshtein

Methods

compare :: Edit a -> Edit a -> Ordering #

(<) :: Edit a -> Edit a -> Bool #

(<=) :: Edit a -> Edit a -> Bool #

(>) :: Edit a -> Edit a -> Bool #

(>=) :: Edit a -> Edit a -> Bool #

max :: Edit a -> Edit a -> Edit a #

min :: Edit a -> Edit a -> Edit a #

Read a => Read (Edit a) Source # 
Instance details

Defined in Dep.Algorithm.Levenshtein

Show a => Show (Edit a) Source # 
Instance details

Defined in Dep.Algorithm.Levenshtein

Methods

showsPrec :: Int -> Edit a -> ShowS #

show :: Edit a -> String #

showList :: [Edit a] -> ShowS #

Generic (Edit a) Source # 
Instance details

Defined in Dep.Algorithm.Levenshtein

Associated Types

type Rep (Edit a) :: Type -> Type #

Methods

from :: Edit a -> Rep (Edit a) x #

to :: Rep (Edit a) x -> Edit a #

Arbitrary a => Arbitrary (Edit a) Source # 
Instance details

Defined in Dep.Algorithm.Levenshtein

Methods

arbitrary :: Gen (Edit a) #

shrink :: Edit a -> [Edit a] #

Binary a => Binary (Edit a) Source # 
Instance details

Defined in Dep.Algorithm.Levenshtein

Methods

put :: Edit a -> Put #

get :: Get (Edit a) #

putList :: [Edit a] -> Put #

NFData a => NFData (Edit a) Source # 
Instance details

Defined in Dep.Algorithm.Levenshtein

Methods

rnf :: Edit a -> () #

Hashable a => Hashable (Edit a) Source # 
Instance details

Defined in Dep.Algorithm.Levenshtein

Methods

hashWithSalt :: Int -> Edit a -> Int #

hash :: Edit a -> Int #

Generic1 Edit Source # 
Instance details

Defined in Dep.Algorithm.Levenshtein

Associated Types

type Rep1 Edit :: k -> Type #

Methods

from1 :: forall (a :: k). Edit a -> Rep1 Edit a #

to1 :: forall (a :: k). Rep1 Edit a -> Edit a #

type Rep (Edit a) Source # 
Instance details

Defined in Dep.Algorithm.Levenshtein

type Rep1 Edit Source # 
Instance details

Defined in Dep.Algorithm.Levenshtein

Edit distance score

editScore Source #

Arguments

:: Edit a

The given Edit to convert to a score.

-> Int

The score of the given Edit object.

Determine the standard edit score for the Levenshtein distance.

editScore' Source #

Arguments

:: Foldable f 
=> f (Edit a)

The given Foldable of edits to determine the score from.

-> Int

The edit score given for the given Foldable of Edits.

Determine the score for the Levenshtein distance for a Foldable of Edits.

Determine the most optimal edit

levenshtein Source #

Arguments

:: Eq a 
=> [a]

The original given sequence.

-> [a]

The target given sequence.

-> (Int, [Edit a])

A 2-tuple with the edit score as first item, and a list of modifications as second item to transform the first sequence to the second one.

Obtain the Levenshtein distance from one sequence ot another, given we each time add one point for an addition, deletion and substitution.

levenshtein' Source #

Arguments

:: (a -> a -> Bool)

A function that determines whether the two items of the sequences are equivalent.

-> [a]

The original given sequence.

-> [a]

The target given sequence.

-> (Int, [Edit a])

A 2-tuple with the edit score as first item, and a list of modifications as second item to transform the first sequence to the second one.

Obtain the Levenshtein distance from one sequence ot another, given we each time add one point for an addition, deletion and substitution. The equality relation is given, for example to perform case-insensitive matching.

reversedLevenshtein Source #

Arguments

:: Eq a 
=> [a]

The original given sequence.

-> [a]

The target given sequence.

-> (Int, [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 sequence to the second one.

Obtain the Levenshtein distance where the list of edits is in reverse order. This because this is more efficient and is thus useful if the order of the Edits does not matter much.

reversedLevenshtein' Source #

Arguments

:: (a -> a -> Bool)

The given equivalence relation to work with.

-> [a]

The original given sequence.

-> [a]

The target sequence.

-> (Int, [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 sequence to the second one.

Obtain the Levenshtein distance where the list of edits is in reverse order. This because this is more efficient and is thus useful if the order of the Edits does not matter much. The equivalence relation is given through a parameter, and thus can for example allow case-insensitive matching.

Advanced Levenshtein distances

genericReversedLevenshtein Source #

Arguments

:: Eq a 
=> (a -> Int)

The cost of adding the given item.

-> (a -> Int)

The cost of removing the given item.

-> (a -> a -> Int)

The cost that it takes to replace an item of the first parameter with one of the second parameter.

-> [a]

The original given sequence.

-> [a]

The target sequence.

-> (Int, [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 sequence to the second one.

A function to determine the Levenshtein distance by specifying the cost functions of adding, removing and editing characters. The 2-tuple returns the distance as first item of the 2-tuple, and the list of Edits in reverse order as second item.

genericReversedLevenshtein' Source #

Arguments

:: (a -> a -> Bool)

The given equivalence relation to work with.

-> (a -> Int)

The cost of adding the given item.

-> (a -> Int)

The cost of removing the given item.

-> (a -> a -> Int)

The cost that it takes to replace an item of the first parameter with one of the second parameter.

-> [a]

The original given sequence.

-> [a]

The target sequence.

-> (Int, [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 sequence to the second one.

A function to determine the Levenshtein distance by specifying the cost functions of adding, removing and editing characters. The 2-tuple returns the distance as first item of the 2-tuple, and the list of Edits in reverse order as second item.