[terms] added test for multi terms docNgrams functionality

parent b7d03cf6
Pipeline #7648 failed with stages
in 53 minutes and 38 seconds
...@@ -437,6 +437,13 @@ experience strange errors like ...@@ -437,6 +437,13 @@ experience strange errors like
fatal: Could not parse object '316d48b6a89593faaf1f2102e9714cea7e416e56'. fatal: Could not parse object '316d48b6a89593faaf1f2102e9714cea7e416e56'.
``` ```
If you're using emacs, you could fire up an interactive REPL directly
via e.g. `haskell-interactive-bring`.
In repl, the `.ghci` file from our repo would be loaded which contains
a useful `:ggload` macro that imports all exposed modules from the
`gargantext` library.
## Running the tests <a name="running-tests"></a> ## Running the tests <a name="running-tests"></a>
Running the tests can be done via the following command: Running the tests can be done via the following command:
......
...@@ -4,7 +4,7 @@ module Test.Ngrams.Terms (tests) where ...@@ -4,7 +4,7 @@ module Test.Ngrams.Terms (tests) where
import Data.HashMap.Strict qualified as HashMap import Data.HashMap.Strict qualified as HashMap
import Data.Map.Strict qualified as Map import Data.Map.Strict qualified as Map
import Gargantext.API.Ngrams import Gargantext.API.Ngrams.Types ( NgramsTerm )
import Gargantext.Core (Lang(..)) import Gargantext.Core (Lang(..))
import Gargantext.Core.Text.Context (TermList) import Gargantext.Core.Text.Context (TermList)
import Gargantext.Core.Text.Ngrams (NgramsType(NgramsTerms), Ngrams(..)) import Gargantext.Core.Text.Ngrams (NgramsType(NgramsTerms), Ngrams(..))
...@@ -15,8 +15,8 @@ import Gargantext.Database.Admin.Types.Hyperdata.Document ( HyperdataDocument(.. ...@@ -15,8 +15,8 @@ import Gargantext.Database.Admin.Types.Hyperdata.Document ( HyperdataDocument(..
import Gargantext.Database.Admin.Types.Node (NodeId(..)) import Gargantext.Database.Admin.Types.Node (NodeId(..))
import Gargantext.Database.Schema.Context ( ContextPolyOnlyId(..) ) import Gargantext.Database.Schema.Context ( ContextPolyOnlyId(..) )
import Gargantext.Prelude import Gargantext.Prelude
import Test.Tasty import Test.Tasty ( TestTree, testGroup )
import Test.Tasty.HUnit import Test.Tasty.HUnit ( Assertion, testCase, (@?=) )
tests :: TestTree tests :: TestTree
...@@ -34,6 +34,7 @@ unitTests = testGroup "Terms tests" ...@@ -34,6 +34,7 @@ unitTests = testGroup "Terms tests"
, testCase "termsInText works 04 (related to issue #221)" testTermsInText04 , testCase "termsInText works 04 (related to issue #221)" testTermsInText04
, testCase "extractTermsWithList' works 01" testExtractTermsWithList'01 , testCase "extractTermsWithList' works 01" testExtractTermsWithList'01
, testCase "extractTermsWithList' works 02 (#471)" testExtractTermsWithList'02
, testCase "docNgrams works 01" testDocNgrams01 , testCase "docNgrams works 01" testDocNgrams01
, testCase "docNgrams works 02" testDocNgrams02 , testCase "docNgrams works 02" testDocNgrams02
...@@ -112,12 +113,18 @@ testExtractTermsWithList'01 = do ...@@ -112,12 +113,18 @@ testExtractTermsWithList'01 = do
let termList = [(["chat blanc"], [["chat","blanc"]])] :: TermList let termList = [(["chat blanc"], [["chat","blanc"]])] :: TermList
extractTermsWithList' (buildPatterns termList) "Le chat blanc" @?= ["chat blanc"] extractTermsWithList' (buildPatterns termList) "Le chat blanc" @?= ["chat blanc"]
-- #471
testExtractTermsWithList'02 :: Assertion
testExtractTermsWithList'02 = do
let termList = [(["patients"], []), (["patients", "with"], [])] :: TermList
extractTermsWithList' (buildPatterns termList) "patients with problems" @?= ["patients", "patientswith"]
testDocNgrams01 :: Assertion testDocNgrams01 :: Assertion
testDocNgrams01 = do testDocNgrams01 = do
let terms = ["hello", "world"] :: [NgramsTerm] let terms = ["hello", "world"] :: [NgramsTerm]
let hd = emptyHyperdataDocument { _hd_title = Just "hello world" let hd = emptyHyperdataDocument { _hd_title = Just "hello world"
, _hd_abstract = Nothing } , _hd_abstract = Nothing }
let ctx = ContextOnlyId 1 hd let ctx = ContextOnlyId { _context_oid_id = 1, _context_oid_hyperdata = hd }
let dNgrams = docNgrams EN terms ctx let dNgrams = docNgrams EN terms ctx
length dNgrams @?= 2 length dNgrams @?= 2
...@@ -126,7 +133,7 @@ testDocNgrams02 = do ...@@ -126,7 +133,7 @@ testDocNgrams02 = do
let terms = ["hello", "world"] :: [NgramsTerm] let terms = ["hello", "world"] :: [NgramsTerm]
let hd = emptyHyperdataDocument { _hd_title = Just "hello world, kaboom" let hd = emptyHyperdataDocument { _hd_title = Just "hello world, kaboom"
, _hd_abstract = Nothing } , _hd_abstract = Nothing }
let ctx = ContextOnlyId 1 hd let ctx = ContextOnlyId { _context_oid_id = 1, _context_oid_hyperdata = hd }
let dNgrams = docNgrams EN terms ctx let dNgrams = docNgrams EN terms ctx
length dNgrams @?= 2 length dNgrams @?= 2
...@@ -135,10 +142,10 @@ testNgramsByDoc01 = do ...@@ -135,10 +142,10 @@ testNgramsByDoc01 = do
let terms = ["hello", "world"] :: [NgramsTerm] let terms = ["hello", "world"] :: [NgramsTerm]
let hd1 = emptyHyperdataDocument { _hd_title = Just "hello world, kaboom" let hd1 = emptyHyperdataDocument { _hd_title = Just "hello world, kaboom"
, _hd_abstract = Nothing } , _hd_abstract = Nothing }
let ctx1 = ContextOnlyId 1 hd1 let ctx1 = ContextOnlyId { _context_oid_id = 1, _context_oid_hyperdata = hd1 }
let hd2 = emptyHyperdataDocument { _hd_title = Just "world, boom world" let hd2 = emptyHyperdataDocument { _hd_title = Just "world, boom world"
, _hd_abstract = Nothing } , _hd_abstract = Nothing }
let ctx2 = ContextOnlyId 2 hd2 let ctx2 = ContextOnlyId { _context_oid_id = 2, _context_oid_hyperdata = hd2 }
ngramsByDoc EN NgramsTerms terms ctx1 @?= ngramsByDoc EN NgramsTerms terms ctx1 @?=
HashMap.fromList HashMap.fromList
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment