]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Core/Methods/Similarities.hs
[Tree] Flat tree API for search
[gargantext.git] / src / Gargantext / Core / Methods / Similarities.hs
1 {-|
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
8 Portability : POSIX
9
10 -}
11
12 {-# LANGUAGE Strict #-}
13
14 module Gargantext.Core.Methods.Similarities
15 where
16
17 import Data.Aeson
18 import Data.Array.Accelerate (Matrix)
19 import Data.Swagger
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
32
33 ------------------------------------------------------------------------
34 data Similarity = Conditional | Distributional
35 deriving (Show, Eq)
36
37 measure :: Similarity -> Matrix Int -> Matrix Double
38 measure Conditional x = measureConditional x
39 measure Distributional x = logDistributional2 x
40
41 ------------------------------------------------------------------------
42 withMetric :: GraphMetric -> Similarity
43 withMetric Order1 = Conditional
44 withMetric Order2 = Distributional
45
46 ------------------------------------------------------------------------
47 data GraphMetric = Order1 | Order2
48 deriving (Generic, Eq, Ord, Enum, Bounded, Show)
49
50 instance FromJSON GraphMetric
51 instance ToJSON GraphMetric
52 instance ToSchema GraphMetric
53 instance Arbitrary GraphMetric where
54 arbitrary = elements [ minBound .. maxBound ]
55
56 ------------------------------------------------------------------------
57
58 -- Let's take 2 different forms to produce another one:
59 hello_words :: [[Text]]
60 hello_words = map (Text.splitOn "-") wrds
61 where
62 wrds = [ "bio-logie"
63 , "socio-logie"
64 -- , "ana-logie"
65 -- , "micro-scope"
66 -- , "micro-phone"
67 -- , "micro-cosme"
68 -- -- , "micro-biote"
69 -- , "tele-scope"
70 -- , "tele-phone"
71 -- , "tele-surveillance"
72 -- , "macro-scope"
73 -- , "macro-cosme"
74 -- , "macro-biote"
75 ]
76
77 {-
78 hello_matrix ms' = measureConditional
79 $ map2mat Square 0 (Map.size ti)
80 $ toIndex ti ms
81 where
82 ms = coocOn identity ms'
83 (ti, it) = createIndices ms
84 -}
85