2 Module : Gargantext.Ngrams.Metrics
3 Description : Short description
4 Copyright : (c) Some Guy, 2013
7 Maintainer : sample@email.com
8 Stability : experimental
11 Here is a longer description of this module, containing some
12 commentary with @some markup@.
15 module Gargantext.Ngrams.Metrics (levenshtein
18 , damerauLevenshteinNorm
24 import Gargantext.Prelude
26 import Data.Text (Text)
27 import GHC.Real (Ratio)
28 import qualified Data.Text.Metrics as DTM
33 -- | This module provide metrics to compare Text
34 -- starting as an API rexporting main functions of the great lib
35 -- text-metrics of Mark Karpov
37 -- | Levenshtein Distance
38 -- In information theory, Linguistics and computer science,
39 -- the Levenshtein distance is a string metric for measuring
40 -- the difference between two sequences.
41 -- See: https://en.wikipedia.org/wiki/Levenshtein_distance
43 levenshtein :: Text -> Text -> Int
44 levenshtein = DTM.levenshtein
46 -- | Return normalized Levenshtein distance between two 'Text' values.
47 -- Result is a non-negative rational number (represented as @'Ratio'
48 -- 'Data.Numeric.Natural'@), where 0 signifies no similarity between the
49 -- strings, while 1 means exact match.
51 levenshteinNorm :: Text -> Text -> Ratio Int
52 levenshteinNorm = DTM.levenshteinNorm
54 -- | Return Damerau-Levenshtein distance between two 'Text' values. The
55 -- function works like 'levenshtein', but the collection of allowed
56 -- operations also includes transposition of two /adjacent/ characters.
58 -- <https://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance>
60 damerauLevenshtein :: Text -> Text -> Int
61 damerauLevenshtein = DTM.damerauLevenshtein
63 -- damerau-Levenshtein distance normalized
65 damerauLevenshteinNorm :: Text -> Text -> Ratio Int
66 damerauLevenshteinNorm = DTM.damerauLevenshteinNorm
68 -- Treating inputs like sets
70 -- | Return overlap coefficient for two 'Text' values. Returned value
71 -- is in the range from 0 (no similarity) to 1 (exact match). Return 1
72 -- if both 'Text' values are empty.
74 -- See also: <https://en.wikipedia.org/wiki/Overlap_coefficient>.
75 overlap :: Text -> Text -> Ratio Int
80 -- measures dissimilarity between sample sets
81 jaccard :: Text -> Text -> Ratio Int
85 -- In information theory, the Hamming distance between two strings of
86 -- equal length is the number of positions at which the corresponding
87 -- symbols are different. In other words, it measures the minimum number of
88 -- substitutions required to change one string into the other
89 -- See: https://en.wikipedia.org/wiki/Hamming_distance
91 hamming :: Text -> Text -> Maybe Int