]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Ngrams/Metrics.hs
[CORS] Firewall fix negation.
[gargantext.git] / src / Gargantext / Ngrams / Metrics.hs
1 {-|
2 Module : Gargantext.Ngrams.Metrics
3 Description : Short description
4 Copyright : (c) Some Guy, 2013
5 Someone Else, 2014
6 License : GPL-3
7 Maintainer : sample@email.com
8 Stability : experimental
9 Portability : POSIX
10
11 Here is a longer description of this module, containing some
12 commentary with @some markup@.
13 -}
14
15 module Gargantext.Ngrams.Metrics (levenshtein
16 , levenshteinNorm
17 , damerauLevenshtein
18 , damerauLevenshteinNorm
19 , overlap
20 , jaccard
21 , hamming
22 ) where
23
24 import Gargantext.Prelude
25
26 import Data.Text (Text)
27 import GHC.Real (Ratio)
28 import qualified Data.Text.Metrics as DTM
29
30 {- * Example de titre
31 -}
32
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
36
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
42 --
43 levenshtein :: Text -> Text -> Int
44 levenshtein = DTM.levenshtein
45
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.
50 --
51 levenshteinNorm :: Text -> Text -> Ratio Int
52 levenshteinNorm = DTM.levenshteinNorm
53
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.
57 -- See also:
58 -- <https://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance>
59 --
60 damerauLevenshtein :: Text -> Text -> Int
61 damerauLevenshtein = DTM.damerauLevenshtein
62
63 -- damerau-Levenshtein distance normalized
64 --
65 damerauLevenshteinNorm :: Text -> Text -> Ratio Int
66 damerauLevenshteinNorm = DTM.damerauLevenshteinNorm
67
68 -- Treating inputs like sets
69
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.
73 --
74 -- See also: <https://en.wikipedia.org/wiki/Overlap_coefficient>.
75 overlap :: Text -> Text -> Ratio Int
76 overlap = DTM.overlap
77
78
79 -- | Jaccard distance
80 -- measures dissimilarity between sample sets
81 jaccard :: Text -> Text -> Ratio Int
82 jaccard = DTM.jaccard
83
84 -- | Hamming Distance
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
90
91 hamming :: Text -> Text -> Maybe Int
92 hamming = DTM.hamming
93
94