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 ...@@ -78,7 +78,12 @@ corpusTree nId t = TreeN (NodeTree ("Corpus " <> t) NodeCorpus nId) ( [ leafT
--data Classification = Favorites | MyClassifcation --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 -- data Metrics = Occurrences | Cooccurrences | Specclusion | Genclusion | Cvalue
-- | TfidfCorpus | TfidfGlobal | TirankLocal | TirankGlobal -- | TfidfCorpus | TfidfGlobal | TirankLocal | TirankGlobal
......
...@@ -28,10 +28,10 @@ import System.FilePath (FilePath) ...@@ -28,10 +28,10 @@ import System.FilePath (FilePath)
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.Text (Text) import Data.Text (Text)
import Data.Map (Map) import Data.Map (Map)
import Data.Tuple.Extra (both) import Data.Tuple.Extra (both, second)
import qualified Data.Map as DM import qualified Data.Map as DM
import Gargantext.Core.Types (NodePoly(..)) import Gargantext.Core.Types (NodePoly(..), ListType(..), listId)
import Gargantext.Prelude import Gargantext.Prelude
import Gargantext.Database.Bashql (runCmd', del) import Gargantext.Database.Bashql (runCmd', del)
import Gargantext.Database.Types.Node (HyperdataDocument(..)) import Gargantext.Database.Types.Node (HyperdataDocument(..))
...@@ -147,40 +147,48 @@ indexNgrams ng2nId = do ...@@ -147,40 +147,48 @@ indexNgrams ng2nId = do
insertToNodeNgrams :: Map (NgramsT NgramsIndexed) (Map NodeId Int) -> Cmd Int 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) (fromIntegral n) ((ngramsTypeId . _ngramsType) ng)
| (ng, nId2int) <- DM.toList m | (ng, nId2int) <- DM.toList m
, (nId, n) <- DM.toList nId2int , (nId, n) <- DM.toList nId2int
] ]
------------------------------------------------------------------------ ------------------------------------------------------------------------
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 groupNgramsBy = undefined
insertGroups :: ListId -> Map NgramsIndexed NgramsIndexed -> Cmd Int insertGroups :: ListId -> Map NgramsIndexed NgramsIndexed -> Cmd Int
insertGroups lId ngrs = insertGroups lId ngrs =
insertNodeNgramNgram $ [ NodeNgramNgram lId ng1 ng2 (Just 1) insertNodeNgramNgram $ [ NodeNgramNgram lId ng1 ng2 (Just 1)
| (ng1, ng2) <- map (both _ngramsId) $ DM.toList 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 :: UserId -> CorpusId -> Map (NgramsT NgramsIndexed) (Map NodeId Int) -> Cmd ListId
listFlow uId cId ng = do listFlow uId cId ng = do
lId <- maybe (panic "mkList error") identity <$> head <$> mkList cId uId lId <- maybe (panic "mkList error") identity <$> head <$> mkList cId uId
-- TODO add stemming equivalence of 2 ngrams -- TODO add stemming equivalence of 2 ngrams
let groupEd = groupNgramsBy (==) ng let groupEd = groupNgramsBy (==) ng
_ <- insertGroups lId groupEd _ <- insertGroups lId groupEd
-- compute Candidate / Map -- compute Candidate / Map
-- ALTER TABLE nodes_nodes_ngrams ADD COLUMN typelist int; let lists = ngrams2list ng
-- insertLists = NodeNodeNgram _ <- insertLists lId lists
pure lId pure lId
------------------------------------------------------------------------
-- | TODO ask on meeting
-- get data of NgramsTable
-- post :: update NodeNodeNgrams
-- group ngrams
{-| {-|
Module : Gargantext.Database.NodeNgram Module : Gargantext.Database.NodeNgram
Description : Description : NodeNgram for Ngram indexation or Lists
Copyright : (c) CNRS, 2017-Present Copyright : (c) CNRS, 2017-Present
License : AGPL + CECILL v3 License : AGPL + CECILL v3
Maintainer : team@gargantext.org Maintainer : team@gargantext.org
Stability : experimental Stability : experimental
Portability : POSIX Portability : POSIX
Here is a longer description of this module, containing some NodeNgram: relation between a Node and a Ngrams
commentary with @some markup@.
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 #-} {-# OPTIONS_GHC -fno-warn-orphans #-}
...@@ -29,6 +32,7 @@ import Control.Lens.TH (makeLensesWith, abbreviatedFields) ...@@ -29,6 +32,7 @@ import Control.Lens.TH (makeLensesWith, abbreviatedFields)
import Gargantext.Database.Node (mkCmd, Cmd(..)) import Gargantext.Database.Node (mkCmd, Cmd(..))
import Opaleye import Opaleye
-- | TODO : remove id
data NodeNgramPoly id node_id ngram_id weight ngrams_type data NodeNgramPoly id node_id ngram_id weight ngrams_type
= NodeNgram { nodeNgram_NodeNgramId :: id = NodeNgram { nodeNgram_NodeNgramId :: id
, nodeNgram_NodeNgramNodeId :: node_id , nodeNgram_NodeNgramNodeId :: node_id
......
{-| {-|
Module : Gargantext.Database.NodeNodeNgram Module : Gargantext.Database.NodeNodeNgram
Description : Description : TODO: remove this module and table in database
Copyright : (c) CNRS, 2017-Present Copyright : (c) CNRS, 2017-Present
License : AGPL + CECILL v3 License : AGPL + CECILL v3
Maintainer : team@gargantext.org Maintainer : team@gargantext.org
Stability : experimental Stability : experimental
Portability : POSIX Portability : POSIX
Here is a longer description of this module, containing some
commentary with @some markup@.
-} -}
{-# LANGUAGE NoImplicitPrelude #-} {-# 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