]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Core/Methods/Similarities.hs
Merge branch 'dev' into dev-openalex
[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_A | Distributional_B
35 deriving (Show, Eq)
36
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
41
42 ------------------------------------------------------------------------
43 withMetric :: GraphMetric -> Similarity
44 withMetric Order1 = Conditional
45 withMetric Order2_A = Distributional_A
46 withMetric _ = Distributional_B
47
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)
53
54 instance FromJSON GraphMetric
55 instance ToJSON GraphMetric
56 instance ToSchema GraphMetric
57 instance Arbitrary GraphMetric where
58 arbitrary = elements [ minBound .. maxBound ]
59
60 ------------------------------------------------------------------------
61
62 -- Let's take 2 different forms to produce another one:
63 hello_words :: [[Text]]
64 hello_words = map (Text.splitOn "-") wrds
65 where
66 wrds = [ "bio-logie"
67 , "socio-logie"
68 -- , "ana-logie"
69 -- , "micro-scope"
70 -- , "micro-phone"
71 -- , "micro-cosme"
72 -- -- , "micro-biote"
73 -- , "tele-scope"
74 -- , "tele-phone"
75 -- , "tele-surveillance"
76 -- , "macro-scope"
77 -- , "macro-cosme"
78 -- , "macro-biote"
79 ]
80
81 {-
82 hello_matrix ms' = measureConditional
83 $ map2mat Square 0 (Map.size ti)
84 $ toIndex ti ms
85 where
86 ms = coocOn identity ms'
87 (ti, it) = createIndices ms
88 -}
89