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
199
Issues
199
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
e38551b0
Unverified
Commit
e38551b0
authored
Dec 10, 2018
by
Nicolas Pouillard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a basic support for limit and offset to getNgramsTableData
parent
7408a02c
Pipeline
#53
failed with stage
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
17 deletions
+29
-17
Ngrams.hs
src/Gargantext/API/Ngrams.hs
+15
-4
Node.hs
src/Gargantext/API/Node.hs
+2
-5
Ngrams.hs
src/Gargantext/Database/Schema/Ngrams.hs
+12
-8
No files found.
src/Gargantext/API/Ngrams.hs
View file @
e38551b0
...
@@ -45,6 +45,7 @@ import qualified Data.Set as Set
...
@@ -45,6 +45,7 @@ import qualified Data.Set as Set
--import qualified Data.Map.Strict as DM
--import qualified Data.Map.Strict as DM
--import qualified Data.Set as Set
--import qualified Data.Set as Set
import
Control.Lens
((
.~
))
import
Control.Lens
((
.~
))
import
Control.Monad.IO.Class
(
MonadIO
,
liftIO
)
import
Data.Aeson
import
Data.Aeson
import
Data.Aeson.TH
(
deriveJSON
)
import
Data.Aeson.TH
(
deriveJSON
)
import
Data.Either
(
Either
(
Left
))
import
Data.Either
(
Either
(
Left
))
...
@@ -60,7 +61,7 @@ import Gargantext.Database.Types.Node (NodeType(..))
...
@@ -60,7 +61,7 @@ import Gargantext.Database.Types.Node (NodeType(..))
import
Gargantext.Database.Schema.Node
(
defaultList
)
import
Gargantext.Database.Schema.Node
(
defaultList
)
import
qualified
Gargantext.Database.Schema.Ngrams
as
Ngrams
import
qualified
Gargantext.Database.Schema.Ngrams
as
Ngrams
import
Gargantext.Prelude
import
Gargantext.Prelude
import
Gargantext.Core.Types
(
ListType
(
..
),
ListId
,
CorpusId
)
import
Gargantext.Core.Types
(
ListType
(
..
),
ListId
,
CorpusId
,
Limit
,
Offset
)
import
Prelude
(
Enum
,
Bounded
,
minBound
,
maxBound
)
import
Prelude
(
Enum
,
Bounded
,
minBound
,
maxBound
)
import
Servant
hiding
(
Patch
)
import
Servant
hiding
(
Patch
)
import
Test.QuickCheck
(
elements
)
import
Test.QuickCheck
(
elements
)
...
@@ -239,6 +240,8 @@ ngramsIdPatch = fromList $ catMaybes $ reverse [ replace (1::NgramsId) (Just $ n
...
@@ -239,6 +240,8 @@ ngramsIdPatch = fromList $ catMaybes $ reverse [ replace (1::NgramsId) (Just $ n
type
TableNgramsApiGet
=
Summary
" Table Ngrams API Get"
type
TableNgramsApiGet
=
Summary
" Table Ngrams API Get"
:>
QueryParam
"ngramsType"
TabType
:>
QueryParam
"ngramsType"
TabType
:>
QueryParam
"list"
ListId
:>
QueryParam
"list"
ListId
:>
QueryParam
"limit"
Limit
:>
QueryParam
"offset"
Offset
:>
Get
'[
J
SON
]
NgramsTable
:>
Get
'[
J
SON
]
NgramsTable
type
TableNgramsApi
=
Summary
" Table Ngrams API Change"
type
TableNgramsApi
=
Summary
" Table Ngrams API Change"
...
@@ -283,8 +286,11 @@ tableNgramsPatch conn corpusId maybeList patchs = do
...
@@ -283,8 +286,11 @@ tableNgramsPatch conn corpusId maybeList patchs = do
-- | TODO Errors management
-- | TODO Errors management
-- TODO: polymorphic for Annuaire or Corpus or ...
-- TODO: polymorphic for Annuaire or Corpus or ...
getTableNgrams
::
Connection
->
CorpusId
->
Maybe
TabType
->
Maybe
ListId
->
IO
NgramsTable
getTableNgrams
::
MonadIO
m
getTableNgrams
c
cId
maybeTabType
maybeListId
=
do
=>
Connection
->
CorpusId
->
Maybe
TabType
->
Maybe
ListId
->
Maybe
Limit
->
Maybe
Offset
->
m
NgramsTable
getTableNgrams
c
cId
maybeTabType
maybeListId
mlimit
moffset
=
liftIO
$
do
let
lieu
=
"Garg.API.Ngrams: "
::
Text
let
lieu
=
"Garg.API.Ngrams: "
::
Text
let
ngramsType
=
case
maybeTabType
of
let
ngramsType
=
case
maybeTabType
of
Nothing
->
Ngrams
.
Sources
-- panic (lieu <> "Indicate the Table")
Nothing
->
Ngrams
.
Sources
-- panic (lieu <> "Indicate the Table")
...
@@ -299,8 +305,13 @@ getTableNgrams c cId maybeTabType maybeListId = do
...
@@ -299,8 +305,13 @@ getTableNgrams c cId maybeTabType maybeListId = do
Nothing
->
defaultList
c
cId
Nothing
->
defaultList
c
cId
Just
lId
->
pure
lId
Just
lId
->
pure
lId
let
defaultLimit
=
10
-- TODO
limit_
=
maybe
defaultLimit
identity
mlimit
offset_
=
maybe
0
identity
moffset
(
ngramsTableDatas
,
mapToParent
,
mapToChildren
)
<-
(
ngramsTableDatas
,
mapToParent
,
mapToChildren
)
<-
Ngrams
.
getNgramsTableDb
c
NodeDocument
ngramsType
(
Ngrams
.
NgramsTableParam
listId
cId
)
Ngrams
.
getNgramsTableDb
c
NodeDocument
ngramsType
(
Ngrams
.
NgramsTableParam
listId
cId
)
limit_
offset_
-- printDebug "ngramsTableDatas" ngramsTableDatas
-- printDebug "ngramsTableDatas" ngramsTableDatas
...
...
src/Gargantext/API/Node.hs
View file @
e38551b0
...
@@ -48,7 +48,7 @@ import Database.PostgreSQL.Simple (Connection)
...
@@ -48,7 +48,7 @@ import Database.PostgreSQL.Simple (Connection)
import
GHC.Generics
(
Generic
)
import
GHC.Generics
(
Generic
)
import
Servant
import
Servant
import
Gargantext.API.Ngrams
(
TabType
(
..
),
TableNgramsApi
,
TableNgramsApiGet
,
tableNgramsPatch
,
getTableNgrams
,
NgramsIdPatchsFeed
,
NgramsIdPatchsBack
,
NgramsTable
)
import
Gargantext.API.Ngrams
(
TabType
(
..
),
TableNgramsApi
,
TableNgramsApiGet
,
tableNgramsPatch
,
getTableNgrams
,
NgramsIdPatchsFeed
,
NgramsIdPatchsBack
)
import
Gargantext.Prelude
import
Gargantext.Prelude
import
Gargantext.Database.Types.Node
import
Gargantext.Database.Types.Node
import
Gargantext.Database.Utils
(
runCmd
)
import
Gargantext.Database.Utils
(
runCmd
)
...
@@ -141,7 +141,7 @@ nodeAPI conn p id
...
@@ -141,7 +141,7 @@ nodeAPI conn p id
-- TODO gather it
-- TODO gather it
:<|>
getTable
conn
id
:<|>
getTable
conn
id
:<|>
tableNgramsPatch'
conn
id
:<|>
tableNgramsPatch'
conn
id
:<|>
getTableNgrams
'
conn
id
:<|>
getTableNgrams
conn
id
:<|>
getPairing
conn
id
:<|>
getPairing
conn
id
:<|>
getChart
conn
id
:<|>
getChart
conn
id
...
@@ -309,9 +309,6 @@ getChildren' conn pId p nodeType offset limit = liftIO (getChildren conn pId p
...
@@ -309,9 +309,6 @@ getChildren' conn pId p nodeType offset limit = liftIO (getChildren conn pId p
tableNgramsPatch'
::
Connection
->
CorpusId
->
Maybe
ListId
->
NgramsIdPatchsFeed
->
Handler
NgramsIdPatchsBack
tableNgramsPatch'
::
Connection
->
CorpusId
->
Maybe
ListId
->
NgramsIdPatchsFeed
->
Handler
NgramsIdPatchsBack
tableNgramsPatch'
c
cId
mL
ns
=
liftIO
$
tableNgramsPatch
c
cId
mL
ns
tableNgramsPatch'
c
cId
mL
ns
=
liftIO
$
tableNgramsPatch
c
cId
mL
ns
getTableNgrams'
::
Connection
->
CorpusId
->
Maybe
TabType
->
Maybe
ListId
->
Handler
NgramsTable
getTableNgrams'
c
cId
nType
mL
=
liftIO
$
getTableNgrams
c
cId
nType
mL
query
::
Text
->
Handler
Text
query
::
Text
->
Handler
Text
query
s
=
pure
s
query
s
=
pure
s
...
...
src/Gargantext/Database/Schema/Ngrams.hs
View file @
e38551b0
...
@@ -24,13 +24,13 @@ Ngrams connection to the Database.
...
@@ -24,13 +24,13 @@ Ngrams connection to the Database.
module
Gargantext.Database.Schema.Ngrams
where
module
Gargantext.Database.Schema.Ngrams
where
import
Control.Lens
(
makeLenses
,
view
,
_Just
,
traverse
)
import
Control.Lens
(
makeLenses
,
view
)
import
Data.ByteString.Internal
(
ByteString
)
import
Data.ByteString.Internal
(
ByteString
)
import
Data.Map
(
Map
,
fromList
,
lookup
,
fromListWith
)
import
Data.Map
(
Map
,
fromList
,
lookup
,
fromListWith
)
import
Data.Profunctor.Product.TH
(
makeAdaptorAndInstance
)
import
Data.Profunctor.Product.TH
(
makeAdaptorAndInstance
)
import
Data.Set
(
Set
)
import
Data.Set
(
Set
)
import
Data.Text
(
Text
,
splitOn
)
import
Data.Text
(
Text
,
splitOn
)
import
Database.PostgreSQL.Simple
as
DPS
(
Connection
)
import
Database.PostgreSQL.Simple
((
:.
)(
..
)
)
import
Database.PostgreSQL.Simple.FromRow
(
fromRow
,
field
)
import
Database.PostgreSQL.Simple.FromRow
(
fromRow
,
field
)
import
Database.PostgreSQL.Simple.SqlQQ
(
sql
)
import
Database.PostgreSQL.Simple.SqlQQ
(
sql
)
import
Database.PostgreSQL.Simple.ToField
(
toField
)
import
Database.PostgreSQL.Simple.ToField
(
toField
)
...
@@ -38,7 +38,6 @@ import Database.PostgreSQL.Simple.ToRow (toRow)
...
@@ -38,7 +38,6 @@ import Database.PostgreSQL.Simple.ToRow (toRow)
import
Database.PostgreSQL.Simple.Types
(
Values
(
..
),
QualifiedIdentifier
(
..
))
import
Database.PostgreSQL.Simple.Types
(
Values
(
..
),
QualifiedIdentifier
(
..
))
import
Debug.Trace
(
trace
)
import
Debug.Trace
(
trace
)
import
GHC.Generics
(
Generic
)
import
GHC.Generics
(
Generic
)
import
Gargantext.Core.Types
(
CorpusId
)
import
Gargantext.Core.Types
-- (fromListTypeId, ListType, NodePoly(Node))
import
Gargantext.Core.Types
-- (fromListTypeId, ListType, NodePoly(Node))
import
Gargantext.Database.Config
(
nodeTypeId
,
userMaster
)
import
Gargantext.Database.Config
(
nodeTypeId
,
userMaster
)
import
Gargantext.Database.Root
(
getRoot
)
import
Gargantext.Database.Root
(
getRoot
)
...
@@ -201,8 +200,9 @@ queryInsertNgrams = [sql|
...
@@ -201,8 +200,9 @@ queryInsertNgrams = [sql|
getNgramsTableDb
::
DPS
.
Connection
getNgramsTableDb
::
DPS
.
Connection
->
NodeType
->
NgramsType
->
NodeType
->
NgramsType
->
NgramsTableParamUser
->
NgramsTableParamUser
->
Limit
->
Offset
->
IO
([
NgramsTableData
],
MapToParent
,
MapToChildren
)
->
IO
([
NgramsTableData
],
MapToParent
,
MapToChildren
)
getNgramsTableDb
c
nt
ngrt
ntp
@
(
NgramsTableParam
listIdUser
_
)
=
do
getNgramsTableDb
c
nt
ngrt
ntp
@
(
NgramsTableParam
listIdUser
_
)
limit_
offset_
=
do
maybeRoot
<-
head
<$>
getRoot
userMaster
c
maybeRoot
<-
head
<$>
getRoot
userMaster
c
...
@@ -214,7 +214,7 @@ getNgramsTableDb c nt ngrt ntp@(NgramsTableParam listIdUser _) = do
...
@@ -214,7 +214,7 @@ getNgramsTableDb c nt ngrt ntp@(NgramsTableParam listIdUser _) = do
listMasterId
<-
maybe
(
panic
"error master list"
)
(
view
node_id
)
<$>
head
<$>
getListsWithParentId
c
corpusMasterId
listMasterId
<-
maybe
(
panic
"error master list"
)
(
view
node_id
)
<$>
head
<$>
getListsWithParentId
c
corpusMasterId
ngramsTableData
<-
getNgramsTableData
c
nt
ngrt
ntp
(
NgramsTableParam
listMasterId
corpusMasterId
)
ngramsTableData
<-
getNgramsTableData
c
nt
ngrt
ntp
(
NgramsTableParam
listMasterId
corpusMasterId
)
limit_
offset_
(
mapToParent
,
mapToChildren
)
<-
getNgramsGroup
c
listIdUser
listMasterId
(
mapToParent
,
mapToChildren
)
<-
getNgramsGroup
c
listIdUser
listMasterId
pure
(
ngramsTableData
,
mapToParent
,
mapToChildren
)
pure
(
ngramsTableData
,
mapToParent
,
mapToChildren
)
...
@@ -237,15 +237,17 @@ data NgramsTableData = NgramsTableData { _ntd_ngrams :: Text
...
@@ -237,15 +237,17 @@ data NgramsTableData = NgramsTableData { _ntd_ngrams :: Text
getNgramsTableData
::
DPS
.
Connection
getNgramsTableData
::
DPS
.
Connection
->
NodeType
->
NgramsType
->
NodeType
->
NgramsType
->
NgramsTableParamUser
->
NgramsTableParamMaster
->
NgramsTableParamUser
->
NgramsTableParamMaster
->
Limit
->
Offset
->
IO
[
NgramsTableData
]
->
IO
[
NgramsTableData
]
getNgramsTableData
conn
nodeT
ngrmT
(
NgramsTableParam
ul
uc
)
(
NgramsTableParam
ml
mc
)
=
getNgramsTableData
conn
nodeT
ngrmT
(
NgramsTableParam
ul
uc
)
(
NgramsTableParam
ml
mc
)
limit_
offset_
=
trace
(
"Ngrams table params"
<>
show
params
)
<$>
trace
(
"Ngrams table params"
<>
show
params
)
<$>
map
(
\
(
t
,
n
,
nt
,
w
)
->
NgramsTableData
t
n
(
fromListTypeId
nt
)
w
)
<$>
map
(
\
(
t
,
n
,
nt
,
w
)
->
NgramsTableData
t
n
(
fromListTypeId
nt
)
w
)
<$>
DPS
.
query
conn
querySelectTableNgrams
params
DPS
.
query
conn
querySelectTableNgrams
params
where
where
nodeTId
=
nodeTypeId
nodeT
nodeTId
=
nodeTypeId
nodeT
ngrmTId
=
ngramsTypeId
ngrmT
ngrmTId
=
ngramsTypeId
ngrmT
params
=
(
ul
,
uc
,
nodeTId
,
ngrmTId
,
ml
,
mc
,
nodeTId
,
ngrmTId
,
uc
)
params
=
(
ul
,
uc
,
nodeTId
,
ngrmTId
,
ml
,
mc
,
nodeTId
,
ngrmTId
,
uc
)
:.
(
limit_
,
offset_
)
...
@@ -282,7 +284,9 @@ querySelectTableNgrams = [sql|
...
@@ -282,7 +284,9 @@ querySelectTableNgrams = [sql|
, COALESCE(tu.ngrams_type,tm.ngrams_type) AS ngrams_type
, COALESCE(tu.ngrams_type,tm.ngrams_type) AS ngrams_type
, SUM(COALESCE(tu.weight,tm.weight)) AS weight
, SUM(COALESCE(tu.weight,tm.weight)) AS weight
FROM tableUser tu RIGHT JOIN tableMaster tm ON tu.terms = tm.terms
FROM tableUser tu RIGHT JOIN tableMaster tm ON tu.terms = tm.terms
GROUP BY tu.terms,tm.terms,tu.n,tm.n,tu.ngrams_type,tm.ngrams_type;
GROUP BY tu.terms,tm.terms,tu.n,tm.n,tu.ngrams_type,tm.ngrams_type
LIMIT ?
OFFSET ?;
|]
|]
...
...
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