1 {-# LANGUAGE ScopedTypeVariables #-}
2 module Ngrams.Query.PaginationCorpus where
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
17 import Paths_gargantext
20 implementationElem :: NgramsElement
21 implementationElem = NgramsElement {
22 _ne_ngrams = "implementation"
25 , _ne_occurrences = Set.fromList [ NodeId 1, NodeId 2, NodeId 3, NodeId 4, NodeId 5 ]
27 , _ne_parent = Nothing
28 , _ne_children = mSetFromList [ "code", "functions", "language", "programs" ]
31 languagesElem :: NgramsElement
32 languagesElem = NgramsElement {
33 _ne_ngrams = NgramsTerm {unNgramsTerm = "languages"}
36 , _ne_occurrences = Set.fromList [ NodeId 1, NodeId 2 , NodeId 3 , NodeId 4 ]
38 , _ne_parent = Nothing
39 , _ne_children = mSetFromList [ "approach", "use" ]
42 termsElem :: NgramsElement
43 termsElem = NgramsElement {
44 _ne_ngrams = NgramsTerm {unNgramsTerm = "terms"}
47 , _ne_occurrences = Set.fromList [ NodeId 1, NodeId 2 , NodeId 3 ]
49 , _ne_parent = Nothing
50 , _ne_children = mSetFromList [ "algorithm", "evaluation", "monad", "programmers" ]
53 proofElem :: NgramsElement
54 proofElem = NgramsElement {
55 _ne_ngrams = NgramsTerm {unNgramsTerm = "proof"}
58 , _ne_occurrences = Set.fromList [ NodeId 1, NodeId 2 ]
60 , _ne_parent = Nothing
61 , _ne_children = mSetFromList [ "proofs" ]
64 sideEffectsElem :: NgramsElement
65 sideEffectsElem = NgramsElement {
66 _ne_ngrams = NgramsTerm {unNgramsTerm = "side effects"}
69 , _ne_occurrences = Set.fromList [ NodeId 1, NodeId 2, NodeId 3, NodeId 4, NodeId 5, NodeId 6 ]
71 , _ne_parent = Nothing
72 , _ne_children = mSetFromList [ ]
75 ooElem :: NgramsElement
76 ooElem = NgramsElement {
77 _ne_ngrams = NgramsTerm {unNgramsTerm = "object oriented"}
80 , _ne_occurrences = Set.fromList [ NodeId 1, NodeId 2, NodeId 3, NodeId 4, NodeId 5 ]
82 , _ne_parent = Nothing
83 , _ne_children = mSetFromList [ "null pointer exception" ]
86 javaElem :: NgramsElement
87 javaElem = NgramsElement {
88 _ne_ngrams = NgramsTerm {unNgramsTerm = "java"}
91 , _ne_occurrences = Set.fromList [ NodeId 1, NodeId 2, NodeId 3 ]
93 , _ne_parent = Nothing
94 , _ne_children = mSetFromList [ "JVM" ]
97 pascalElem :: NgramsElement
98 pascalElem = NgramsElement {
99 _ne_ngrams = NgramsTerm {unNgramsTerm = "pascal"}
101 , _ne_list = StopTerm
102 , _ne_occurrences = Set.fromList [ NodeId 1, NodeId 2 ]
104 , _ne_parent = Nothing
105 , _ne_children = mSetFromList [ "turbo", "borland" ]
108 haskellElem :: NgramsElement
109 haskellElem = NgramsElement {
110 _ne_ngrams = NgramsTerm {unNgramsTerm = "haskell"}
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 ]
115 , _ne_parent = Nothing
116 , _ne_children = mSetFromList [ ]
119 concHaskellElem :: NgramsElement
120 concHaskellElem = NgramsElement {
121 _ne_ngrams = NgramsTerm {unNgramsTerm = "concurrent haskell"}
123 , _ne_list = CandidateTerm
124 , _ne_occurrences = Set.fromList [ NodeId 1, NodeId 2, NodeId 3, NodeId 4, NodeId 5 ]
126 , _ne_parent = Nothing
127 , _ne_children = mSetFromList [ "Simon Marlow" ]
130 -- | A big (for the sake of the tests anyway) corpus which has
133 -- * 2 @CandidateTerm@s
134 paginationCorpus :: Versioned (Map NgramsTerm NgramsElement)
135 paginationCorpus = Versioned 0 $ Map.fromList [
137 ( "implementation", implementationElem)
138 , ( "languages", languagesElem)
139 , ( "terms", termsElem)
140 , ("proof", proofElem)
143 , ("side effects", sideEffectsElem)
144 , ("object oriented", ooElem)
146 , ("pascal", pascalElem)
149 , ("haskell", haskellElem)
150 , ("concurrent haskell", concHaskellElem)
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 #-}