1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
module Gargantext.Components.NgramsTable.Spec where
import Prelude
import Data.Maybe (Maybe(..))
import Data.Tuple (Tuple(..))
import Gargantext.Components.NgramsTable.Core (highlightNgrams, NgramsElement(..), NgramsTable(..))
import Gargantext.Types (TermList(..))
import Test.Spec (Spec, describe, it)
import Test.Spec.Assertions (shouldEqual)
-- import Test.Spec.QuickCheck (quickCheck')
import Data.Map as Map
import Data.Set as Set
{-
spec :: Spec Unit
spec = do
let ne ngrams list =
NgramsElement
{ ngrams
, list
, occurrences: 0
, parent: Nothing
, root: Nothing
, children: Set.empty
}
tne ngrams list = Tuple ngrams (ne ngrams list)
describe "NgramsTable.highlightNgrams" do
it "works on a simple example" do
let table = NgramsTable
(Map.fromFoldable [tne "graph" GraphTerm
,tne "which" StopTerm
,tne "stops" StopTerm
,tne "candidate" CandidateTerm
])
input = "this is a graph about a biography which stops at every candidate"
output = [Tuple "this is a " Nothing
,Tuple "graph" (Just GraphTerm)
,Tuple " about a biography " Nothing
,Tuple "which" (Just StopTerm)
,Tuple " " Nothing
,Tuple "stops" (Just StopTerm)
,Tuple " at every " Nothing
,Tuple "candidate" (Just CandidateTerm)
]
highlightNgrams CTabTerms table input `shouldEqual` output
it "works when pattern overlaps" do
let table = NgramsTable
(Map.fromFoldable [tne "is" StopTerm
,tne "a" StopTerm
,tne "of" StopTerm
,tne "new" GraphTerm
,tne "the" GraphTerm
,tne "state" GraphTerm
])
input = "This is a new state of the"
output = [Tuple "This " Nothing
,Tuple "is" (Just StopTerm)
,Tuple " " Nothing
,Tuple "a" (Just StopTerm)
,Tuple " " Nothing
,Tuple "new" (Just GraphTerm)
,Tuple " " Nothing
,Tuple "state" (Just GraphTerm)
,Tuple " " Nothing
,Tuple "of" (Just StopTerm)
,Tuple " " Nothing
,Tuple "the" (Just GraphTerm)
]
highlightNgrams CTabTerms table input `shouldEqual` output
it "works when pattern overlaps 2" do
let table = NgramsTable
(Map.fromFoldable [tne "from" GraphTerm
,tne "i" StopTerm
,tne "images" GraphTerm
])
input = "This is from space images"
output = [Tuple "This is " Nothing
,Tuple "from" (Just GraphTerm)
,Tuple " space " Nothing
,Tuple "images" (Just GraphTerm)
]
highlightNgrams CTabTerms table input `shouldEqual` output
it "works with punctuation" do
let table = NgramsTable
(Map.fromFoldable [tne "graph" GraphTerm])
input = "before graph, after"
output = [Tuple "before " Nothing
,Tuple "graph" (Just GraphTerm)
,Tuple ", after" Nothing
]
highlightNgrams CTabTerms table input `shouldEqual` output
-}