Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
195
Issues
195
List
Board
Labels
Milestones
Merge Requests
12
Merge Requests
12
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
haskell-gargantext
Commits
aaf4b338
Commit
aaf4b338
authored
Jan 07, 2021
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[REFACT/CLEAN] TextFlow
parent
39826d6a
Pipeline
#1331
canceled with stage
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
43 additions
and
70 deletions
+43
-70
Types.hs
src/Gargantext/Core/Flow/Types.hs
+6
-14
Terms.hs
src/Gargantext/Core/Text/Terms.hs
+2
-2
Flow.hs
src/Gargantext/Database/Action/Flow.hs
+10
-8
List.hs
src/Gargantext/Database/Action/Flow/List.hs
+12
-9
Utils.hs
src/Gargantext/Database/Action/Flow/Utils.hs
+2
-33
Prelude.hs
src/Gargantext/Database/Admin/Types/Hyperdata/Prelude.hs
+1
-1
Types.hs
src/Gargantext/Database/Types.hs
+10
-3
No files found.
src/Gargantext/Core/Flow/Types.hs
View file @
aaf4b338
...
@@ -14,14 +14,13 @@ Portability : POSIX
...
@@ -14,14 +14,13 @@ Portability : POSIX
module
Gargantext.Core.Flow.Types
where
module
Gargantext.Core.Flow.Types
where
import
Control.Lens
-- (Lens')
import
Control.Lens
import
Data.Map
(
Map
)
import
Data.Map
(
Map
)
import
Gargantext.Core.Text
(
HasText
(
..
))
import
Gargantext.Core.Text
(
HasText
(
..
))
import
Gargantext.Database.Admin.Types.Hyperdata
import
Gargantext.Database.Admin.Types.Hyperdata
import
Gargantext.Database.Admin.Types.Node
import
Gargantext.Database.Admin.Types.Node
import
Gargantext.Database.Schema.Node
(
node_hash_id
)
import
Gargantext.Database.Schema.Ngrams
(
Ngrams
,
NgramsType
)
import
Gargantext.Database.Schema.Ngrams
(
Ngrams
,
NgramsType
)
import
Gargantext.Database.Schema.Node
(
node_hash_id
)
import
Gargantext.Prelude
import
Gargantext.Prelude
import
Gargantext.Prelude.Crypto.Hash
(
Hash
)
import
Gargantext.Prelude.Crypto.Hash
(
Hash
)
...
@@ -41,17 +40,10 @@ instance UniqId (Node a)
...
@@ -41,17 +40,10 @@ instance UniqId (Node a)
where
where
uniqId
=
node_hash_id
uniqId
=
node_hash_id
{-
data DocumentIdWithNgrams a = DocumentIdWithNgrams
data DocumentIdWithNgrams a = DocumentIdWithNgrams
{
documentWithId
::
!
(
DocumentWith
Id
a
)
{ documentWithId :: !(
Indexed Node
Id a)
, documentNgrams :: !(Map Ngrams (Map NgramsType Int))
, documentNgrams :: !(Map Ngrams (Map NgramsType Int))
} deriving (Show)
} deriving (Show)
-}
data
DocumentWithId
a
=
DocumentWithId
{
documentId
::
!
NodeId
,
documentData
::
!
a
}
deriving
(
Show
)
instance
HasText
a
=>
HasText
(
DocumentWithId
a
)
where
hasText
(
DocumentWithId
_
a
)
=
hasText
a
src/Gargantext/Core/Text/Terms.hs
View file @
aaf4b338
...
@@ -91,9 +91,9 @@ extractTerms termTypeLang xs = mapM (terms termTypeLang) xs
...
@@ -91,9 +91,9 @@ extractTerms termTypeLang xs = mapM (terms termTypeLang) xs
------------------------------------------------------------------------
------------------------------------------------------------------------
withLang
::
HasText
a
withLang
::
(
Foldable
t
,
Functor
t
,
HasText
h
)
=>
TermType
Lang
=>
TermType
Lang
->
[
DocumentWithId
a
]
->
t
h
->
TermType
Lang
->
TermType
Lang
withLang
(
Unsupervised
l
n
s
m
)
ns
=
Unsupervised
l
n
s
m'
withLang
(
Unsupervised
l
n
s
m
)
ns
=
Unsupervised
l
n
s
m'
where
where
...
...
src/Gargantext/Database/Action/Flow.hs
View file @
aaf4b338
...
@@ -75,7 +75,7 @@ import Gargantext.Core.Types.Main
...
@@ -75,7 +75,7 @@ import Gargantext.Core.Types.Main
import
Gargantext.Core.Utils.Prefix
(
unPrefix
,
unPrefixSwagger
)
import
Gargantext.Core.Utils.Prefix
(
unPrefix
,
unPrefixSwagger
)
import
Gargantext.Database.Action.Flow.List
import
Gargantext.Database.Action.Flow.List
import
Gargantext.Database.Action.Flow.Types
import
Gargantext.Database.Action.Flow.Types
import
Gargantext.Database.Action.Flow.Utils
(
insertDocNgrams
)
import
Gargantext.Database.Action.Flow.Utils
(
insertDocNgrams
,
DocumentIdWithNgrams
(
..
)
)
import
Gargantext.Database.Action.Search
(
searchDocInDatabase
)
import
Gargantext.Database.Action.Search
(
searchDocInDatabase
)
import
Gargantext.Database.Admin.Config
(
userMaster
,
corpusMasterName
)
import
Gargantext.Database.Admin.Config
(
userMaster
,
corpusMasterName
)
import
Gargantext.Database.Admin.Types.Hyperdata
import
Gargantext.Database.Admin.Types.Hyperdata
...
@@ -89,6 +89,7 @@ import Gargantext.Database.Query.Table.NodeNgrams (listInsertDb , getCgramsId)
...
@@ -89,6 +89,7 @@ import Gargantext.Database.Query.Table.NodeNgrams (listInsertDb , getCgramsId)
import
Gargantext.Database.Query.Table.NodeNodeNgrams2
import
Gargantext.Database.Query.Table.NodeNodeNgrams2
import
Gargantext.Database.Query.Tree.Root
(
getOrMkRoot
,
getOrMk_RootWithCorpus
)
import
Gargantext.Database.Query.Tree.Root
(
getOrMkRoot
,
getOrMk_RootWithCorpus
)
import
Gargantext.Database.Schema.Node
(
NodePoly
(
..
))
import
Gargantext.Database.Schema.Node
(
NodePoly
(
..
))
import
Gargantext.Database.Types
import
Gargantext.Prelude
import
Gargantext.Prelude
import
Gargantext.Prelude.Crypto.Hash
(
Hash
)
import
Gargantext.Prelude.Crypto.Hash
(
Hash
)
import
qualified
Gargantext.Core.Text.Corpus.API
as
API
import
qualified
Gargantext.Core.Text.Corpus.API
as
API
...
@@ -258,7 +259,8 @@ insertMasterDocs c lang hs = do
...
@@ -258,7 +259,8 @@ insertMasterDocs c lang hs = do
-- this will enable global database monitoring
-- this will enable global database monitoring
-- maps :: IO Map Ngrams (Map NgramsType (Map NodeId Int))
-- maps :: IO Map Ngrams (Map NgramsType (Map NodeId Int))
mapNgramsDocs
<-
mapNodeIdNgrams
mapNgramsDocs
::
Map
Ngrams
(
Map
NgramsType
(
Map
NodeId
Int
))
<-
mapNodeIdNgrams
<$>
documentIdWithNgrams
<$>
documentIdWithNgrams
(
extractNgramsT
$
withLang
lang
documentsWithId
)
(
extractNgramsT
$
withLang
lang
documentsWithId
)
documentsWithId
documentsWithId
...
@@ -296,7 +298,7 @@ insertDocs :: ( FlowCmdM env err m
...
@@ -296,7 +298,7 @@ insertDocs :: ( FlowCmdM env err m
=>
UserId
=>
UserId
->
CorpusId
->
CorpusId
->
[
a
]
->
[
a
]
->
m
([
DocId
],
[
DocumentWith
Id
a
])
->
m
([
DocId
],
[
Indexed
Node
Id
a
])
insertDocs
uId
cId
hs
=
do
insertDocs
uId
cId
hs
=
do
let
docs
=
map
addUniqId
hs
let
docs
=
map
addUniqId
hs
newIds
<-
insertDb
uId
cId
docs
newIds
<-
insertDb
uId
cId
docs
...
@@ -325,12 +327,12 @@ toInserted =
...
@@ -325,12 +327,12 @@ toInserted =
mergeData
::
Map
Hash
ReturnId
mergeData
::
Map
Hash
ReturnId
->
Map
Hash
a
->
Map
Hash
a
->
[
DocumentWith
Id
a
]
->
[
Indexed
Node
Id
a
]
mergeData
rs
=
catMaybes
.
map
toDocumentWithId
.
Map
.
toList
mergeData
rs
=
catMaybes
.
map
toDocumentWithId
.
Map
.
toList
where
where
toDocumentWithId
(
sha
,
hpd
)
=
toDocumentWithId
(
sha
,
hpd
)
=
DocumentWithI
d
<$>
fmap
reId
(
lookup
sha
rs
)
Indexe
d
<$>
fmap
reId
(
lookup
sha
rs
)
<*>
Just
hpd
<*>
Just
hpd
------------------------------------------------------------------------
------------------------------------------------------------------------
------------------------------------------------------------------------
------------------------------------------------------------------------
...
@@ -338,12 +340,12 @@ mergeData rs = catMaybes . map toDocumentWithId . Map.toList
...
@@ -338,12 +340,12 @@ mergeData rs = catMaybes . map toDocumentWithId . Map.toList
documentIdWithNgrams
::
HasNodeError
err
documentIdWithNgrams
::
HasNodeError
err
=>
(
a
=>
(
a
->
Cmd
err
(
Map
Ngrams
(
Map
NgramsType
Int
)))
->
Cmd
err
(
Map
Ngrams
(
Map
NgramsType
Int
)))
->
[
DocumentWith
Id
a
]
->
[
Indexed
Node
Id
a
]
->
Cmd
err
[
DocumentIdWithNgrams
a
]
->
Cmd
err
[
DocumentIdWithNgrams
a
]
documentIdWithNgrams
f
=
traverse
toDocumentIdWithNgrams
documentIdWithNgrams
f
=
traverse
toDocumentIdWithNgrams
where
where
toDocumentIdWithNgrams
d
=
do
toDocumentIdWithNgrams
d
=
do
e
<-
f
$
documentData
d
e
<-
f
$
_unIndex
d
pure
$
DocumentIdWithNgrams
d
e
pure
$
DocumentIdWithNgrams
d
e
------------------------------------------------------------------------
------------------------------------------------------------------------
...
...
src/Gargantext/Database/Action/Flow/List.hs
View file @
aaf4b338
...
@@ -20,25 +20,25 @@ module Gargantext.Database.Action.Flow.List
...
@@ -20,25 +20,25 @@ module Gargantext.Database.Action.Flow.List
import
Control.Concurrent
import
Control.Concurrent
import
Control.Lens
(
view
,
(
^.
),
(
+~
),
(
%~
),
at
)
import
Control.Lens
(
view
,
(
^.
),
(
+~
),
(
%~
),
at
)
import
Control.Monad.Reader
import
Control.Monad.Reader
import
qualified
Data.List
as
List
import
qualified
Data.Map
as
Map
import
Data.Map
(
Map
,
toList
)
import
Data.Map
(
Map
,
toList
)
import
qualified
Data.Map.Strict.Patch
as
PM
import
Data.Maybe
(
catMaybes
)
import
Data.Maybe
(
catMaybes
)
import
Data.Text
(
Text
)
import
Data.Text
(
Text
)
import
Gargantext.API.Ngrams.Types
(
HasRepoSaver
(
..
),
NgramsElement
(
..
),
NgramsPatch
(
..
),
NgramsRepoElement
(
..
),
NgramsTablePatch
(
..
),
NgramsTerm
(
..
),
RepoCmdM
,
ne_ngrams
,
ngramsElementToRepo
,
r_history
,
r_state
,
r_version
,
repoVar
)
import
Gargantext.API.Ngrams.Types
(
HasRepoSaver
(
..
),
NgramsElement
(
..
),
NgramsPatch
(
..
),
NgramsRepoElement
(
..
),
NgramsTablePatch
(
..
),
NgramsTerm
(
..
),
RepoCmdM
,
ne_ngrams
,
ngramsElementToRepo
,
r_history
,
r_state
,
r_version
,
repoVar
)
import
Gargantext.Core.Flow.Types
import
Gargantext.Core.Types
(
HasInvalidError
(
..
),
assertValid
)
import
Gargantext.Core.Types
(
HasInvalidError
(
..
),
assertValid
)
import
Gargantext.Core.Types.Main
(
ListType
(
CandidateTerm
))
import
Gargantext.Core.Types.Main
(
ListType
(
CandidateTerm
))
import
Gargantext.Core.Utils
(
something
)
import
Gargantext.Core.Utils
(
something
)
import
Gargantext.Database.Action.Flow.Types
import
Gargantext.Database.Action.Flow.Types
import
qualified
Gargantext.Database.Query.Table.Ngrams
as
TableNgrams
import
Gargantext.Database.Action.Flow.Utils
(
DocumentIdWithNgrams
(
..
))
import
Gargantext.Database.Admin.Types.Node
import
Gargantext.Database.Admin.Types.Node
import
Gargantext.Database.Query.Table.Node_NodeNgramsNodeNgrams
import
Gargantext.Database.Query.Table.NodeNgrams
(
NodeNgramsPoly
(
..
),
NodeNgramsW
,
listInsertDb
,
getCgramsId
)
import
Gargantext.Database.Query.Table.NodeNgrams
(
NodeNgramsPoly
(
..
),
NodeNgramsW
,
listInsertDb
,
getCgramsId
)
import
Gargantext.Database.Query.Table.Node_NodeNgramsNodeNgrams
import
Gargantext.Database.Schema.Ngrams
(
Ngrams
(
..
),
NgramsType
(
..
))
import
Gargantext.Database.Schema.Ngrams
(
Ngrams
(
..
),
NgramsType
(
..
))
import
Gargantext.Database.Types
import
Gargantext.Prelude
import
Gargantext.Prelude
import
qualified
Data.List
as
List
import
qualified
Data.Map
as
Map
import
qualified
Data.Map.Strict.Patch
as
PM
import
qualified
Gargantext.Database.Query.Table.Ngrams
as
TableNgrams
-- FLOW LIST
-- FLOW LIST
-- 1. select specific terms of the corpus when compared with others langs
-- 1. select specific terms of the corpus when compared with others langs
...
@@ -84,14 +84,17 @@ flowList_Tficf' u m nt f = do
...
@@ -84,14 +84,17 @@ flowList_Tficf' u m nt f = do
-- | TODO check optimization
-- | TODO check optimization
mapNodeIdNgrams
::
[
DocumentIdWithNgrams
a
]
mapNodeIdNgrams
::
[
DocumentIdWithNgrams
a
]
->
Map
Ngrams
(
Map
NgramsType
(
Map
NodeId
Int
))
->
Map
Ngrams
(
Map
NgramsType
(
Map
NodeId
Int
)
)
mapNodeIdNgrams
=
Map
.
unionsWith
(
Map
.
unionWith
(
Map
.
unionWith
(
+
)))
.
fmap
f
mapNodeIdNgrams
=
Map
.
unionsWith
(
Map
.
unionWith
(
Map
.
unionWith
(
+
)))
.
fmap
f
where
where
f
::
DocumentIdWithNgrams
a
f
::
DocumentIdWithNgrams
a
->
Map
Ngrams
(
Map
NgramsType
(
Map
NodeId
Int
))
->
Map
Ngrams
(
Map
NgramsType
(
Map
NodeId
Int
))
f
d
=
fmap
(
fmap
(
Map
.
singleton
nId
))
$
documentNgrams
d
f
d
=
fmap
(
fmap
(
Map
.
singleton
nId
))
$
documentNgrams
d
where
where
nId
=
documentId
$
documentWithId
d
nId
=
_index
$
documentWithId
d
------------------------------------------------------------------------
------------------------------------------------------------------------
flowList_DbRepo
::
FlowCmdM
env
err
m
flowList_DbRepo
::
FlowCmdM
env
err
m
...
...
src/Gargantext/Database/Action/Flow/Utils.hs
View file @
aaf4b338
...
@@ -14,51 +14,20 @@ module Gargantext.Database.Action.Flow.Utils
...
@@ -14,51 +14,20 @@ module Gargantext.Database.Action.Flow.Utils
where
where
import
Data.Map
(
Map
)
import
Data.Map
(
Map
)
import
Gargantext.Database.Admin.Types.Hyperdata
(
Hyperdata
)
import
Gargantext.Database.Admin.Types.Node
import
Gargantext.Database.Admin.Types.Node
import
Gargantext.Database.Prelude
(
Cmd
)
import
Gargantext.Database.Prelude
(
Cmd
)
import
Gargantext.Database.Query.Table.NodeNodeNgrams
import
Gargantext.Database.Query.Table.NodeNodeNgrams
import
Gargantext.Database.Schema.Ngrams
import
Gargantext.Database.Schema.Ngrams
import
Gargantext.Database.Schema.Node
import
Gargantext.Database.Types
import
Gargantext.Database.Types
import
Gargantext.Prelude
import
Gargantext.Prelude
import
qualified
Data.Map
as
DM
import
qualified
Data.Map
as
DM
type
DocumentWithId
a
=
Indexed
NodeId
a
toMaps
::
Hyperdata
a
=>
(
a
->
Map
(
NgramsT
Ngrams
)
Int
)
->
[
Node
a
]
->
Map
(
NgramsT
Ngrams
)
(
Map
NodeId
Int
)
toMaps
fun
ns
=
mapNodeIdNgrams
$
documentIdWithNgrams
fun
ns'
where
ns'
=
map
(
\
(
Node
nId
_
_
_
_
_
_
json
)
->
DocumentWithId
nId
json
)
ns
mapNodeIdNgrams
::
Hyperdata
a
=>
[
DocumentIdWithNgrams
a
]
->
Map
(
NgramsT
Ngrams
)
(
Map
NodeId
Int
)
mapNodeIdNgrams
ds
=
DM
.
map
(
DM
.
fromListWith
(
+
))
$
DM
.
fromListWith
(
<>
)
xs
where
xs
=
[(
ng
,
[(
nId
,
i
)])
|
(
nId
,
n2i'
)
<-
n2i
ds
,
(
ng
,
i
)
<-
DM
.
toList
n2i'
]
n2i
=
map
(
\
d
->
((
documentId
.
documentWithId
)
d
,
documentNgrams
d
))
documentIdWithNgrams
::
Hyperdata
a
=>
(
a
->
Map
(
NgramsT
Ngrams
)
Int
)
->
[
DocumentWithId
a
]
->
[
DocumentIdWithNgrams
a
]
documentIdWithNgrams
f
=
map
(
\
d
->
DocumentIdWithNgrams
d
((
f
.
documentData
)
d
))
data
DocumentWithId
a
=
DocumentWithId
{
documentId
::
NodeId
,
documentData
::
a
}
deriving
(
Show
)
data
DocumentIdWithNgrams
a
=
data
DocumentIdWithNgrams
a
=
DocumentIdWithNgrams
DocumentIdWithNgrams
{
documentWithId
::
DocumentWithId
a
{
documentWithId
::
DocumentWithId
a
,
documentNgrams
::
Map
(
NgramsT
Ngrams
)
Int
,
documentNgrams
::
Map
Ngrams
(
Map
NgramsType
Int
)
}
deriving
(
Show
)
}
deriving
(
Show
)
...
...
src/Gargantext/Database/Admin/Types/Hyperdata/Prelude.hs
View file @
aaf4b338
...
@@ -33,7 +33,7 @@ module Gargantext.Database.Admin.Types.Hyperdata.Prelude
...
@@ -33,7 +33,7 @@ module Gargantext.Database.Admin.Types.Hyperdata.Prelude
)
)
where
where
import
Control.Lens
hiding
(
elements
,
(
&
),
(
.=
))
import
Control.Lens
hiding
(
elements
,
(
&
),
(
.=
)
,
Indexed
)
import
Data.Aeson
import
Data.Aeson
import
Data.Aeson.TH
(
deriveJSON
)
import
Data.Aeson.TH
(
deriveJSON
)
import
Data.Aeson.Types
(
emptyObject
)
import
Data.Aeson.Types
(
emptyObject
)
...
...
src/Gargantext/Database/Types.hs
View file @
aaf4b338
...
@@ -14,20 +14,27 @@ Portability : POSIX
...
@@ -14,20 +14,27 @@ Portability : POSIX
module
Gargantext.Database.Types
module
Gargantext.Database.Types
where
where
import
Gargantext.
Prelude
import
Gargantext.
Core.Text
(
HasText
(
..
))
import
Gargantext.Database.Schema.Prelude
import
Gargantext.Database.Schema.Prelude
import
Gargantext.Prelude
import
qualified
Database.PostgreSQL.Simple
as
PGS
import
qualified
Database.PostgreSQL.Simple
as
PGS
-- | Index memory of any type in Gargantext
-- | Index memory of any type in Gargantext
data
Indexed
i
a
=
data
Indexed
i
a
=
Indexed
{
_index
::
i
Indexed
{
_index
::
!
i
,
_unIndex
::
a
,
_unIndex
::
!
a
}
}
deriving
(
Show
,
Generic
,
Eq
,
Ord
)
deriving
(
Show
,
Generic
,
Eq
,
Ord
)
makeLenses
''
I
ndexed
makeLenses
''
I
ndexed
----------------------------------------------------------------------
-- | Main instances
instance
(
FromField
i
,
FromField
a
)
=>
PGS
.
FromRow
(
Indexed
i
a
)
where
instance
(
FromField
i
,
FromField
a
)
=>
PGS
.
FromRow
(
Indexed
i
a
)
where
fromRow
=
Indexed
<$>
field
<*>
field
fromRow
=
Indexed
<$>
field
<*>
field
instance
HasText
a
=>
HasText
(
Indexed
i
a
)
where
hasText
(
Indexed
_
a
)
=
hasText
a
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment