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
163
Issues
163
List
Board
Labels
Milestones
Merge Requests
9
Merge Requests
9
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
11f5f30e
Verified
Commit
11f5f30e
authored
Feb 27, 2025
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[sqlite] WIP CorpusSQLiteData to make import/export easier
parent
ee090895
Pipeline
#7377
failed with stages
in 51 minutes and 15 seconds
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
8 deletions
+51
-8
Utils.hs
src/Gargantext/API/Node/Corpus/Export/Utils.hs
+49
-6
Export.hs
test/Test/API/Export.hs
+2
-2
No files found.
src/Gargantext/API/Node/Corpus/Export/Utils.hs
View file @
11f5f30e
...
@@ -20,8 +20,8 @@ import Data.HashMap.Strict qualified as HashMap
...
@@ -20,8 +20,8 @@ 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.Time.Clock
(
getCurrentTime
)
import
Data.Time.Clock
(
getCurrentTime
)
import
Data.Time.Format.ISO8601
(
iso8601Show
)
import
Data.Time.Format.ISO8601
(
iso8601
ParseM
,
iso8601
Show
)
import
Data.Version
(
showVersion
)
import
Data.Version
(
parseVersion
,
showVersion
)
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
(
unNgramsTerm
)
)
import
Gargantext.API.Ngrams.Types
(
NgramsTerm
(
unNgramsTerm
)
)
...
@@ -34,7 +34,7 @@ import Gargantext.Database.Action.Metrics.NgramsByContext (getNgramsByContextOnl
...
@@ -34,7 +34,7 @@ import Gargantext.Database.Action.Metrics.NgramsByContext (getNgramsByContextOnl
import
Gargantext.Database.Admin.Config
(
userMaster
)
import
Gargantext.Database.Admin.Config
(
userMaster
)
import
Gargantext.Database.Admin.Types.Hyperdata.Corpus
(
HyperdataCorpus
)
import
Gargantext.Database.Admin.Types.Hyperdata.Corpus
(
HyperdataCorpus
)
import
Gargantext.Database.Admin.Types.Hyperdata.List
(
HyperdataList
)
import
Gargantext.Database.Admin.Types.Hyperdata.List
(
HyperdataList
)
import
Gargantext.Database.Admin.Types.Node
(
unNodeId
,
ContextId
(
_ContextId
))
import
Gargantext.Database.Admin.Types.Node
(
unNodeId
,
ContextId
(
_ContextId
)
,
NodeId
(
UnsafeMkNodeId
)
)
import
Gargantext.Database.Prelude
(
DBCmd
,
IsDBCmd
)
import
Gargantext.Database.Prelude
(
DBCmd
,
IsDBCmd
)
import
Gargantext.Database.Schema.Context
(
context_id
,
context_name
,
context_date
,
context_hyperdata
)
import
Gargantext.Database.Schema.Context
(
context_id
,
context_name
,
context_date
,
context_hyperdata
)
import
Gargantext.Database.Schema.Node
(
node_hash_id
,
node_hyperdata
,
node_name
,
node_parent_id
)
import
Gargantext.Database.Schema.Node
(
node_hash_id
,
node_hyperdata
,
node_name
,
node_parent_id
)
...
@@ -47,7 +47,7 @@ import Paths_gargantext qualified as PG -- cabal magic build module
...
@@ -47,7 +47,7 @@ import Paths_gargantext qualified as PG -- cabal magic build module
import
Prelude
qualified
import
Prelude
qualified
import
System.Directory
(
removeDirectoryRecursive
)
import
System.Directory
(
removeDirectoryRecursive
)
import
System.IO.Temp
(
createTempDirectory
,
getCanonicalTemporaryDirectory
)
import
System.IO.Temp
(
createTempDirectory
,
getCanonicalTemporaryDirectory
)
import
Text.ParserCombinators.ReadP
(
readP_to_S
)
...
@@ -170,8 +170,51 @@ mkCorpusSQLite (CorpusSQLiteData { .. }) = withTempSQLiteDir $ \(fp, _fname, fpa
...
@@ -170,8 +170,51 @@ mkCorpusSQLite (CorpusSQLiteData { .. }) = withTempSQLiteDir $ \(fp, _fname, fpa
bsl
<-
BSL
.
readFile
fpath
bsl
<-
BSL
.
readFile
fpath
pure
$
CorpusSQLite
bsl
pure
$
CorpusSQLite
{
_cs_bs
=
bsl
}
readCorpusSQLite
::
(
CES
.
MonadMask
m
,
MonadBase
IO
m
)
=>
CorpusSQLite
->
m
(
Either
Text
CorpusSQLiteData
)
readCorpusSQLite
(
CorpusSQLite
{
_cs_bs
})
=
withTempSQLiteDir
$
\
(
_fp
,
_fname
,
fpath
)
->
liftBase
$
do
(
info
,
corpusData
,
listData
)
<-
S
.
withConnection
fpath
$
\
conn
->
do
[
S
.
Only
version
]
<-
S
.
query_
conn
"SELECT value FROM info WHERE key = 'gargVersion'"
[
S
.
Only
cId
]
<-
S
.
query_
conn
"SELECT value FROM info WHERE key = 'corpusId'"
[
S
.
Only
lId
]
<-
S
.
query_
conn
"SELECT value FROM info WHERE key = 'listId'"
[
S
.
Only
created
]
<-
S
.
query_
conn
"SELECT value FROM info WHERE key = 'created'"
let
info
=
(
version
,
cId
,
lId
,
created
)
[
corpusData
]
<-
S
.
query_
conn
"SELECT name, hash, parent_id, hyperdata FROM corpus"
[
listData
]
<-
S
.
query_
conn
"SELECT name, parent_id, hyperdata FROM lists"
-- [ngrams] <- S.query_ conn "SELECT context_id, terms, type_ FROM ngrams"
-- [documents] <- S.query_ conn "SELECT context_id, name, date, hyperdata FROM documents"
pure
(
info
,
corpusData
,
listData
)
--, ngrams, documents)
let
(
version
,
cId
,
lId
,
created
)
=
info
let
(
_csd_corpus_name
,
_csd_corpus_hash
,
corpusParent
,
corpusHyperdata
)
=
corpusData
let
(
_csd_list_name
,
listParent
,
listHyperdata
)
=
listData
case
(
readP_to_S
parseVersion
version
,
iso8601ParseM
created
,
Aeson
.
decode
corpusHyperdata
,
Aeson
.
decode
listHyperdata
)
of
([(
_csd_version
,
_
)],
Just
_csd_created
,
Just
_csd_corpus_hyperdata
,
Just
_csd_list_hyperdata
)
->
do
let
_csd_cId
=
UnsafeMkNodeId
cId
let
_csd_lId
=
UnsafeMkNodeId
lId
let
_csd_corpus_parent
=
UnsafeMkNodeId
<$>
corpusParent
let
_csd_list_parent
=
UnsafeMkNodeId
<$>
listParent
-- TODO
let
_csd_contexts
=
[]
let
_csd_map_context_ngrams
=
Map
.
empty
let
_csd_stop_context_ngrams
=
Map
.
empty
let
_csd_candidate_context_ngrams
=
Map
.
empty
pure
$
Right
$
CorpusSQLiteData
{
..
}
_
->
pure
$
Left
"Parse error"
withTempSQLiteDir
::
(
CES
.
MonadMask
m
,
MonadBase
IO
m
)
withTempSQLiteDir
::
(
CES
.
MonadMask
m
,
MonadBase
IO
m
)
=>
((
FilePath
,
Prelude
.
String
,
FilePath
)
->
m
a
)
=>
((
FilePath
,
Prelude
.
String
,
FilePath
)
->
m
a
)
...
...
test/Test/API/Export.hs
View file @
11f5f30e
...
@@ -5,7 +5,7 @@ module Test.API.Export (tests) where
...
@@ -5,7 +5,7 @@ module Test.API.Export (tests) where
import
Control.Lens
(
view
)
import
Control.Lens
(
view
)
import
Data.ByteString.Lazy
qualified
as
BSL
import
Data.ByteString.Lazy
qualified
as
BSL
import
Data.Version
(
showVersion
)
import
Data.Version
(
parseVersion
,
showVersion
)
import
Database.SQLite.Simple
qualified
as
S
import
Database.SQLite.Simple
qualified
as
S
-- import Fmt (build)
-- import Fmt (build)
import
Gargantext.API.Node.Corpus.Export.Types
(
CorpusSQLite
(
..
),
CorpusSQLiteData
(
..
))
import
Gargantext.API.Node.Corpus.Export.Types
(
CorpusSQLite
(
..
),
CorpusSQLiteData
(
..
))
...
@@ -18,7 +18,7 @@ import Gargantext.Core.Types.Individu
...
@@ -18,7 +18,7 @@ import Gargantext.Core.Types.Individu
import
Gargantext.Database.Action.Flow
(
addDocumentsToHyperCorpus
)
import
Gargantext.Database.Action.Flow
(
addDocumentsToHyperCorpus
)
import
Gargantext.Database.Action.User
(
getUserId
)
import
Gargantext.Database.Action.User
(
getUserId
)
import
Gargantext.Database.Admin.Types.Hyperdata.Corpus
(
HyperdataCorpus
)
import
Gargantext.Database.Admin.Types.Hyperdata.Corpus
(
HyperdataCorpus
)
import
Gargantext.Database.Admin.Types.Node
(
NodeType
(
NodeFolder
,
NodeCorpus
,
NodeFolderPrivate
))
import
Gargantext.Database.Admin.Types.Node
(
NodeType
(
NodeFolder
,
NodeCorpus
,
NodeFolderPrivate
)
,
NodeId
(
UnsafeMkNodeId
)
)
import
Gargantext.Database.Query.Table.Node
(
getOrMkList
,
getNodeWith
,
insertDefaultNode
,
insertNode
)
import
Gargantext.Database.Query.Table.Node
(
getOrMkList
,
getNodeWith
,
insertDefaultNode
,
insertNode
)
import
Gargantext.Database.Query.Tree.Root
(
getRootId
)
import
Gargantext.Database.Query.Tree.Root
(
getRootId
)
import
Gargantext.Database.Schema.Node
(
node_hyperdata
)
import
Gargantext.Database.Schema.Node
(
node_hyperdata
)
...
...
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