{-|
Module      : Gargantext.Core.Text.Terms.Multi.RAKE
Description : Rapid automatic keyword extraction (RAKE)
Copyright   : (c) CNRS, 2017
License     : AGPL + CECILL v3
Maintainer  : team@gargantext.org
Stability   : experimental
Portability : POSIX

Personal notes for the integration of RAKE in Gargantext.

RAKE algorithm is a simple, rapid and effective algorithm to extract
keywords that is very sensitive to the quality of the stop word list.

Indeed, the very first step starts from the stop words list to cut the
text towards keywords extraction. The conTexT is the sentence level to
compute the coccurrences and occurrences which are divided to compute
the metric of one word. Multi-words metrics is equal to the sum of the
metrics of each word.

Finally The metrics highlight longer keywords which highly depends of
quality of the cut which depends on the quality of the stop word list.

As a consequence, to improve the effectiveness of RAKE algorithm, I am
wondering if some bayesian features could be added to increase stop word
list quality in time.

-}


module Gargantext.Core.Text.Terms.Multi.RAKE (multiterms_rake, select, hardStopList)
  where

import Data.Text (Text)
import NLP.RAKE.Text

import Gargantext.Core.Text.Samples.EN (stopList)
import Gargantext.Prelude

select :: Double -> [a] -> [a]
select :: Double -> [a] -> [a]
select Double
part [a]
ns = Int -> [a] -> [a]
forall a. Int -> [a] -> [a]
take Int
n [a]
ns
  where
    n :: Int
n = Double -> Int
forall a b. (RealFrac a, Integral b) => a -> b
round (Double -> Int) -> Double -> Int
forall a b. (a -> b) -> a -> b
$ Double
part Double -> Double -> Double
forall a. Num a => a -> a -> a
* (Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Double) -> Int -> Double
forall a b. (a -> b) -> a -> b
$ [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [a]
ns)


multiterms_rake :: Text -> [WordScore]
multiterms_rake :: Text -> [WordScore]
multiterms_rake = StopwordsMap -> NoSplit -> NoList -> NoList -> [WordScore]
candidates StopwordsMap
hardStopList
                        NoSplit
defaultNosplit
                        NoList
defaultNolist   (NoList -> [WordScore]) -> (Text -> NoList) -> Text -> [WordScore]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> NoList
pSplitter

-- | StopList
hardStopList :: StopwordsMap
hardStopList :: StopwordsMap
hardStopList =  [NoSplit] -> StopwordsMap
mkStopwordsStr [NoSplit]
stopList