Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Grégoire Locqueville
purescript-gargantext
Commits
69038bce
Commit
69038bce
authored
Feb 09, 2021
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[test] ngrams: fix pattern overlap test
parent
c23bbf37
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
33 deletions
+52
-33
Core.purs
src/Gargantext/Components/NgramsTable/Core.purs
+1
-0
Spec.purs
test/Gargantext/Components/NgramsTable/Spec.purs
+51
-33
No files found.
src/Gargantext/Components/NgramsTable/Core.purs
View file @
69038bce
...
@@ -28,6 +28,7 @@ module Gargantext.Components.NgramsTable.Core
...
@@ -28,6 +28,7 @@ module Gargantext.Components.NgramsTable.Core
, NgramsTablePatch
, NgramsTablePatch
, NgramsPatch(..)
, NgramsPatch(..)
, CoreState
, CoreState
, HighlightElement
, highlightNgrams
, highlightNgrams
, initialPageParams
, initialPageParams
, loadNgramsTable
, loadNgramsTable
...
...
test/Gargantext/Components/NgramsTable/Spec.purs
View file @
69038bce
module Gargantext.Components.NgramsTable.Spec where
module Gargantext.Components.NgramsTable.Spec where
import Prelude
import Prelude
import Data.List as L
import Data.Maybe (Maybe(..))
import Data.Maybe (Maybe(..))
import Data.Map as Map
import Data.Map as Map
import Data.Set as Set
import Data.Set as Set
import Data.Tuple (Tuple(..))
import Data.Tuple (Tuple(..))
import Test.Spec (Spec, describe, it)
import Test.Spec (Spec, describe, it)
import Test.Spec.Assertions (shouldEqual)
--
import Test.Spec.Assertions (shouldEqual)
-- import Test.Spec.QuickCheck (quickCheck')
-- import Test.Spec.QuickCheck (quickCheck')
import Gargantext.Components.NgramsTable.Core (highlightNgrams, NgramsElement(..), NgramsRepoElement(..), NgramsTable(..), NgramsTerm, normNgram)
import Test.Utils (shouldEqualArray)
import Gargantext.Components.NgramsTable.Core (highlightNgrams, HighlightElement, NgramsElement(..), NgramsRepoElement(..), NgramsTable(..), NgramsTerm, normNgram)
import Gargantext.Types (CTabNgramType(..), TermList(..))
import Gargantext.Types (CTabNgramType(..), TermList(..))
...
@@ -43,6 +46,15 @@ tnre ngrams list ngramType = Tuple normed (nre ngrams list ngramType)
...
@@ -43,6 +46,15 @@ tnre ngrams list ngramType = Tuple normed (nre ngrams list ngramType)
where
where
normed = normNgram ngramType ngrams
normed = normNgram ngramType ngrams
highlightNil :: String -> HighlightElement
highlightNil s = Tuple s L.Nil
highlightTuple :: String -> CTabNgramType -> TermList -> Tuple NgramsTerm TermList
highlightTuple s ngramType term = Tuple (normNgram ngramType s) term
highlightSingleton :: String -> CTabNgramType -> TermList -> HighlightElement
highlightSingleton s ngramType term = Tuple s (L.singleton $ highlightTuple s ngramType term)
spec :: Spec Unit
spec :: Spec Unit
spec = do
spec = do
describe "NgramsTable.highlightNgrams" do
describe "NgramsTable.highlightNgrams" do
...
@@ -55,14 +67,15 @@ spec = do
...
@@ -55,14 +67,15 @@ spec = do
]
]
, ngrams_scores: Map.fromFoldable [] }
, ngrams_scores: Map.fromFoldable [] }
input = "this is a graph about a biography which stops at every candidate"
input = "this is a graph about a biography which stops at every candidate"
output = [ Tuple "this is a graph about a biography " Nothing
output = [ highlightNil " this is a graph about a biography "
, Tuple "which" (Just StopTerm)
, highlightSingleton " which" ngramType StopTerm
, Tuple " " Nothing
, highlightNil " "
, Tuple "stops" (Just StopTerm)
, highlightSingleton " stops" ngramType StopTerm
, Tuple " at every " Nothing
, highlightNil " at every "
, Tuple "candidate" (Just CandidateTerm)
, highlightSingleton " candidate" ngramType CandidateTerm
, highlightNil " "
]
]
highlightNgrams CTabTerms table input `shouldEqual` output
highlightNgrams CTabTerms table input `shouldEqual
Array
` output
it "works when pattern overlaps" do
it "works when pattern overlaps" do
let ngramType = CTabSources
let ngramType = CTabSources
...
@@ -73,15 +86,15 @@ spec = do
...
@@ -73,15 +86,15 @@ spec = do
]
]
, ngrams_scores: Map.fromFoldable [] }
, ngrams_scores: Map.fromFoldable [] }
input = "This is a new state of the"
input = "This is a new state of the"
output = [
Tuple "This " Nothing
output = [
highlightNil " This "
,
Tuple "is" (Just StopTerm)
,
highlightSingleton " is" ngramType StopTerm
,
Tuple " " Nothing
,
highlightNil " "
,
Tuple "a" (Just StopTerm)
,
highlightSingleton " a" ngramType StopTerm
,
Tuple " new state " Nothing
,
highlightNil " new state "
,
Tuple "of" (Just StopTerm)
,
highlightSingleton " of" ngramType StopTerm
,
Tuple " the" Nothing
,
highlightNil " the "
]
]
highlightNgrams CTabTerms table input `shouldEqual` output
highlightNgrams CTabTerms table input `shouldEqual
Array
` output
it "works when pattern overlaps 2" do
it "works when pattern overlaps 2" do
let ngramType = CTabSources
let ngramType = CTabSources
...
@@ -92,26 +105,31 @@ spec = do
...
@@ -92,26 +105,31 @@ spec = do
]
]
, ngrams_scores: Map.fromFoldable [] }
, ngrams_scores: Map.fromFoldable [] }
input = "This is from space images"
input = "This is from space images"
output = [ Tuple "This is " Nothing
output = [ highlightNil " This is "
, Tuple "from" (Just CandidateTerm)
, highlightSingleton " from" ngramType CandidateTerm
, Tuple " space " Nothing
, highlightNil " space "
, Tuple "images" (Just CandidateTerm)
, highlightSingleton " images" ngramType CandidateTerm
, highlightNil " "
]
]
highlightNgrams CTabTerms table input `shouldEqual` output
highlightNgrams CTabTerms table input `shouldEqual
Array
` output
it "works when pattern overlaps 3" do
it "works when pattern overlaps 3" do
let ngramType = CTabSources
let ngramType = CTabSources
let table = NgramsTable
let table = NgramsTable
{ ngrams_repo_elements: Map.fromFoldable [ tnre "
fusion" Map
Term ngramType
{ ngrams_repo_elements: Map.fromFoldable [ tnre "
something" Candidate
Term ngramType
, tnre "
calculate fusion" Candidate
Term ngramType
, tnre "
something different" Map
Term ngramType
]
]
, ngrams_scores: Map.fromFoldable [] }
, ngrams_scores: Map.fromFoldable [] }
input = "Model has been used to calculate fusion cross sections"
input = "and now for something different"
output = [ Tuple "Model has been used to " Nothing
output = [ highlightNil " and now for "
, Tuple "calculate fusion" (Just CandidateTerm)
, Tuple " something" $ L.fromFoldable [
, Tuple " sections " Nothing
highlightTuple "something different" ngramType MapTerm
, highlightTuple "something" ngramType CandidateTerm
]
, Tuple " different" $ L.singleton $ highlightTuple "something different" ngramType MapTerm
, highlightNil " "
]
]
highlightNgrams CTabTerms table input `shouldEqual` output
highlightNgrams CTabTerms table input `shouldEqual
Array
` output
it "works with punctuation" do
it "works with punctuation" do
let ngramType = CTabSources
let ngramType = CTabSources
...
@@ -119,8 +137,8 @@ spec = do
...
@@ -119,8 +137,8 @@ spec = do
{ ngrams_repo_elements: Map.fromFoldable [ tnre "graph" CandidateTerm ngramType ]
{ ngrams_repo_elements: Map.fromFoldable [ tnre "graph" CandidateTerm ngramType ]
, ngrams_scores: Map.fromFoldable [] }
, ngrams_scores: Map.fromFoldable [] }
input = "before graph, after"
input = "before graph, after"
output = [
Tuple "before " Nothing
output = [
highlightNil " before "
,
Tuple "graph" (Just CandidateTerm)
,
highlightSingleton " graph" ngramType CandidateTerm
,
Tuple ", after" Nothing
,
highlightNil ", after "
]
]
highlightNgrams CTabTerms table input `shouldEqual` output
highlightNgrams CTabTerms table input `shouldEqual
Array
` output
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment