]> Git — Sourcephile - gargantext.git/blob - test/Ngrams.hs
[CLEAN] Moving CoreNLP in Ngrams folder.
[gargantext.git] / test / Ngrams.hs
1 {-# LANGUAGE OverloadedStrings #-}
2 {-# LANGUAGE ScopedTypeVariables #-}
3
4 import Test.Hspec
5 import Test.QuickCheck
6 import Control.Exception (evaluate)
7
8
9 import Data.Text (Text)
10
11 import Data.Gargantext.Prelude
12 import Data.Gargantext.Types.Main (Language(..))
13 import Data.Gargantext.Ngrams
14 import Data.Gargantext.Ngrams.Occurrences (parseOccurrences)
15 import Data.Gargantext.Ngrams.Parser (extractNgrams, selectNgrams)
16
17
18 ngramsExtractionTest EN = hspec $ do
19 describe "Ngrams extraction in English Language" $ do
20 let textTest = [ "Alcoholic extract of Kaempferia galanga was tested for analgesic and antiinflammatory activities in animal models. ", "Three doses, 300 mg/kg, 600 mg/kg and 1200 mg/kg of the plant extract prepared as a suspension in 2 ml of 2% gum acacia were used. ", " Acute and sub acute inflammatory activities were studied in rats by carrageenan induced paw edema and cotton pellet induced granuloma models respectively. ", "In both models, the standard drug used was aspirin 100 mg/kg. ", "Two doses 600 mg/kg and 1200 mg/kg of plant extract exhibited significant (P<0.001) antiinflammatory activity in carrageenan model and cotton pellet granuloma model in comparison to control. ", "Analgesic activity was studied in rats using hot plate and tail-flick models. ", "Codeine 5 mg/kg and vehicle served as standard and control respectively. ", "The two doses of plant extract exhibited significant analgesic activity in tail flick model (P<0.001) and hot plate model (P<0.001) in comparison to control. ", "In conclusion K. galanga possesses antiinflammatory and analgesic activities. "] :: [String]
21
22 it "\"Of\" seperates two ngrams" $ do
23 t1 <- pm (selectNgrams EN) <$> extractNgrams EN (textTest !! 0)
24 t1 `shouldBe` [[("Alcoholic extract","NN","O"),("Kaempferia galanga","NN","O"),("analgesic activities","NN+CC","O"),("antiinflammatory activities","NN+CC","O"),("animal models","NN","O")]]
25
26 it "Tests the conjunction of coordination in two ngrams with its adjectives" $ do
27 t2 <- pm (selectNgrams EN) <$> extractNgrams EN (textTest !! 2)
28 t2 `shouldBe` [[("Acute activities","NN+CC","O"),("sub acute inflammatory activities","NN+CC","O"),("rats","NNS","O"),("carrageenan","NN","O"),("paw edema","NN","O"),("cotton pellet","NN","O"),("granuloma models","NN","O")]]
29
30
31 ngramsExtractionTest FR = hspec $ do
32 describe "Behavioral tests: ngrams extraction in French Language" $ do
33
34 it "Groupe : adjectif et nom commun" $ do
35 let textFr = "Le beau texte fut écrit."
36 testFr <- pm (selectNgrams FR) <$> (extractNgrams FR) textFr
37 testFr `shouldBe` [[("beau texte","NC","O")]]
38
39 it "Groupe : adjectifs et nom commun" $ do
40 let textFr = "Le beau petit texte fut écrit."
41 testFr <- pm (selectNgrams FR) <$> (extractNgrams FR) textFr
42 testFr `shouldBe` [[("beau petit texte","NC","O")]]
43 -- `shouldBe` [[("beau texte","NC","O"),("petit texte","NC","O")]] ?
44
45 it "Groupe : nom commun et adjectif" $ do
46 let textFr = "Le livre blanc fut écrit."
47 testFr <- pm (selectNgrams FR) <$> (extractNgrams FR) textFr
48 testFr `shouldBe` [[("livre blanc","NC","O")]]
49
50 it "Groupe : nom commun et adjectifs avec conjonction" $ do
51 let textFr = "Le livre blanc et rouge."
52 testFr <- pm (selectNgrams FR) <$> (extractNgrams FR) textFr
53 testFr `shouldBe` [[("livre blanc","N","O"),("livre rouge","N","O")]]
54 -- `shouldBe` [[("livre blanc et rouge","N","O")]] ?
55
56 it "Groupe: Nom commun + préposition + Nom commun" $ do
57 let textFr0 = "Le problème du jour est résolu."
58 testFr0 <- pm (selectNgrams FR) <$> (extractNgrams FR) textFr0
59 testFr0 `shouldBe` [[("problème du jour","NC","O")]]
60
61 it "Groupe: Nom commun + préposition + Nom commun + prép + Nom commun" $ do
62 let textFr1 = "L'heure d'arrivée des coureurs dépend de la météo du jour."
63 testFr1 <- pm (selectNgrams FR) <$> (extractNgrams FR) textFr1
64 testFr1 `shouldBe` [[("heure d' arrivée des coureurs","NC","I-ORG"),("météo du jour","NC","O")]]
65
66
67 parsersTest = hspec $ do
68 describe "Parser for occurrences" $ do
69
70 let txt = "internet"
71
72 it "returns the result of one parsing" $ do
73 parseOccurrences "internet" "internet" `shouldBe` Right 1
74
75 -- | Context of Text should be toLower
76 it "returns the result of one parsing not case sensitive" $ do
77 let txtCase = "Internet"
78 parseOccurrences txtCase "internet" `shouldBe` Right 1
79
80 it "returns the result of one parsing after space" $ do
81 parseOccurrences txt " internet"
82 `shouldBe` Right 1
83
84 it "returns the result of one parsing after chars" $ do
85 parseOccurrences txt "l'internet"
86 `shouldBe` Right 1
87
88 it "returns the result of multiple parsing" $ do
89 parseOccurrences txt "internet internet of things"
90 `shouldBe` Right 2
91
92 it "returns the result of multiple parsing separated by text" $ do
93 parseOccurrences txt "internet in the internet of things"
94 `shouldBe` Right 2
95
96 it "returns the result of multiple parsing separated by punctuation" $ do
97 parseOccurrences txt "internet. In the internet of things, internet like; internet?"
98 `shouldBe` Right 4
99
100 -- describe "Parser for nodes" $ do
101 -- it "returns the result of one parsing after space" $ do
102 -- occOfCorpus 249509 "sciences" `shouldReturn` 7
103
104 main :: IO ()
105 main = do
106 -- parsersTest
107 -- ngramsExtractionTest EN
108 ngramsExtractionTest FR
109