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 (logDistributional)
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
37 measure :: Similarity -> Matrix Int -> Matrix Double
38 measure Conditional x = measureConditional x
39 measure Distributional x = logDistributional x
41 ------------------------------------------------------------------------
42 withMetric :: GraphMetric -> Similarity
43 withMetric Order1 = Conditional
44 withMetric Order2 = Distributional
46 ------------------------------------------------------------------------
47 data GraphMetric = Order1 | Order2
48 deriving (Generic, Eq, Ord, Enum, Bounded, Show)
50 instance FromJSON GraphMetric
51 instance ToJSON GraphMetric
52 instance ToSchema GraphMetric
53 instance Arbitrary GraphMetric where
54 arbitrary = elements [ minBound .. maxBound ]
56 ------------------------------------------------------------------------
58 -- Let's take 2 different forms to produce another one:
59 hello_words :: [[Text]]
60 hello_words = map (Text.splitOn "-") wrds
71 -- , "tele-surveillance"
78 hello_matrix ms' = measureConditional
79 $ map2mat Square 0 (Map.size ti)
82 ms = coocOn identity ms'
83 (ti, it) = createIndices ms