]> Git — Sourcephile - gargantext.git/blob - src/Data/Gargantext/Ngrams/Lang/En.hs
app/Main & connectGargandb
[gargantext.git] / src / Data / Gargantext / Ngrams / Lang / En.hs
1 {-# LANGUAGE OverloadedStrings #-}
2
3 module Data.Gargantext.Ngrams.Lang.En (selectNgrams, groupNgrams, textTest) where
4
5 import Data.Gargantext.Prelude
6 import Data.Text (Text)
7 import Data.Monoid ((<>))
8
9 selectNgrams :: [(Text, Text, Text)] -> [(Text, Text, Text)]
10 selectNgrams xs = pf selectNgrams' xs
11 where
12 selectNgrams' (_,"NN" ,_ ) = True
13 selectNgrams' (_,"NNS" ,_ ) = True
14 selectNgrams' (_,"NNP" ,_ ) = True
15 selectNgrams' (_,"NN+CC",_ ) = True
16 selectNgrams' (_,_ ,"PERSON" ) = True
17 selectNgrams' (_,_ ,"ORGANIZATION") = True
18 selectNgrams' (_,_ ,"LOCATION" ) = True
19 selectNgrams' (_,_ ,_ ) = False
20
21
22 groupNgrams :: [(Text, Text, Text)] -> [(Text, Text, Text)]
23 groupNgrams [] = []
24
25 groupNgrams ((j1,"JJ",j1'):(c1,"CC",c1'):(j2,"JJ",j2'):(j3,"JJ",_):xs) = groupNgrams (jn1:cc:jn2:xs)
26 where
27 jn j' j'' jn' = (j' <> " " <> j'', "JJ", jn')
28 cc = (c1,"CC",c1')
29 jn1 = (j1, "JJ", j1')
30 jn2 = jn j2 j3 j2'
31
32 groupNgrams ((j1,"JJ",_):(_,"CC",_):(j2,"JJ",_):(n,"NN",nn):xs) = groupNgrams (jn1:jn2:xs)
33 where
34 jn j m mm p = (j <> " " <> m, p, mm)
35 jn1 = jn j1 n nn ("NN+CC" :: Text)
36 jn2 = jn j2 n nn ("NN+CC" :: Text)
37
38 groupNgrams ((j1,"JJ",_):(_,"CC",_):(j2,"JJ",_):(n,"NNS",nn):xs) = groupNgrams (jn1:jn2:xs)
39 where
40 jn j m mm p = (j <> " " <> m, p, mm)
41 jn1 = jn j1 n nn ("NN+CC" :: Text)
42 jn2 = jn j2 n nn ("NN+CC" :: Text)
43
44 groupNgrams ((x,"JJ",_):(y,"JJ",yy):xs) = groupNgrams ((x <> " " <> y, "JJ", yy):xs)
45 groupNgrams ((x,"JJ",_):(y,"NN",yy):xs) = groupNgrams ((x <> " " <> y, "NN", yy):xs)
46 groupNgrams ((x,"JJ",_):(y,"NNS",yy):xs) = groupNgrams ((x <> " " <> y, "NN", yy):xs)
47
48 groupNgrams ((x,"NNP",_):(y,"NN",yy):xs) = groupNgrams ((x <> " " <> y, "NN", yy):xs)
49 groupNgrams ((x,"NN",_):(y,"NP",yy):xs) = groupNgrams ((x <> " " <> y, "NN", yy):xs)
50
51 groupNgrams ((x,"NN",_):(y,"NNS",yy):xs) = groupNgrams ((x <> " " <> y, "NN", yy):xs)
52 groupNgrams ((x,"NP",_):(y,"NP",yy):xs) = groupNgrams ((x <> " " <> y, "NN", yy):xs)
53
54 groupNgrams ((x,"NN",_):(y,"NN",yy):xs) = groupNgrams ((x <> " " <> y, "NN", yy):xs)
55
56
57 -- extractNgrams "Test the antiinflammatory or analgesic activity?"
58 -- [[("``","``","O"),("Test","VB","O"),("the","DT","O"),("antiinflammatory activity analgesic activity","NN","O"),("?",".","O"),("''","''","O")]]
59 -- > should be (antiinflammatory activity) <> (analgesic activity)
60
61 groupNgrams ((x,"NN",_):(o,"IN",_):(y,"NN",yy):xs) = groupNgrams ((x <> " " <> o <> " " <> y, "NN", yy):xs)
62 groupNgrams ((x,"NN",_):(o,"IN",_):(y,"NNP",yy):xs) = groupNgrams ((x <> " " <> o <> " " <> y, "NN", yy):xs)
63
64 groupNgrams ((x,"NN",_):(o,"IN",_):(det,"DT",_):(y,"NN",yy):xs) = groupNgrams ((x <> " " <> o <> " " <> det <> " " <> y, "NN", yy):xs)
65 groupNgrams ((x,"NN",_):(o,"IN",_):(det,"DT",_):(y,"NNP",yy):xs) = groupNgrams ((x <> " " <> o <> " " <> det <> " " <> y, "NN", yy):xs)
66
67 groupNgrams ((x,_,"PERSON"):(y,yy,"PERSON"):xs) = groupNgrams ((x <> " " <> y,yy,"PERSON"):xs)
68 groupNgrams ((x,_,"ORGANIZATION"):(y,yy,"ORGANIZATION"):xs) = groupNgrams ((x <> " " <> y,yy,"ORGANIZATION"):xs)
69 groupNgrams ((x,_,"LOCATION"):(y,yy,"LOCATION"):xs) = groupNgrams ((x <> " " <> y,yy,"LOCATION"):xs)
70
71 groupNgrams (x:xs) = (x:(groupNgrams xs))
72
73
74 textTest :: [String]
75 textTest = [ "Alcoholic extract of Kaempferia galanga was tested for analgesic and antiinflammatory activities in animal models. "
76 , "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. "
77 , " Acute and sub acute inflammatory activities were studied in rats by carrageenan induced paw edema and cotton pellet induced granuloma models respectively. "
78 , "In both models, the standard drug used was aspirin 100 mg/kg. "
79 , "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. "
80 , "Analgesic activity was studied in rats using hot plate and tail-flick models. "
81 , "Codeine 5 mg/kg and vehicle served as standard and control respectively. "
82 , "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. "
83 , "In conclusion K. galanga possesses antiinflammatory and analgesic activities. "]
84
85