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
878907d0
Commit
878907d0
authored
Feb 07, 2022
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FEAT][PHYLO] corpusId to Documents function
parent
85fcd70b
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
115 additions
and
32 deletions
+115
-32
Main.hs
bin/gargantext-phylo/Main.hs
+2
-26
package.yaml
package.yaml
+1
-0
Export.hs
src/Gargantext/API/Node/Corpus/Export.hs
+4
-3
API.hs
src/Gargantext/Core/Viz/Phylo/API.hs
+108
-0
NgramsByContext.hs
src/Gargantext/Database/Action/Metrics/NgramsByContext.hs
+0
-3
No files found.
bin/gargantext-phylo/Main.hs
View file @
878907d0
...
...
@@ -49,6 +49,8 @@ import Gargantext.Core.Viz.Phylo.PhyloMaker (toPhylo, toPhyloStep)
import
Gargantext.Core.Viz.Phylo.PhyloTools
(
printIOMsg
,
printIOComment
,
setConfig
)
import
Gargantext.Core.Viz.Phylo.PhyloExport
(
toPhyloExport
,
dotToFile
)
-- import Gargantext.API.Ngrams.Prelude (toTermList)
import
Gargantext.Core.Viz.Phylo.API
(
toPhyloDate
,
toPhyloDate'
)
-- import Debug.Trace (trace)
...
...
@@ -66,32 +68,6 @@ getFilesFromPath path = do
then
(
listDirectory
path
)
else
return
[
path
]
---------------
-- | Dates | --
---------------
toMonths
::
Integer
->
Int
->
Int
->
Date
toMonths
y
m
d
=
fromIntegral
$
cdMonths
$
diffGregorianDurationClip
(
fromGregorian
y
m
d
)
(
fromGregorian
0000
0
0
)
toDays
::
Integer
->
Int
->
Int
->
Date
toDays
y
m
d
=
fromIntegral
$
diffDays
(
fromGregorian
y
m
d
)
(
fromGregorian
0000
0
0
)
toPhyloDate
::
Int
->
Int
->
Int
->
TimeUnit
->
Date
toPhyloDate
y
m
d
tu
=
case
tu
of
Year
_
_
_
->
y
Month
_
_
_
->
toMonths
(
Prelude
.
toInteger
y
)
m
d
Week
_
_
_
->
div
(
toDays
(
Prelude
.
toInteger
y
)
m
d
)
7
Day
_
_
_
->
toDays
(
Prelude
.
toInteger
y
)
m
d
-- Function to use in Database export
toPhyloDate'
::
Int
->
Int
->
Int
->
Text
toPhyloDate'
y
m
d
=
pack
$
showGregorian
$
fromGregorian
(
Prelude
.
toInteger
y
)
m
d
--------------
-- | Json | --
--------------
...
...
package.yaml
View file @
878907d0
...
...
@@ -101,6 +101,7 @@ library:
-
Gargantext.Core.Viz.Graph.Tools.IGraph
-
Gargantext.Core.Viz.Graph.Index
-
Gargantext.Core.Viz.Phylo
-
Gargantext.Core.Viz.Phylo.API
-
Gargantext.Core.Viz.Phylo.PhyloMaker
-
Gargantext.Core.Viz.Phylo.PhyloTools
-
Gargantext.Core.Viz.Phylo.PhyloExport
...
...
src/Gargantext/API/Node/Corpus/Export.hs
View file @
878907d0
...
...
@@ -67,7 +67,7 @@ getCorpus cId lId nt' = do
<$>
selectDocNodes
cId
repo
<-
getRepo'
[
listId
]
ngs
<-
getContextNgrams
cId
listId
nt
repo
ngs
<-
getContextNgrams
cId
listId
MapTerm
nt
repo
let
-- uniqId is hash computed already for each document imported in database
r
=
Map
.
intersectionWith
(
\
a
b
->
DocumentExport
.
Document
{
_d_document
=
context2node
a
...
...
@@ -85,16 +85,17 @@ getCorpus cId lId nt' = do
getContextNgrams
::
HasNodeError
err
=>
CorpusId
->
ListId
->
ListType
->
NgramsType
->
NodeListStory
->
Cmd
err
(
Map
ContextId
(
Set
NgramsTerm
))
getContextNgrams
cId
lId
nt
repo
=
do
getContextNgrams
cId
lId
listType
nt
repo
=
do
-- lId <- case lId' of
-- Nothing -> defaultList cId
-- Just l -> pure l
lIds
<-
selectNodesWithUsername
NodeList
userMaster
let
ngs
=
filterListWithRoot
MapTerm
$
mapTermListRoot
[
lId
]
nt
repo
let
ngs
=
filterListWithRoot
listType
$
mapTermListRoot
[
lId
]
nt
repo
-- TODO HashMap
r
<-
getNgramsByContextOnlyUser
cId
(
lIds
<>
[
lId
])
nt
(
HashMap
.
keys
ngs
)
pure
r
...
...
src/Gargantext/Core/Viz/Phylo/API.hs
0 → 100644
View file @
878907d0
{-|
Module : Gargantext.Core.Viz.Phylo.API
Description :
Copyright : (c) CNRS, 2017-Present
License : AGPL + CECILL v3
Maintainer : team@gargantext.org
Stability : experimental
Portability : POSIX
-}
module
Gargantext.Core.Viz.Phylo.API
where
import
Data.Map
(
Map
)
import
Data.Maybe
(
catMaybes
)
import
Data.Text
(
Text
,
pack
)
import
Data.Set
(
Set
)
import
Data.Time.Calendar
(
fromGregorian
,
diffGregorianDurationClip
,
cdMonths
,
diffDays
,
showGregorian
)
import
Gargantext.API.Ngrams.Tools
(
getRepo'
)
import
Gargantext.API.Node.Corpus.Export
(
getContextNgrams
)
import
Gargantext.API.Prelude
(
GargNoServer
)
import
Gargantext.Core.Types
(
Context
)
import
Gargantext.Core.Types.Main
(
ListType
(
MapTerm
))
import
Gargantext.Core.Viz.Phylo
(
TimeUnit
(
..
),
Date
,
Document
(
..
))
import
Gargantext.Database.Admin.Types.Hyperdata.Document
(
HyperdataDocument
(
..
))
import
Gargantext.Database.Admin.Types.Node
(
CorpusId
,
ContextId
)
import
Gargantext.Database.Query.Table.Node
(
defaultList
)
import
Gargantext.Database.Query.Table.NodeContext
(
selectDocNodes
)
import
Gargantext.Database.Schema.Context
import
Gargantext.Database.Schema.Ngrams
(
NgramsType
(
..
))
import
Gargantext.Prelude
import
Prelude
as
Prelude
import
Gargantext.API.Ngrams.Types
(
NgramsTerm
(
..
))
import
qualified
Data.Map
as
Map
import
qualified
Data.Set
as
Set
import
qualified
Data.List
as
List
corpusIdtoDocuments
::
TimeUnit
->
CorpusId
->
GargNoServer
[
Document
]
corpusIdtoDocuments
timeUnit
corpusId
=
do
docs
<-
selectDocNodes
corpusId
lId
<-
defaultList
corpusId
repo
<-
getRepo'
[
lId
]
ngs_terms
<-
getContextNgrams
corpusId
lId
MapTerm
NgramsTerms
repo
ngs_sources
<-
getContextNgrams
corpusId
lId
MapTerm
Sources
repo
pure
$
catMaybes
$
List
.
map
(
\
doc
->
context2phyloDocument
timeUnit
doc
(
ngs_terms
,
ngs_sources
)
)
docs
context2phyloDocument
::
TimeUnit
->
Context
HyperdataDocument
->
(
Map
ContextId
(
Set
NgramsTerm
),
Map
ContextId
(
Set
NgramsTerm
))
->
Maybe
Document
context2phyloDocument
timeUnit
context
(
ngs_terms
,
ngs_sources
)
=
do
let
contextId
=
_context_id
context
(
date
,
date'
)
<-
context2date
context
timeUnit
text
<-
Map
.
lookup
contextId
ngs_terms
sources
<-
Map
.
lookup
contextId
ngs_sources
pure
$
Document
date
date'
(
toText
text
)
Nothing
(
toText
sources
)
where
toText
x
=
Set
.
toList
$
Set
.
map
unNgramsTerm
x
context2date
::
Context
HyperdataDocument
->
TimeUnit
->
Maybe
(
Date
,
Text
)
context2date
context
timeUnit
=
do
let
hyperdata
=
_context_hyperdata
context
year
<-
_hd_publication_year
hyperdata
month
<-
_hd_publication_month
hyperdata
day
<-
_hd_publication_day
hyperdata
pure
(
toPhyloDate
year
month
day
timeUnit
,
toPhyloDate'
year
month
day
)
---------------
-- | Dates | --
---------------
toMonths
::
Integer
->
Int
->
Int
->
Date
toMonths
y
m
d
=
fromIntegral
$
cdMonths
$
diffGregorianDurationClip
(
fromGregorian
y
m
d
)
(
fromGregorian
0000
0
0
)
toDays
::
Integer
->
Int
->
Int
->
Date
toDays
y
m
d
=
fromIntegral
$
diffDays
(
fromGregorian
y
m
d
)
(
fromGregorian
0000
0
0
)
toPhyloDate
::
Int
->
Int
->
Int
->
TimeUnit
->
Date
toPhyloDate
y
m
d
tu
=
case
tu
of
Year
_
_
_
->
y
Month
_
_
_
->
toMonths
(
Prelude
.
toInteger
y
)
m
d
Week
_
_
_
->
div
(
toDays
(
Prelude
.
toInteger
y
)
m
d
)
7
Day
_
_
_
->
toDays
(
Prelude
.
toInteger
y
)
m
d
-- Function to use in Database export
toPhyloDate'
::
Int
->
Int
->
Int
->
Text
toPhyloDate'
y
m
d
=
pack
$
showGregorian
$
fromGregorian
(
Prelude
.
toInteger
y
)
m
d
src/Gargantext/Database/Action/Metrics/NgramsByContext.hs
View file @
878907d0
...
...
@@ -60,7 +60,6 @@ countContextsByNgramsWith f m = (total, m')
$
HM
.
toList
m''
------------------------------------------------------------------------
getContextsByNgramsUser
::
HasDBid
NodeType
=>
CorpusId
->
NgramsType
...
...
@@ -191,7 +190,6 @@ queryNgramsOccurrencesOnlyByContextUser_withSample = [sql|
------------------------------------------------------------------------
getContextsByNgramsOnlyUser
::
HasDBid
NodeType
=>
CorpusId
->
[
ListId
]
...
...
@@ -221,7 +219,6 @@ getNgramsByContextOnlyUser cId ls nt ngs =
(
splitEvery
1000
ngs
)
------------------------------------------------------------------------
-- used in G.Core.Text.List
selectNgramsOnlyByContextUser
::
HasDBid
NodeType
=>
CorpusId
->
[
ListId
]
...
...
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