Commit 0f2abe5f authored by Alexandre Delanoë's avatar Alexandre Delanoë

[Ngrams/Graph] inserted into lists.

parent 26fe8014
...@@ -33,7 +33,9 @@ import Gargantext.Core.Types.Main ...@@ -33,7 +33,9 @@ import Gargantext.Core.Types.Main
import Gargantext.Core (Lang(..)) import Gargantext.Core (Lang(..))
import Gargantext.Database.Config (userMaster, userArbitrary, corpusMasterName) import Gargantext.Database.Config (userMaster, userArbitrary, corpusMasterName)
import Gargantext.Database.Flow.Utils (insertToNodeNgrams) import Gargantext.Database.Flow.Utils (insertToNodeNgrams)
import Gargantext.Database.Metrics.TFICF (getTficf)
import Gargantext.Text.Terms (extractTerms) import Gargantext.Text.Terms (extractTerms)
import Gargantext.Text.Metrics.TFICF (Tficf(..))
import Gargantext.Database.Node.Document.Add (add) import Gargantext.Database.Node.Document.Add (add)
import Gargantext.Database.Node.Document.Insert (insertDocuments, ReturnId(..), addUniqIdsDoc, addUniqIdsContact, ToDbData(..)) import Gargantext.Database.Node.Document.Insert (insertDocuments, ReturnId(..), addUniqIdsDoc, addUniqIdsContact, ToDbData(..))
import Gargantext.Database.Root (getRoot) import Gargantext.Database.Root (getRoot)
...@@ -103,7 +105,7 @@ flowCorpus' :: HasNodeError err ...@@ -103,7 +105,7 @@ flowCorpus' :: HasNodeError err
flowCorpus' NodeCorpus hyperdataDocuments (ids,masterUserId,masterCorpusId, userId,userCorpusId) = do flowCorpus' NodeCorpus hyperdataDocuments (ids,masterUserId,masterCorpusId, userId,userCorpusId) = do
-------------------------------------------------- --------------------------------------------------
-- List Ngrams Flow -- List Ngrams Flow
userListId <- flowListUser userId userCorpusId userListId <- flowListUser userId userCorpusId 300
printDebug "Working on User ListId : " userListId printDebug "Working on User ListId : " userListId
let documentsWithId = mergeData (toInserted ids) (toInsert hyperdataDocuments) let documentsWithId = mergeData (toInserted ids) (toInsert hyperdataDocuments)
...@@ -280,11 +282,15 @@ flowList uId cId ngs = do ...@@ -280,11 +282,15 @@ flowList uId cId ngs = do
pure lId pure lId
flowListUser :: HasNodeError err => UserId -> CorpusId -> Cmd err NodeId flowListUser :: HasNodeError err => UserId -> CorpusId -> Int -> Cmd err NodeId
flowListUser uId cId = do flowListUser uId cId n = do
lid <- getOrMkList cId uId lId <- getOrMkList cId uId
-- is <- insertLists lId $ ngrams2list ngs -- is <- insertLists lId $ ngrams2list ngs
pure lid
ngs <- take n <$> sortWith tficf_score <$> getTficf userMaster cId lId NgramsTerms
_ <- insertNodeNgrams [ NodeNgram lId (tficf_ngramsId ng) Nothing (ngramsTypeId NgramsTerms) (fromIntegral $ listTypeId GraphList) 1 | ng <- ngs]
pure lId
------------------------------------------------------------------------ ------------------------------------------------------------------------
...@@ -323,10 +329,3 @@ insertLists lId lngs = insertNodeNgrams [ NodeNgram lId (_ngramsId ng) Nothing ( ...@@ -323,10 +329,3 @@ insertLists lId lngs = insertNodeNgrams [ NodeNgram lId (_ngramsId ng) Nothing (
] ]
------------------------------------------------------------------------ ------------------------------------------------------------------------
...@@ -26,7 +26,7 @@ data TficfContext n m = TficfLanguage n m | TficfCorpus n m | TficfDocument n m ...@@ -26,7 +26,7 @@ data TficfContext n m = TficfLanguage n m | TficfCorpus n m | TficfDocument n m
data Tficf = Tficf { tficf_ngramsId :: NgramsId data Tficf = Tficf { tficf_ngramsId :: NgramsId
, tficf_ngramsTerms :: NgramsTerms , tficf_ngramsTerms :: NgramsTerms
, tficf_score :: Double , tficf_score :: Double
} } deriving (Show)
type SupraContext = TficfContext type SupraContext = TficfContext
...@@ -41,7 +41,7 @@ tficf _ _ = panic "Not in definition" ...@@ -41,7 +41,7 @@ tficf _ _ = panic "Not in definition"
tficf' :: Double -> Double -> Double -> Double -> Double tficf' :: Double -> Double -> Double -> Double -> Double
tficf' c c' l l' tficf' c c' l l'
| c <= c' && l < l' = (c/c') / log (l/l') | c <= c' && l < l' = (l/l') / log (c/c')
| otherwise = panic "Frequency impossible" | otherwise = panic "Frequency impossible"
......
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