Commit 97d5140c authored by Alexandre Delanoë's avatar Alexandre Delanoë

[FLOW][DB][NGRAMS][Lists] Done, need to be tested with real data.

parent a4fb6705
......@@ -78,7 +78,12 @@ corpusTree nId t = TreeN (NodeTree ("Corpus " <> t) NodeCorpus nId) ( [ leafT
--data Classification = Favorites | MyClassifcation
data Lists = StopList | MainList | MapList | GroupList
data ListType = Stop | Candidate | Map
listId :: ListType -> Int
listId Stop = 0
listId Candidate = 1
listId Map = 2
-- data Metrics = Occurrences | Cooccurrences | Specclusion | Genclusion | Cvalue
-- | TfidfCorpus | TfidfGlobal | TirankLocal | TirankGlobal
......
......@@ -28,10 +28,10 @@ import System.FilePath (FilePath)
import Data.Maybe (Maybe(..))
import Data.Text (Text)
import Data.Map (Map)
import Data.Tuple.Extra (both)
import Data.Tuple.Extra (both, second)
import qualified Data.Map as DM
import Gargantext.Core.Types (NodePoly(..))
import Gargantext.Core.Types (NodePoly(..), ListType(..), listId)
import Gargantext.Prelude
import Gargantext.Database.Bashql (runCmd', del)
import Gargantext.Database.Types.Node (HyperdataDocument(..))
......@@ -147,7 +147,7 @@ indexNgrams ng2nId = do
insertToNodeNgrams :: Map (NgramsT NgramsIndexed) (Map NodeId Int) -> Cmd Int
insertToNodeNgrams m = insertNodeNgrams $ [ NodeNgram Nothing nId ((_ngramsId . _ngramsT ) ng)
insertToNodeNgrams m = insertNodeNgrams [ NodeNgram Nothing nId ((_ngramsId . _ngramsT ) ng)
(fromIntegral n) ((ngramsTypeId . _ngramsType) ng)
| (ng, nId2int) <- DM.toList m
......@@ -155,7 +155,9 @@ insertToNodeNgrams m = insertNodeNgrams $ [ NodeNgram Nothing nId ((_ngramsId
]
------------------------------------------------------------------------
groupNgramsBy :: (Ngrams -> Ngrams -> Bool) -> Map (NgramsT NgramsIndexed) (Map NodeId Int) -> Map NgramsIndexed NgramsIndexed
groupNgramsBy :: (Ngrams -> Ngrams -> Bool)
-> Map (NgramsT NgramsIndexed) (Map NodeId Int)
-> Map NgramsIndexed NgramsIndexed
groupNgramsBy = undefined
insertGroups :: ListId -> Map NgramsIndexed NgramsIndexed -> Cmd Int
......@@ -164,23 +166,29 @@ insertGroups lId ngrs =
| (ng1, ng2) <- map (both _ngramsId) $ DM.toList ngrs
]
------------------------------------------------------------------------
ngrams2list :: Map (NgramsT NgramsIndexed) (Map NodeId Int) -> Map ListType NgramsIndexed
ngrams2list = undefined
-- | TODO: weight of the list could be a probability
insertLists :: ListId -> Map ListType NgramsIndexed -> Cmd Int
insertLists lId list2ngrams =
insertNodeNgrams [ NodeNgram Nothing lId ngr (fromIntegral $ listId l) (listId l)
| (l,ngr) <- map (second _ngramsId) $ DM.toList list2ngrams
]
listFlow :: UserId -> CorpusId -> Map (NgramsT NgramsIndexed) (Map NodeId Int) -> Cmd ListId
listFlow uId cId ng = do
lId <- maybe (panic "mkList error") identity <$> head <$> mkList cId uId
-- TODO add stemming equivalence of 2 ngrams
let groupEd = groupNgramsBy (==) ng
_ <- insertGroups lId groupEd
-- compute Candidate / Map
-- ALTER TABLE nodes_nodes_ngrams ADD COLUMN typelist int;
-- insertLists = NodeNodeNgram
let lists = ngrams2list ng
_ <- insertLists lId lists
pure lId
-- | TODO ask on meeting
-- get data of NgramsTable
-- post :: update NodeNodeNgrams
-- group ngrams
------------------------------------------------------------------------
{-|
Module : Gargantext.Database.NodeNgram
Description :
Description : NodeNgram for Ngram indexation or Lists
Copyright : (c) CNRS, 2017-Present
License : AGPL + CECILL v3
Maintainer : team@gargantext.org
Stability : experimental
Portability : POSIX
Here is a longer description of this module, containing some
commentary with @some markup@.
NodeNgram: relation between a Node and a Ngrams
if Node is a Document then it is indexing
if Node is a List then it is listing (either Stop, Candidate or Map)
-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
......@@ -29,6 +32,7 @@ import Control.Lens.TH (makeLensesWith, abbreviatedFields)
import Gargantext.Database.Node (mkCmd, Cmd(..))
import Opaleye
-- | TODO : remove id
data NodeNgramPoly id node_id ngram_id weight ngrams_type
= NodeNgram { nodeNgram_NodeNgramId :: id
, nodeNgram_NodeNgramNodeId :: node_id
......
{-|
Module : Gargantext.Database.NodeNodeNgram
Description :
Description : TODO: remove this module and table in database
Copyright : (c) CNRS, 2017-Present
License : AGPL + CECILL v3
Maintainer : team@gargantext.org
Stability : experimental
Portability : POSIX
Here is a longer description of this module, containing some
commentary with @some markup@.
-}
{-# LANGUAGE NoImplicitPrelude #-}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment