]> Git — Sourcephile - gargantext.git/blob - src-test/Ngrams/Query/PaginationCorpus.hs
Merge remote-tracking branch 'origin/dev-phyloDebug' into 206-dev-phylo
[gargantext.git] / src-test / Ngrams / Query / PaginationCorpus.hs
1 {-# LANGUAGE ScopedTypeVariables #-}
2 module Ngrams.Query.PaginationCorpus where
3
4 import Prelude
5
6 import Data.Aeson
7 import Data.Map.Strict (Map)
8 import Gargantext.API.Ngrams
9 import Gargantext.API.Ngrams.Types
10 import Gargantext.Core.Types.Main
11 import Gargantext.Database.Admin.Types.Node
12 import System.IO.Unsafe
13 import qualified Data.ByteString as B
14 import qualified Data.Map.Strict as Map
15 import qualified Data.Set as Set
16
17 import Paths_gargantext
18
19
20 implementationElem :: NgramsElement
21 implementationElem = NgramsElement {
22 _ne_ngrams = "implementation"
23 , _ne_size = 1
24 , _ne_list = MapTerm
25 , _ne_occurrences = Set.fromList [ NodeId 1, NodeId 2, NodeId 3, NodeId 4, NodeId 5 ]
26 , _ne_root = Nothing
27 , _ne_parent = Nothing
28 , _ne_children = mSetFromList [ "code", "functions", "language", "programs" ]
29 }
30
31 languagesElem :: NgramsElement
32 languagesElem = NgramsElement {
33 _ne_ngrams = NgramsTerm {unNgramsTerm = "languages"}
34 , _ne_size = 1
35 , _ne_list = MapTerm
36 , _ne_occurrences = Set.fromList [ NodeId 1, NodeId 2 , NodeId 3 , NodeId 4 ]
37 , _ne_root = Nothing
38 , _ne_parent = Nothing
39 , _ne_children = mSetFromList [ "approach", "use" ]
40 }
41
42 termsElem :: NgramsElement
43 termsElem = NgramsElement {
44 _ne_ngrams = NgramsTerm {unNgramsTerm = "terms"}
45 , _ne_size = 1
46 , _ne_list = MapTerm
47 , _ne_occurrences = Set.fromList [ NodeId 1, NodeId 2 , NodeId 3 ]
48 , _ne_root = Nothing
49 , _ne_parent = Nothing
50 , _ne_children = mSetFromList [ "algorithm", "evaluation", "monad", "programmers" ]
51 }
52
53 proofElem :: NgramsElement
54 proofElem = NgramsElement {
55 _ne_ngrams = NgramsTerm {unNgramsTerm = "proof"}
56 , _ne_size = 1
57 , _ne_list = MapTerm
58 , _ne_occurrences = Set.fromList [ NodeId 1, NodeId 2 ]
59 , _ne_root = Nothing
60 , _ne_parent = Nothing
61 , _ne_children = mSetFromList [ "proofs" ]
62 }
63
64 sideEffectsElem :: NgramsElement
65 sideEffectsElem = NgramsElement {
66 _ne_ngrams = NgramsTerm {unNgramsTerm = "side effects"}
67 , _ne_size = 1
68 , _ne_list = StopTerm
69 , _ne_occurrences = Set.fromList [ NodeId 1, NodeId 2, NodeId 3, NodeId 4, NodeId 5, NodeId 6 ]
70 , _ne_root = Nothing
71 , _ne_parent = Nothing
72 , _ne_children = mSetFromList [ ]
73 }
74
75 ooElem :: NgramsElement
76 ooElem = NgramsElement {
77 _ne_ngrams = NgramsTerm {unNgramsTerm = "object oriented"}
78 , _ne_size = 1
79 , _ne_list = StopTerm
80 , _ne_occurrences = Set.fromList [ NodeId 1, NodeId 2, NodeId 3, NodeId 4, NodeId 5 ]
81 , _ne_root = Nothing
82 , _ne_parent = Nothing
83 , _ne_children = mSetFromList [ "null pointer exception" ]
84 }
85
86 javaElem :: NgramsElement
87 javaElem = NgramsElement {
88 _ne_ngrams = NgramsTerm {unNgramsTerm = "java"}
89 , _ne_size = 1
90 , _ne_list = StopTerm
91 , _ne_occurrences = Set.fromList [ NodeId 1, NodeId 2, NodeId 3 ]
92 , _ne_root = Nothing
93 , _ne_parent = Nothing
94 , _ne_children = mSetFromList [ "JVM" ]
95 }
96
97 pascalElem :: NgramsElement
98 pascalElem = NgramsElement {
99 _ne_ngrams = NgramsTerm {unNgramsTerm = "pascal"}
100 , _ne_size = 1
101 , _ne_list = StopTerm
102 , _ne_occurrences = Set.fromList [ NodeId 1, NodeId 2 ]
103 , _ne_root = Nothing
104 , _ne_parent = Nothing
105 , _ne_children = mSetFromList [ "turbo", "borland" ]
106 }
107
108 haskellElem :: NgramsElement
109 haskellElem = NgramsElement {
110 _ne_ngrams = NgramsTerm {unNgramsTerm = "haskell"}
111 , _ne_size = 1
112 , _ne_list = CandidateTerm
113 , _ne_occurrences = Set.fromList [ NodeId 1, NodeId 2, NodeId 3, NodeId 4, NodeId 5, NodeId 6, NodeId 7, NodeId 8 ]
114 , _ne_root = Nothing
115 , _ne_parent = Nothing
116 , _ne_children = mSetFromList [ ]
117 }
118
119 concHaskellElem :: NgramsElement
120 concHaskellElem = NgramsElement {
121 _ne_ngrams = NgramsTerm {unNgramsTerm = "concurrent haskell"}
122 , _ne_size = 1
123 , _ne_list = CandidateTerm
124 , _ne_occurrences = Set.fromList [ NodeId 1, NodeId 2, NodeId 3, NodeId 4, NodeId 5 ]
125 , _ne_root = Nothing
126 , _ne_parent = Nothing
127 , _ne_children = mSetFromList [ "Simon Marlow" ]
128 }
129
130 -- | A big (for the sake of the tests anyway) corpus which has
131 -- * 4 @MapTerm@s
132 -- * 4 @StopTerm@s
133 -- * 2 @CandidateTerm@s
134 paginationCorpus :: Versioned (Map NgramsTerm NgramsElement)
135 paginationCorpus = Versioned 0 $ Map.fromList [
136 -- Map terms
137 ( "implementation", implementationElem)
138 , ( "languages", languagesElem)
139 , ( "terms", termsElem)
140 , ("proof", proofElem)
141
142 -- Stop terms
143 , ("side effects", sideEffectsElem)
144 , ("object oriented", ooElem)
145 , ("java", javaElem)
146 , ("pascal", pascalElem)
147
148 -- Candidate terms
149 , ("haskell", haskellElem)
150 , ("concurrent haskell", concHaskellElem)
151 ]
152
153 quantumComputingCorpus :: Versioned (Map NgramsTerm NgramsElement)
154 quantumComputingCorpus = unsafePerformIO $ do
155 pth <- getDataFileName "test-data/ngrams/GarganText_NgramsTerms-QuantumComputing.json"
156 jsonBlob <- B.readFile pth
157 case eitherDecodeStrict' jsonBlob of
158 Left err -> error err
159 Right (Versioned ver (mp :: Map NgramsTerm NgramsRepoElement)) ->
160 pure $ Versioned ver (Map.mapWithKey (\k -> ngramsElementFromRepo k) mp)
161 {-# NOINLINE quantumComputingCorpus #-}