2 Module : Gargantext.Database.Metrics.TFICF
3 Description : Ngrams by Node user and master
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
12 {-# LANGUAGE QuasiQuotes #-}
14 module Gargantext.Database.Action.Metrics.TFICF
17 -- import Debug.Trace (trace)
18 -- import Gargantext.Core (Lang(..))
19 import Data.HashMap.Strict (HashMap)
20 import qualified Data.HashMap.Strict as HM
21 import Data.Maybe (fromMaybe)
22 import Gargantext.Core.Text.Metrics.TFICF
23 import Gargantext.Database.Action.Metrics.NgramsByNode (getNodesByNgramsUser, getOccByNgramsOnlyFast)
24 import Gargantext.Database.Admin.Types.Node -- (ListId, CorpusId, NodeId)
25 import Gargantext.Database.Prelude (Cmd)
26 import Gargantext.Database.Query.Table.NodeNode (selectCountDocs)
27 import Gargantext.Database.Schema.Ngrams (NgramsType(..))
28 import Gargantext.API.Ngrams.Types
29 import Gargantext.Prelude
30 import qualified Data.Set as Set
32 getTficf :: UserCorpusId
35 -> Cmd err (HashMap NgramsTerm Double)
36 getTficf cId mId nt = do
37 mapTextDoubleLocal <- HM.filter (> 1)
38 <$> HM.map (fromIntegral . Set.size)
39 <$> getNodesByNgramsUser cId nt
41 mapTextDoubleGlobal <- HM.map fromIntegral
42 <$> getOccByNgramsOnlyFast mId nt (HM.keys mapTextDoubleLocal)
44 countLocal <- selectCountDocs cId
45 countGlobal <- selectCountDocs mId
47 pure $ HM.mapWithKey (\t n ->
48 tficf (TficfInfra (Count n )
49 (Total $ fromIntegral countLocal))
50 (TficfSupra (Count $ fromMaybe 0 $ HM.lookup t mapTextDoubleGlobal)
51 (Total $ fromIntegral countGlobal))