2 Module : Gargantext.Ngrams.Metrics
3 Description : Short description
4 Copyright : (c) Some Guy, 2013
7 Maintainer : sample@email.com
8 Stability : experimental
11 Mainly reexport functions in @Data.Text.Metrics@
14 module Gargantext.Ngrams.Metrics (levenshtein
17 , damerauLevenshteinNorm
23 import Gargantext.Prelude
25 import Data.Text (Text)
26 import GHC.Real (Ratio)
27 import qualified Data.Text.Metrics as DTM
32 -- | This module provide metrics to compare Text
33 -- starting as an API rexporting main functions of the great lib
34 -- text-metrics of Mark Karpov
36 -- | Levenshtein Distance
37 -- In information theory, Linguistics and computer science,
38 -- the Levenshtein distance is a string metric for measuring
39 -- the difference between two sequences.
40 -- See: https://en.wikipedia.org/wiki/Levenshtein_distance
42 levenshtein :: Text -> Text -> Int
43 levenshtein = DTM.levenshtein
45 -- | Return normalized Levenshtein distance between two 'Text' values.
46 -- Result is a non-negative rational number (represented as @'Ratio'
47 -- 'Data.Numeric.Natural'@), where 0 signifies no similarity between the
48 -- strings, while 1 means exact match.
50 levenshteinNorm :: Text -> Text -> Ratio Int
51 levenshteinNorm = DTM.levenshteinNorm
53 -- | Return Damerau-Levenshtein distance between two 'Text' values. The
54 -- function works like 'levenshtein', but the collection of allowed
55 -- operations also includes transposition of two /adjacent/ characters.
57 -- <https://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance>
59 damerauLevenshtein :: Text -> Text -> Int
60 damerauLevenshtein = DTM.damerauLevenshtein
62 -- damerau-Levenshtein distance normalized
64 damerauLevenshteinNorm :: Text -> Text -> Ratio Int
65 damerauLevenshteinNorm = DTM.damerauLevenshteinNorm
67 -- Treating inputs like sets
69 -- | Return overlap coefficient for two 'Text' values. Returned value
70 -- is in the range from 0 (no similarity) to 1 (exact match). Return 1
71 -- if both 'Text' values are empty.
73 -- See also: <https://en.wikipedia.org/wiki/Overlap_coefficient>.
74 overlap :: Text -> Text -> Ratio Int
79 -- measures dissimilarity between sample sets
80 jaccard :: Text -> Text -> Ratio Int
84 -- In information theory, the Hamming distance between two strings of
85 -- equal length is the number of positions at which the corresponding
86 -- symbols are different. In other words, it measures the minimum number of
87 -- substitutions required to change one string into the other
88 -- See: https://en.wikipedia.org/wiki/Hamming_distance
90 hamming :: Text -> Text -> Maybe Int