edits-0.1.1.0: show the differences between 2 pieces of Text using the Levenshtein distance
Safe HaskellSafe-Inferred
LanguageGHC2021

Data.Text.Edits

Description

This module provides a showDistance function showing the differences between 2 pieces of text using the Levenshtein distance. That distance is defined as the minimum number of edits: insertions, deletions, substitutions to go from one text to another.

Several options are available to customize this processing: - split size: texts are broken into new lines first. Then if the texts are too large there are split into smaller pieces in order to compute their difference. This is done in order to reduce the size of the edit matrix which is used to compute all the edit costs the default is 200

  • separators: opening and closing pieces of text (brackets by default) used to highlight a difference
  • shorten size: there is the possibly to display mostly the differences with a bit of context around if the input text is too large. The text gets elided around separators if it gets greater than the shorten size (the default is 20)
  • shorten text: the text to use when eliding characters in the original text (the default is "...")
  • display edit operations: edit operations, insertdeletesubstitute/keep can be annotated if necessary

Here are some examples:

import Data.Text.Edits

-- "between the e and the n the letter i was added"
showDistance "kitten" "kittein" === "kitte[+i]n"

-- "at the end of the text 3 letters have been deleted"
showDistance "kitten" "kit" === "kit[-t-e-n]"

-- "between the t and the n 2 letters have been modified"
showDistance "kitten" "kitsin" === "kit[~ts~ei]"
Synopsis

Documentation

newtype SplitSize Source #

Size to use when splitting a large piece of text

Constructors

SplitSize Int 

Instances

Instances details
Show SplitSize Source # 
Instance details

Defined in Data.Text.Edits

Eq SplitSize Source # 
Instance details

Defined in Data.Text.Edits

data ShortenOptions Source #

Size used to decide if a piece of text needs to be shortened

Constructors

ShortenOptions 

Instances

Instances details
Show ShortenOptions Source # 
Instance details

Defined in Data.Text.Shorten

Eq ShortenOptions Source # 
Instance details

Defined in Data.Text.Shorten

data Separators Source #

Separators are used to highlight a difference between 2 pieces of text for example

Constructors

Separators 

Instances

Instances details
Show Separators Source # 
Instance details

Defined in Data.Text.Difference

Eq Separators Source # 
Instance details

Defined in Data.Text.Difference

data DisplayOptions Source #

Options to use for displaying differences

data EditOperation a Source #

Atomic operation required to edit a piece of text at a given position in the EditMatrix

Constructors

Insert a 
Delete a 
Substitute a a 
Keep a 

Instances

Instances details
Show a => Show (EditOperation a) Source # 
Instance details

Defined in Data.Text.EditOperation

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

Defined in Data.Text.EditOperation

data Color Source #

Available ASCII colors

Constructors

Black 
Red 
Green 
Yellow 
Blue 
Magenta 
Cyan 
White 

Instances

Instances details
Show Color Source # 
Instance details

Defined in Data.Text.Color

Methods

showsPrec :: Int -> Color -> ShowS #

show :: Color -> String #

showList :: [Color] -> ShowS #

Eq Color Source # 
Instance details

Defined in Data.Text.Color

Methods

(==) :: Color -> Color -> Bool #

(/=) :: Color -> Color -> Bool #

colorAs :: Color -> Text -> Text Source #

Surround a piece of text with ASCII control characters to color it

showDistance :: Text -> Text -> Text Source #

Show the distance between 2 pieces of text

showDistanceColored :: Text -> Text -> Text Source #

Show the distance between 2 pieces of text with colors instead of symbols

showDistanceWith :: SplitSize -> DisplayOptions -> Text -> Text -> Text Source #

Show the distance between 2 pieces of text and specify splitting / display options

levenshteinOperations :: Text -> Text -> [EditOperation Char] Source #

Return the list of operations necessary to go from one piece of text to another using the Levenshtein distance

defaultDisplayOptions :: DisplayOptions Source #

Default display options

defaultDisplayEditOperations :: EditOperation Char -> Text Source #

Display an edit operation by prepending a symbol showing which operation is used

coloredDisplayEditOperation :: EditOperation Char -> Text Source #

Display an edit operation using ascii colors: green = added, red = removed, blue = substituted

defaultSplitSize :: SplitSize Source #

Default split size

parensSeparators :: Separators Source #

Make parens separators

bracketsSeparators :: Separators Source #

Make brackets separators

makeCharSeparators :: Char -> Char -> Separators Source #

Make separators with simple Chars