Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
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
Przemyslaw Kaminski
haskell-gargantext
Commits
10b2cb3e
Commit
10b2cb3e
authored
Jul 27, 2021
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[NodeStory] Tools updates (WIP)
parent
be4c8194
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
11 deletions
+80
-11
Tools.hs
src/Gargantext/API/Ngrams/Tools.hs
+73
-6
NodeStory.hs
src/Gargantext/Core/NodeStory.hs
+7
-5
No files found.
src/Gargantext/API/Ngrams/Tools.hs
View file @
10b2cb3e
...
...
@@ -28,6 +28,7 @@ import Gargantext.Prelude
import
qualified
Data.HashMap.Strict
as
HM
import
qualified
Data.Map.Strict
as
Map
import
qualified
Data.Set
as
Set
import
qualified
Data.List
as
List
import
Gargantext.Core.NodeStory
mergeNgramsElement
::
NgramsRepoElement
->
NgramsRepoElement
->
NgramsRepoElement
...
...
@@ -40,24 +41,33 @@ getRepo = do
v
<-
view
repoVar
liftBase
$
readMVar
v
getNodeListStory
::
HasNodeStory'
env
err
m
getRepo'
::
HasNodeStory
env
err
m
=>
[
ListId
]
->
m
NodeListStory
getRepo'
listIds
=
do
maybeNodeListStory
<-
head
<$>
List
.
reverse
<$>
mapM
getNodeListStory''
listIds
case
maybeNodeListStory
of
Nothing
->
panic
"[G.A.N.Tools.getRepo']"
Just
nls
->
pure
nls
getNodeListStory
::
HasNodeStory
env
err
m
=>
m
(
NodeId
->
IO
(
MVar
NodeListStory
))
getNodeListStory
=
do
env
<-
view
hasNodeStory
pure
$
view
nse_getter
env
getNodeListStory'
::
HasNodeStory
'
env
err
m
getNodeListStory'
::
HasNodeStory
env
err
m
=>
NodeId
->
m
(
IO
NodeListStory
)
getNodeListStory'
n
=
do
f
<-
getNodeListStory
v
<-
liftBase
$
f
n
pure
$
readMVar
v
getNodeListStory''
::
HasNodeStory
'
env
err
m
getNodeListStory''
::
HasNodeStory
env
err
m
=>
NodeId
->
m
NodeListStory
getNodeListStory''
n
=
do
f
<-
getNodeListStory
v
<-
liftBase
$
f
n
v
<-
liftBase
$
f
n
v'
<-
liftBase
$
readMVar
v
pure
$
v'
...
...
@@ -74,6 +84,22 @@ listNgramsFromRepo nodeIds ngramsType repo = ngrams
[
ngramsMap
^.
at
nodeId
.
_Just
|
nodeId
<-
nodeIds
]
listNgramsFromRepo'
::
[
ListId
]
->
NgramsType
->
NodeListStory
->
HashMap
NgramsTerm
NgramsRepoElement
listNgramsFromRepo'
nodeIds
ngramsType
repo
=
HM
.
fromList
$
Map
.
toList
$
Map
.
unionsWith
mergeNgramsElement
ngrams
where
ngrams
=
[
repo
^.
unNodeStory
.
at
nodeId
.
_Just
.
a_state
.
at
ngramsType
.
_Just
|
nodeId
<-
nodeIds
]
-- TODO-ACCESS: We want to do the security check before entering here.
-- Add a static capability parameter would be nice.
-- Ideally this is the access to `repoVar` which needs to
...
...
@@ -83,6 +109,13 @@ getListNgrams :: RepoCmdM env err m
->
m
(
HashMap
NgramsTerm
NgramsRepoElement
)
getListNgrams
nodeIds
ngramsType
=
listNgramsFromRepo
nodeIds
ngramsType
<$>
getRepo
getListNgrams'
::
HasNodeStory
env
err
m
=>
[
ListId
]
->
NgramsType
->
m
(
HashMap
NgramsTerm
NgramsRepoElement
)
getListNgrams'
nodeIds
ngramsType
=
listNgramsFromRepo'
nodeIds
ngramsType
<$>
getRepo'
nodeIds
getTermsWith
::
(
RepoCmdM
env
err
m
,
Eq
a
,
Hashable
a
)
=>
(
NgramsTerm
->
a
)
->
[
ListId
]
->
NgramsType
->
Set
ListType
...
...
@@ -97,6 +130,23 @@ getTermsWith f ls ngt lts = HM.fromListWith (<>)
toTreeWith
(
t
,
(
_lt
,
maybeRoot
))
=
case
maybeRoot
of
Nothing
->
(
f
t
,
[]
)
Just
r
->
(
f
r
,
[
f
t
])
getTermsWith'
::
(
HasNodeStory
env
err
m
,
Eq
a
,
Hashable
a
)
=>
(
NgramsTerm
->
a
)
->
[
ListId
]
->
NgramsType
->
Set
ListType
->
m
(
HashMap
a
[
a
])
getTermsWith'
f
ls
ngt
lts
=
HM
.
fromListWith
(
<>
)
<$>
map
toTreeWith
<$>
HM
.
toList
<$>
HM
.
filter
(
\
f'
->
Set
.
member
(
fst
f'
)
lts
)
<$>
mapTermListRoot'
ls
ngt
<$>
getRepo'
ls
where
toTreeWith
(
t
,
(
_lt
,
maybeRoot
))
=
case
maybeRoot
of
Nothing
->
(
f
t
,
[]
)
Just
r
->
(
f
r
,
[
f
t
])
mapTermListRoot
::
[
ListId
]
->
NgramsType
...
...
@@ -105,6 +155,17 @@ mapTermListRoot :: [ListId]
mapTermListRoot
nodeIds
ngramsType
repo
=
(
\
nre
->
(
_nre_list
nre
,
_nre_root
nre
))
<$>
listNgramsFromRepo
nodeIds
ngramsType
repo
mapTermListRoot'
::
[
ListId
]
->
NgramsType
->
NodeListStory
->
HashMap
NgramsTerm
(
ListType
,
Maybe
NgramsTerm
)
mapTermListRoot'
nodeIds
ngramsType
repo
=
(
\
nre
->
(
_nre_list
nre
,
_nre_root
nre
))
<$>
listNgramsFromRepo'
nodeIds
ngramsType
repo
filterListWithRootHashMap
::
ListType
->
HashMap
NgramsTerm
(
ListType
,
Maybe
NgramsTerm
)
...
...
@@ -146,11 +207,17 @@ groupNodesByNgrams syn occs = HM.fromListWith (<>) occs'
data
Diagonal
=
Diagonal
Bool
getCoocByNgrams
::
Diagonal
->
HashMap
NgramsTerm
(
Set
NodeId
)
->
HashMap
(
NgramsTerm
,
NgramsTerm
)
Int
getCoocByNgrams
::
Diagonal
->
HashMap
NgramsTerm
(
Set
NodeId
)
->
HashMap
(
NgramsTerm
,
NgramsTerm
)
Int
getCoocByNgrams
=
getCoocByNgrams'
identity
getCoocByNgrams'
::
(
Hashable
a
,
Ord
a
,
Ord
c
)
=>
(
b
->
Set
c
)
->
Diagonal
->
HashMap
a
b
->
HashMap
(
a
,
a
)
Int
getCoocByNgrams'
::
(
Hashable
a
,
Ord
a
,
Ord
c
)
=>
(
b
->
Set
c
)
->
Diagonal
->
HashMap
a
b
->
HashMap
(
a
,
a
)
Int
getCoocByNgrams'
f
(
Diagonal
diag
)
m
=
HM
.
fromList
[(
(
t1
,
t2
)
,
maybe
0
Set
.
size
$
Set
.
intersection
...
...
src/Gargantext/Core/NodeStory.hs
View file @
10b2cb3e
...
...
@@ -29,7 +29,6 @@ import Gargantext.API.Ngrams.Types
import
Gargantext.Core.Types
(
NodeId
)
import
Gargantext.Core.Utils.Prefix
(
unPrefix
)
import
Gargantext.Prelude
import
Control.Monad.Reader
import
qualified
Gargantext.Database.Query.Table.Ngrams
as
TableNgrams
import
qualified
Data.Map.Strict.Patch.Internal
as
Patch
import
qualified
Data.ByteString.Lazy
as
L
...
...
@@ -48,13 +47,14 @@ data NodeStoryEnv = NodeStoryEnv
}
deriving
(
Generic
)
type
HasNodeStory
'
env
err
m
=
(
CmdM'
env
err
m
,
HasNodeStory
env
type
HasNodeStory
env
err
m
=
(
CmdM'
env
err
m
,
HasNodeStory
Env
env
,
HasConfig
env
,
HasConnectionPool
env
)
class
(
HasNodeStoryVar
env
,
HasNodeStorySaver
env
)
=>
HasNodeStory
env
where
=>
HasNodeStory
Env
env
where
hasNodeStory
::
Getter
env
NodeStoryEnv
class
HasNodeStoryVar
env
where
...
...
@@ -184,7 +184,7 @@ ngramsStatePatch_migration np' = Map.fromListWith (<>)
TODO : generalize for any NodeType, let's start with NodeList which
is implemented already
-}
data
NodeStory
s
p
=
NodeStory
{
unNodeStory
::
Map
NodeId
(
Archive
s
p
)
}
data
NodeStory
s
p
=
NodeStory
{
_
unNodeStory
::
Map
NodeId
(
Archive
s
p
)
}
deriving
(
Generic
,
Show
)
instance
(
FromJSON
s
,
FromJSON
p
)
=>
FromJSON
(
NodeStory
s
p
)
...
...
@@ -239,3 +239,5 @@ initNodeListStoryMock = NodeStory $ Map.singleton nodeListId archive
------------------------------------------------------------------------
-- | Lenses at the bottom of the file because Template Haskell would reorder order of execution in others cases
makeLenses
''
N
odeStoryEnv
makeLenses
''
N
odeStory
makeLenses
''
A
rchive
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