Spec.purs 3.78 KB
Newer Older
1 2 3 4 5
module Gargantext.Components.NgramsTable.Spec where

import Prelude
import Data.Maybe (Maybe(..))
import Data.Tuple (Tuple(..))
6
import Gargantext.Components.NgramsTable.Core (highlightNgrams, NgramsElement(..), NgramsTable(..))
7 8 9 10 11 12 13
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

14
{-
15
spec :: Spec Unit
16 17 18 19 20 21 22 23 24 25 26
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)
27
  describe "NgramsTable.highlightNgrams" do
28
    it "works on a simple example" do
29
      let table = NgramsTable
30
                    (Map.fromFoldable [tne "graph"     GraphTerm
31 32
                                      ,tne "which"     StopTerm
                                      ,tne "stops"     StopTerm
33 34
                                      ,tne "candidate" CandidateTerm
                                      ])
35
          input = "this is a graph about a biography which stops at every candidate"
36
          output = [Tuple "this is a " Nothing
37
                   ,Tuple "graph" (Just GraphTerm)
38
                   ,Tuple " about a biography " Nothing
39 40 41
                   ,Tuple "which" (Just StopTerm)
                   ,Tuple " " Nothing
                   ,Tuple "stops" (Just StopTerm)
42
                   ,Tuple " at every " Nothing
43 44
                   ,Tuple "candidate" (Just CandidateTerm)
                   ]
Przemyslaw Kaminski's avatar
Przemyslaw Kaminski committed
45
      highlightNgrams CTabTerms table input `shouldEqual` output
46 47 48 49 50 51 52 53 54 55

    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
                                      ])
56
          input = "This is a new state of the"
57
          output = [Tuple "This " Nothing
58 59 60 61 62 63 64 65 66 67 68
                   ,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)
69
                   ]
Przemyslaw Kaminski's avatar
Przemyslaw Kaminski committed
70
      highlightNgrams CTabTerms table input `shouldEqual` output
71 72 73 74 75 76 77 78

    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"
79
          output = [Tuple "This is " Nothing
80
                   ,Tuple "from" (Just GraphTerm)
81
                   ,Tuple " space " Nothing
82
                   ,Tuple "images" (Just GraphTerm)
83
                   ]
Przemyslaw Kaminski's avatar
Przemyslaw Kaminski committed
84
      highlightNgrams CTabTerms table input `shouldEqual` output
85 86 87 88 89 90 91 92

    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
93
                   ]
Przemyslaw Kaminski's avatar
Przemyslaw Kaminski committed
94
      highlightNgrams CTabTerms table input `shouldEqual` output
95
-}