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
197
Issues
197
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
4568d4ec
Verified
Commit
4568d4ec
authored
Mar 03, 2025
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[export] refactor sqlite do use Either monad
parent
c227e749
Pipeline
#7400
passed with stages
in 83 minutes and 26 seconds
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
21 deletions
+29
-21
Utils.hs
src/Gargantext/API/Node/Corpus/Export/Utils.hs
+29
-21
No files found.
src/Gargantext/API/Node/Corpus/Export/Utils.hs
View file @
4568d4ec
...
@@ -14,14 +14,16 @@ module Gargantext.API.Node.Corpus.Export.Utils
...
@@ -14,14 +14,16 @@ module Gargantext.API.Node.Corpus.Export.Utils
where
where
import
Control.Exception.Safe
qualified
as
CES
import
Control.Exception.Safe
qualified
as
CES
import
Control.Monad.Fail
(
fail
)
import
Data.Aeson
qualified
as
Aeson
import
Data.Aeson
qualified
as
Aeson
import
Data.ByteString.Lazy
qualified
as
BSL
import
Data.ByteString.Lazy
qualified
as
BSL
import
Data.HashMap.Strict
qualified
as
HashMap
import
Data.HashMap.Strict
qualified
as
HashMap
import
Data.Map.Strict
qualified
as
Map
import
Data.Map.Strict
qualified
as
Map
import
Data.Set
qualified
as
Set
import
Data.Set
qualified
as
Set
import
Data.Text
qualified
as
T
import
Data.Time.Clock
(
getCurrentTime
,
UTCTime
)
import
Data.Time.Clock
(
getCurrentTime
,
UTCTime
)
import
Data.Time.Format.ISO8601
(
iso8601ParseM
,
iso8601Show
)
import
Data.Time.Format.ISO8601
(
iso8601ParseM
,
iso8601Show
)
import
Data.Version
(
parseVersion
,
showVersion
)
import
Data.Version
(
parseVersion
,
showVersion
,
Version
)
import
Database.SQLite.Simple
qualified
as
S
import
Database.SQLite.Simple
qualified
as
S
import
Gargantext.API.Ngrams.Tools
(
filterListWithRoot
,
mapTermListRoot
,
getRepo
)
import
Gargantext.API.Ngrams.Tools
(
filterListWithRoot
,
mapTermListRoot
,
getRepo
)
import
Gargantext.API.Ngrams.Types
(
NgramsTerm
(
..
)
)
import
Gargantext.API.Ngrams.Types
(
NgramsTerm
(
..
)
)
...
@@ -67,8 +69,7 @@ getContextNgrams cId lId listType nt repo = do
...
@@ -67,8 +69,7 @@ getContextNgrams cId lId listType nt repo = do
lIds
<-
selectNodesWithUsername
NodeList
userMaster
lIds
<-
selectNodesWithUsername
NodeList
userMaster
let
ngs
=
filterListWithRoot
[
listType
]
$
mapTermListRoot
[
lId
]
nt
repo
let
ngs
=
filterListWithRoot
[
listType
]
$
mapTermListRoot
[
lId
]
nt
repo
-- TODO HashMap
-- TODO HashMap
r
<-
getNgramsByContextOnlyUser
cId
(
lIds
<>
[
lId
])
nt
(
HashMap
.
keys
ngs
)
getNgramsByContextOnlyUser
cId
(
lIds
<>
[
lId
])
nt
(
HashMap
.
keys
ngs
)
pure
r
mkCorpusSQLiteData
::
(
CES
.
MonadMask
m
mkCorpusSQLiteData
::
(
CES
.
MonadMask
m
...
@@ -201,14 +202,17 @@ readCorpusSQLite (CorpusSQLite { _cs_bs }) = withTempSQLiteDir $ \(_fp, _fname,
...
@@ -201,14 +202,17 @@ readCorpusSQLite (CorpusSQLite { _cs_bs }) = withTempSQLiteDir $ \(_fp, _fname,
let
(
ngrams_errors
,
ngrams_
)
=
partitionEithers
(
parseNgrams
<$>
ngrams
)
let
(
ngrams_errors
,
ngrams_
)
=
partitionEithers
(
parseNgrams
<$>
ngrams
)
-- TODO pure $ do in Either monad
-- NOTE To make things simpler, use the 'Either Text CorpusSQLData' as a monad
case
(
readP_to_S
parseVersion
version
-- (there's quire a few things to test here)
,
iso8601ParseM
created
pure
$
do
,
Aeson
.
decode
corpusHyperdata
_csd_version
<-
eParseVersion
version
,
Aeson
.
decode
listHyperdata
_csd_created
<-
maybeToEither
(
"Incorrect created: "
<>
T
.
pack
created
)
$
iso8601ParseM
created
,
context_errors
_csd_corpus_hyperdata
<-
first
T
.
pack
$
Aeson
.
eitherDecode
corpusHyperdata
,
ngrams_errors
)
of
_csd_list_hyperdata
<-
first
T
.
pack
$
Aeson
.
eitherDecode
listHyperdata
([(
_csd_version
,
_
)],
Just
_csd_created
,
Just
_csd_corpus_hyperdata
,
Just
_csd_list_hyperdata
,
[]
,
[]
)
->
do
unless
(
null
context_errors
)
$
fail
$
"Context errors: "
<>
show
context_errors
unless
(
null
ngrams_errors
)
$
fail
$
"Ngrams errors: "
<>
show
ngrams_errors
let
_csd_cId
=
UnsafeMkNodeId
cId
let
_csd_cId
=
UnsafeMkNodeId
cId
let
_csd_lId
=
UnsafeMkNodeId
lId
let
_csd_lId
=
UnsafeMkNodeId
lId
...
@@ -220,10 +224,14 @@ readCorpusSQLite (CorpusSQLite { _cs_bs }) = withTempSQLiteDir $ \(_fp, _fname,
...
@@ -220,10 +224,14 @@ readCorpusSQLite (CorpusSQLite { _cs_bs }) = withTempSQLiteDir $ \(_fp, _fname,
let
_csd_stop_context_ngrams
=
filterNgrams
StopTerm
ngrams_
let
_csd_stop_context_ngrams
=
filterNgrams
StopTerm
ngrams_
let
_csd_candidate_context_ngrams
=
filterNgrams
CandidateTerm
ngrams_
let
_csd_candidate_context_ngrams
=
filterNgrams
CandidateTerm
ngrams_
pure
$
Right
$
CorpusSQLiteData
{
..
}
pure
$
CorpusSQLiteData
{
..
}
_
->
pure
$
Left
"Parse error"
where
where
eParseVersion
::
Prelude
.
String
->
Either
Text
Version
eParseVersion
v
=
case
readP_to_S
parseVersion
v
of
[(
v_
,
_
)]
->
Right
v_
_
->
Left
(
"Incorrect version: "
<>
T
.
pack
v
)
parseCtx
::
(
Int
,
Text
,
Prelude
.
String
,
BSL
.
ByteString
)
parseCtx
::
(
Int
,
Text
,
Prelude
.
String
,
BSL
.
ByteString
)
->
Either
Text
(
NodeId
,
Text
,
UTCTime
,
HyperdataDocument
)
->
Either
Text
(
NodeId
,
Text
,
UTCTime
,
HyperdataDocument
)
parseCtx
(
ctxId
,
name
,
date
,
hd
)
=
parseCtx
(
ctxId
,
name
,
date
,
hd
)
=
...
...
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