]> Git — Sourcephile - gargantext.git/blob - src/Data/Gargantext/Ngrams/Lang/Fr.hs
[FIX] NLP Ngrams parser works for French _and_ English.
[gargantext.git] / src / Data / Gargantext / Ngrams / Lang / Fr.hs
1 {-# LANGUAGE OverloadedStrings #-}
2
3 module Data.Gargantext.Ngrams.Lang.Fr (selectNgrams, groupNgrams, textTest)
4 where
5
6 import Data.Gargantext.Prelude
7 import Data.Text (Text)
8 import Data.Monoid ((<>))
9
10 selectNgrams :: [(Text, Text, Text)] -> [(Text, Text, Text)]
11 selectNgrams xs = pf selectNgrams' xs
12 where
13 selectNgrams' (_,"N" ,_ ) = True
14 selectNgrams' (_,"NC" ,_ ) = 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 -- "Groupe : nom commun et adjectifs avec conjonction"
26 groupNgrams ((n,"NC",n'):(j1,"ADJ",_):(_,"CC",_):(j2,"ADJ",_):xs) = groupNgrams (n1:n2:xs)
27 where
28 n1 = (n <> " " <> j1, "NC", n')
29 n2 = (n <> " " <> j2, "NC", n')
30
31 -- /!\ sometimes N instead of NC (why?)
32 groupNgrams ((n,"N",n'):(j1,"ADJ",_):(_,"CC",_):(j2,"ADJ",_):xs) = groupNgrams (n1:n2:xs)
33 where
34 n1 = (n <> " " <> j1, "N", n')
35 n2 = (n <> " " <> j2, "N", n')
36
37 -- Groupe : Adjectif + Conjonction de coordination + Adjectif
38 -- groupNgrams ((j1,"ADJ",_):(_,"CC",_):(j2,"ADJ",j2'):xs) = groupNgrams ((j1 <> " " <> j2, "ADJ", j2'):xs)
39
40 -- Groupe : Nom commun + préposition + Nom commun
41 groupNgrams ((n1,"NC",_):(p,"P",_):(n2,"NC",n2'):xs) = groupNgrams ((n1 <> " " <> p <> " " <> n2, "NC", n2'):xs)
42
43 -- Groupe : Plusieurs adjectifs successifs
44 groupNgrams ((x,"ADJ",_):(y,"ADJ",yy):xs) = groupNgrams ((x <> " " <> y, "ADJ", yy):xs)
45
46 -- Groupe : nom commun et adjectif
47 groupNgrams ((x,"NC",_):(y,"ADJ",yy):xs) = groupNgrams ((x <> " " <> y, "NC", yy):xs)
48 -- /!\ sometimes N instead of NC (why?)
49 groupNgrams ((x,"N",_):(y,"ADJ",yy):xs) = groupNgrams ((x <> " " <> y, "NC", yy):xs)
50
51 -- Groupe : adjectif et nom commun
52 groupNgrams ((x,"ADJ",_):(y,"NC",yy):xs) = groupNgrams ((x <> " " <> y, "NC", yy):xs)
53 -- /!\ sometimes N instead of NC (why?)
54 groupNgrams ((x,"ADJ",_):(y,"N",yy):xs) = groupNgrams ((x <> " " <> y, "NC", yy):xs)
55
56
57 groupNgrams ((x,_,"PERSON"):(y,yy,"PERSON"):xs) = groupNgrams ((x <> " " <> y,yy,"PERSON"):xs)
58 groupNgrams ((x,_,"ORGANIZATION"):(y,yy,"ORGANIZATION"):xs) = groupNgrams ((x <> " " <> y,yy,"ORGANIZATION"):xs)
59
60
61 -- Si aucune des règles précédentes n'est remplie
62 groupNgrams (x:xs) = (x:(groupNgrams xs))
63
64
65 textTest :: [String]
66 textTest = [ "L'heure d'arrivée des coureurs dépend de la météo du jour."]
67