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
6cacf848
Commit
6cacf848
authored
Jan 07, 2019
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/dev-ngrams-table' into dev
parents
60e0b101
fd0699d9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
20 deletions
+22
-20
Ngrams.hs
src/Gargantext/API/Ngrams.hs
+2
-2
NodeNgram.hs
src/Gargantext/Database/Schema/NodeNgram.hs
+10
-12
NodeNgramsNgrams.hs
src/Gargantext/Database/Schema/NodeNgramsNgrams.hs
+7
-6
Utils.hs
src/Gargantext/Database/Utils.hs
+3
-0
No files found.
src/Gargantext/API/Ngrams.hs
View file @
6cacf848
...
...
@@ -44,7 +44,7 @@ import qualified Data.Set as Set
import
Data.Map.Strict
(
Map
)
--import qualified Data.Set as Set
import
Control.Lens
(
makeLenses
,
Prism
'
,
prism'
,
(
^..
),
(
.~
),
(
#
),
to
,
withIndex
,
folded
,
ifolded
)
import
Control.Monad
(
guard
,
void
)
import
Control.Monad
(
guard
)
import
Control.Monad.Error.Class
(
MonadError
,
throwError
)
import
Data.Aeson
import
Data.Aeson.TH
(
deriveJSON
)
...
...
@@ -297,7 +297,7 @@ tableNgramsPatch :: (HasNgramError err, HasNodeError err)
tableNgramsPatch
corpusId
maybeList
(
Versioned
version
patch
)
=
do
when
(
version
/=
1
)
$
ngramError
UnsupportedVersion
listId
<-
maybe
(
defaultList
corpusId
)
pure
maybeList
void
$
updateNodeNgrams
$
NodeNgramsUpdate
updateNodeNgrams
$
NodeNgramsUpdate
{
_nnu_lists_update
=
mkListsUpdate
listId
patch
,
_nnu_rem_children
=
mkChildrenGroups
listId
_rem
patch
,
_nnu_add_children
=
mkChildrenGroups
listId
_add
patch
...
...
src/Gargantext/Database/Schema/NodeNgram.hs
View file @
6cacf848
...
...
@@ -32,11 +32,12 @@ module Gargantext.Database.Schema.NodeNgram where
import
Data.Text
(
Text
)
import
Control.Lens.TH
(
makeLensesWith
,
abbreviatedFields
)
import
Control.Monad
(
void
)
import
Data.Profunctor.Product.TH
(
makeAdaptorAndInstance
)
import
Database.PostgreSQL.Simple.Types
(
Values
(
..
),
QualifiedIdentifier
(
..
))
import
Database.PostgreSQL.Simple.SqlQQ
(
sql
)
import
Gargantext.Core.Types.Main
(
ListId
,
ListTypeId
)
import
Gargantext.Database.Utils
(
mkCmd
,
Cmd
,
run
PGSQuery
)
import
Gargantext.Database.Utils
(
mkCmd
,
Cmd
,
exec
PGSQuery
)
import
Gargantext.Database.Schema.NodeNgramsNgrams
import
Gargantext.Prelude
import
Opaleye
...
...
@@ -115,10 +116,9 @@ insertNodeNgramW nns =
type
NgramsText
=
Text
updateNodeNgrams'
::
[(
ListId
,
NgramsText
,
ListTypeId
)]
->
Cmd
err
[
Int
]
updateNodeNgrams'
[]
=
pure
[]
updateNodeNgrams'
input
=
map
(
\
(
PGS
.
Only
a
)
->
a
)
<$>
runPGSQuery
updateQuery
(
PGS
.
Only
$
Values
fields
$
input
)
updateNodeNgrams'
::
[(
ListId
,
NgramsText
,
ListTypeId
)]
->
Cmd
err
()
updateNodeNgrams'
[]
=
pure
()
updateNodeNgrams'
input
=
void
$
execPGSQuery
updateQuery
(
PGS
.
Only
$
Values
fields
input
)
where
fields
=
map
(
\
t
->
QualifiedIdentifier
Nothing
t
)
[
"int4"
,
"text"
,
"int4"
]
updateQuery
=
[
sql
|
UPDATE nodes_ngrams as old SET
...
...
@@ -126,8 +126,7 @@ updateNodeNgrams' input = map (\(PGS.Only a) -> a) <$>
from (?) as new(node_id,terms,typeList)
JOIN ngrams ON ngrams.terms = new.terms
WHERE old.node_id = new.node_id
AND old.ngram_id = ngrams.id
RETURNING old.ngram_id;
AND old.ngram_id = ngrams.id;
|]
data
NodeNgramsUpdate
=
NodeNgramsUpdate
...
...
@@ -137,9 +136,8 @@ data NodeNgramsUpdate = NodeNgramsUpdate
}
-- TODO wrap these updates in a transaction.
updateNodeNgrams
::
NodeNgramsUpdate
->
Cmd
err
[
Int
]
updateNodeNgrams
::
NodeNgramsUpdate
->
Cmd
err
()
updateNodeNgrams
nnu
=
do
xs
<-
updateNodeNgrams'
$
_nnu_lists_update
nnu
ys
<-
ngramsGroup
Del
$
_nnu_rem_children
nnu
zs
<-
ngramsGroup
Add
$
_nnu_add_children
nnu
pure
$
xs
<>
ys
<>
zs
updateNodeNgrams'
$
_nnu_lists_update
nnu
ngramsGroup
Del
$
_nnu_rem_children
nnu
ngramsGroup
Add
$
_nnu_add_children
nnu
src/Gargantext/Database/Schema/NodeNgramsNgrams.hs
View file @
6cacf848
...
...
@@ -34,13 +34,14 @@ module Gargantext.Database.Schema.NodeNgramsNgrams
import
Control.Lens
(
view
)
import
Control.Lens.TH
(
makeLensesWith
,
abbreviatedFields
)
import
Control.Monad
(
void
)
import
Control.Monad.IO.Class
(
liftIO
)
import
Data.Text
(
Text
)
import
Data.Maybe
(
Maybe
)
import
Data.Profunctor.Product.TH
(
makeAdaptorAndInstance
)
import
Database.PostgreSQL.Simple.SqlQQ
(
sql
)
import
Database.PostgreSQL.Simple.Types
(
Values
(
..
),
QualifiedIdentifier
(
..
))
import
Gargantext.Database.Utils
(
Cmd
,
runOpaQuery
,
run
PGSQuery
,
connection
)
import
Gargantext.Database.Utils
(
Cmd
,
runOpaQuery
,
exec
PGSQuery
,
connection
)
import
Gargantext.Core.Types.Main
(
ListId
)
import
Gargantext.Prelude
import
Opaleye
...
...
@@ -126,8 +127,8 @@ type NgramsChild = Text
ngramsGroup
::
Action
->
[(
ListId
,
NgramsParent
,
NgramsChild
,
Maybe
Double
)]
->
Cmd
err
[
Int
]
ngramsGroup
_
[]
=
pure
[]
->
Cmd
err
()
ngramsGroup
_
[]
=
pure
()
ngramsGroup
action
ngs
=
runNodeNgramsNgrams
q
ngs
where
q
=
case
action
of
...
...
@@ -135,12 +136,12 @@ ngramsGroup action ngs = runNodeNgramsNgrams q ngs
Add
->
queryInsertNodeNgramsNgrams
runNodeNgramsNgrams
::
PGS
.
Query
->
[(
ListId
,
NgramsParent
,
NgramsChild
,
Maybe
Double
)]
->
Cmd
err
[
Int
]
runNodeNgramsNgrams
q
ngs
=
map
(
\
(
PGS
.
Only
a
)
->
a
)
<$>
runPGSQuery
q
(
PGS
.
Only
$
Values
fields
ngs'
)
runNodeNgramsNgrams
::
PGS
.
Query
->
[(
ListId
,
NgramsParent
,
NgramsChild
,
Maybe
Double
)]
->
Cmd
err
()
runNodeNgramsNgrams
q
ngs
=
void
$
execPGSQuery
q
(
PGS
.
Only
$
Values
fields
ngs'
)
where
ngs'
=
map
(
\
(
n
,
ng1
,
ng2
,
w
)
->
(
n
,
ng1
,
ng2
,
maybe
0
identity
w
))
ngs
fields
=
map
(
\
t
->
QualifiedIdentifier
Nothing
t
)
[
"int4"
,
"text"
,
"text"
,
"
real
"
]
[
"int4"
,
"text"
,
"text"
,
"
float8
"
]
--------------------------------------------------------------------
-- TODO: on conflict update weight
...
...
src/Gargantext/Database/Utils.hs
View file @
6cacf848
...
...
@@ -91,6 +91,9 @@ formatPGSQuery q a = mkCmd $ \conn -> PGS.formatQuery conn q a
runPGSQuery
::
(
PGS
.
ToRow
a
,
PGS
.
FromRow
b
)
=>
PGS
.
Query
->
a
->
Cmd
err
[
b
]
runPGSQuery
q
a
=
mkCmd
$
\
conn
->
PGS
.
query
conn
q
a
execPGSQuery
::
PGS
.
ToRow
a
=>
PGS
.
Query
->
a
->
Cmd
err
Int64
execPGSQuery
q
a
=
mkCmd
$
\
conn
->
PGS
.
execute
conn
q
a
------------------------------------------------------------------------
databaseParameters
::
FilePath
->
IO
PGS
.
ConnectInfo
...
...
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