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
902126ad
Commit
902126ad
authored
Mar 03, 2022
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FIX] V3 Ngrams List post/update with CSV format
parent
ba645886
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
25 deletions
+21
-25
List.hs
src/Gargantext/API/Ngrams/List.hs
+21
-25
No files found.
src/Gargantext/API/Ngrams/List.hs
View file @
902126ad
...
...
@@ -22,14 +22,14 @@ import Data.HashMap.Strict (HashMap)
import
Data.Map
(
Map
,
toList
)
import
Data.Maybe
(
catMaybes
)
import
Data.Set
(
Set
)
import
Data.Text
(
Text
,
concat
,
pack
)
import
Data.Text
(
Text
,
concat
,
pack
,
splitOn
)
import
Data.Vector
(
Vector
)
import
Gargantext.API.Admin.Orchestrator.Types
import
Gargantext.API.Ngrams
(
setListNgrams
)
import
Gargantext.API.Ngrams.List.Types
import
Gargantext.API.Ngrams.Prelude
(
getNgramsList
)
import
Gargantext.API.Ngrams.Tools
(
getTermsWith
)
import
Gargantext.API.Ngrams.Types
import
Gargantext.API.Ngrams.Prelude
(
getNgramsList
)
import
Gargantext.API.Ngrams.List.Types
import
Gargantext.API.Prelude
(
GargServer
)
import
Gargantext.Core.NodeStory
import
Gargantext.Core.Text.Terms
(
ExtractedNgrams
(
..
))
...
...
@@ -41,8 +41,8 @@ import Gargantext.Database.Action.Metrics.NgramsByContext (getOccByNgramsOnlyFas
import
Gargantext.Database.Admin.Types.Hyperdata.Document
import
Gargantext.Database.Admin.Types.Node
import
Gargantext.Database.Query.Table.NodeContext
(
selectDocNodes
)
import
Gargantext.Database.Schema.Ngrams
import
Gargantext.Database.Schema.Context
import
Gargantext.Database.Schema.Ngrams
import
Gargantext.Database.Types
(
Indexed
(
..
))
import
Gargantext.Prelude
import
Network.HTTP.Media
((
//
),
(
/:
))
...
...
@@ -58,17 +58,6 @@ import qualified Data.Vector as Vec
import
qualified
Prelude
as
Prelude
import
qualified
Protolude
as
P
------------------------------------------------------------------------
-- | TODO refactor
{-
type API = Get '[JSON, HTML] (Headers '[Header "Content-Disposition" Text] NgramsList)
-- :<|> ReqBody '[JSON] NgramsList :> Post '[JSON] Bool
:<|> PostAPI
:<|> CSVPostAPI
api :: ListId -> GargServer API
api l = get l :<|> postAsync l :<|> csvPostAsync l
-}
----------------------
type
GETAPI
=
Summary
"Get List"
:>
"lists"
:>
Capture
"listId"
ListId
...
...
@@ -122,11 +111,11 @@ get lId = do
------------------------------------------------------------------------
-- TODO : purge list
-- TODO talk
po
st
::
FlowCmdM
env
err
m
setLi
st
::
FlowCmdM
env
err
m
=>
ListId
->
NgramsList
->
m
Bool
po
st
l
m
=
do
setLi
st
l
m
=
do
-- TODO check with Version for optim
printDebug
"New list as file"
l
_
<-
mapM
(
\
(
nt
,
Versioned
_v
ns
)
->
setListNgrams
l
nt
ns
)
$
toList
m
...
...
@@ -227,7 +216,7 @@ postAsync' l (WithFile _ m _) logStatus = do
,
_scst_events
=
Just
[]
}
printDebug
"New list as file"
l
_
<-
po
st
l
m
_
<-
setLi
st
l
m
-- printDebug "Done" r
pure
JobLog
{
_scst_succeeded
=
Just
1
...
...
@@ -236,7 +225,6 @@ postAsync' l (WithFile _ m _) logStatus = do
,
_scst_events
=
Just
[]
}
------------------------------------------------------------------------
type
CSVPostAPI
=
Summary
"Update List (legacy v3 CSV)"
:>
"csv"
:>
"add"
...
...
@@ -257,12 +245,22 @@ readCsvText t = case eDec of
parseCsvData
::
[(
Text
,
Text
,
Text
)]
->
Map
NgramsTerm
NgramsRepoElement
parseCsvData
lst
=
Map
.
fromList
$
conv
<$>
lst
where
conv
(
_status
,
label
,
_
forms
)
=
conv
(
status
,
label
,
forms
)
=
(
NgramsTerm
label
,
NgramsRepoElement
{
_nre_size
=
1
,
_nre_list
=
CandidateTerm
,
_nre_list
=
case
status
==
"map"
of
True
->
MapTerm
False
->
case
status
==
"main"
of
True
->
CandidateTerm
False
->
StopTerm
,
_nre_root
=
Nothing
,
_nre_parent
=
Nothing
,
_nre_children
=
MSet
Map
.
empty
})
,
_nre_children
=
MSet
$
Map
.
fromList
$
map
(
\
form
->
(
NgramsTerm
form
,
()
))
$
filter
(
/=
""
)
$
splitOn
"|&|"
forms
}
)
csvPost
::
FlowCmdM
env
err
m
=>
ListId
...
...
@@ -278,10 +276,8 @@ csvPost l m = do
printDebug
"[csvPost] p"
p
_
<-
setListNgrams
l
NgramsTerms
p
pure
True
------------------------------------------------------------------------
------------------------------------------------------------------------
csvPostAsync
::
GargServer
CSVAPI
csvPostAsync
lId
=
serveJobsAPI
$
...
...
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