1 {-# LANGUAGE OverloadedStrings #-}
3 module Data.Gargantext.Ngrams.Lang.Fr (selectNgrams, groupNgrams, textTest)
6 import Data.Gargantext.Prelude
7 import Data.Text (Text)
8 import Data.Monoid ((<>))
10 selectNgrams :: [(Text, Text, Text)] -> [(Text, Text, Text)]
11 selectNgrams xs = pf selectNgrams' xs
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
22 groupNgrams :: [(Text, Text, Text)] -> [(Text, Text, Text)]
25 -- "Groupe : nom commun et adjectifs avec conjonction"
26 groupNgrams ((n,"NC",n'):(j1,"ADJ",_):(_,"CC",_):(j2,"ADJ",_):xs) = groupNgrams (n1:n2:xs)
28 n1 = (n <> " " <> j1, "NC", n')
29 n2 = (n <> " " <> j2, "NC", n')
31 -- /!\ sometimes N instead of NC (why?)
32 groupNgrams ((n,"N",n'):(j1,"ADJ",_):(_,"CC",_):(j2,"ADJ",_):xs) = groupNgrams (n1:n2:xs)
34 n1 = (n <> " " <> j1, "N", n')
35 n2 = (n <> " " <> j2, "N", n')
37 -- Groupe : Adjectif + Conjonction de coordination + Adjectif
38 -- groupNgrams ((j1,"ADJ",_):(_,"CC",_):(j2,"ADJ",j2'):xs) = groupNgrams ((j1 <> " " <> j2, "ADJ", j2'):xs)
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)
43 -- Groupe : Plusieurs adjectifs successifs
44 groupNgrams ((x,"ADJ",_):(y,"ADJ",yy):xs) = groupNgrams ((x <> " " <> y, "ADJ", yy):xs)
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)
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)
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)
61 -- Si aucune des règles précédentes n'est remplie
62 groupNgrams (x:xs) = (x:(groupNgrams xs))
66 textTest = [ "L'heure d'arrivée des coureurs dépend de la météo du jour."]