2 Module : Gargantext.Graph.Similarities
3 Description : Similarity management tools
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
12 {-# LANGUAGE Strict #-}
14 module Gargantext.Core.Methods.Similarities
18 import Data.Array.Accelerate (Matrix)
20 import Data.Text (Text)
21 import GHC.Generics (Generic)
22 import Gargantext.Core.Methods.Similarities.Accelerate.Conditional (measureConditional)
23 import Gargantext.Core.Methods.Similarities.Accelerate.Distributional (logDistributional2)
24 -- import Gargantext.Core.Text.Metrics.Count (coocOn)
25 -- import Gargantext.Core.Viz.Graph.Index
26 import Gargantext.Prelude (Ord, Eq, Int, Double, Show, map)
27 import Prelude (Enum, Bounded, minBound, maxBound)
28 import Test.QuickCheck (elements)
29 import Test.QuickCheck.Arbitrary
30 -- import qualified Data.Map as Map
31 import qualified Data.Text as Text
33 ------------------------------------------------------------------------
34 data Similarity = Conditional | Distributional_A | Distributional_B
37 measure :: Similarity -> Matrix Int -> Matrix Double
38 measure Conditional x = measureConditional x
39 measure Distributional_A x = logDistributional2 1 x
40 measure Distributional_B x = logDistributional2 0 x
42 ------------------------------------------------------------------------
43 withMetric :: GraphMetric -> Similarity
44 withMetric Order1 = Conditional
45 withMetric Order2_A = Distributional_A
46 withMetric _ = Distributional_B
48 ------------------------------------------------------------------------
49 -- Order2 type is for keeping Database json compatibility
50 -- it is supposed to be removed in the future
51 data GraphMetric = Order1 | Order2 | Order2_A | Order2_B
52 deriving (Generic, Eq, Ord, Enum, Bounded, Show)
54 instance FromJSON GraphMetric
55 instance ToJSON GraphMetric
56 instance ToSchema GraphMetric
57 instance Arbitrary GraphMetric where
58 arbitrary = elements [ minBound .. maxBound ]
60 ------------------------------------------------------------------------
62 -- Let's take 2 different forms to produce another one:
63 hello_words :: [[Text]]
64 hello_words = map (Text.splitOn "-") wrds
75 -- , "tele-surveillance"
82 hello_matrix ms' = measureConditional
83 $ map2mat Square 0 (Map.size ti)
86 ms = coocOn identity ms'
87 (ti, it) = createIndices ms