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
6b6a0c8a
Commit
6b6a0c8a
authored
Dec 10, 2018
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/rest-fix'
parents
a077ef1f
e38551b0
Changes
3
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 @
6b6a0c8a
...
...
@@ -45,6 +45,7 @@ import qualified Data.Set as Set
--import qualified Data.Map.Strict as DM
--import qualified Data.Set as Set
import
Control.Lens
((
.~
))
import
Control.Monad.IO.Class
(
MonadIO
,
liftIO
)
import
Data.Aeson
import
Data.Aeson.TH
(
deriveJSON
)
import
Data.Either
(
Either
(
Left
))
...
...
@@ -60,7 +61,7 @@ import Gargantext.Database.Types.Node (NodeType(..))
import
Gargantext.Database.Schema.Node
(
defaultList
)
import
qualified
Gargantext.Database.Schema.Ngrams
as
Ngrams
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
Servant
hiding
(
Patch
)
import
Test.QuickCheck
(
elements
)
...
...
@@ -239,6 +240,8 @@ ngramsIdPatch = fromList $ catMaybes $ reverse [ replace (1::NgramsId) (Just $ n
type
TableNgramsApiGet
=
Summary
" Table Ngrams API Get"
:>
QueryParam
"ngramsType"
TabType
:>
QueryParam
"list"
ListId
:>
QueryParam
"limit"
Limit
:>
QueryParam
"offset"
Offset
:>
Get
'[
J
SON
]
NgramsTable
type
TableNgramsApi
=
Summary
" Table Ngrams API Change"
...
...
@@ -283,8 +286,11 @@ tableNgramsPatch conn corpusId maybeList patchs = do
-- | TODO Errors management
-- TODO: polymorphic for Annuaire or Corpus or ...
getTableNgrams
::
Connection
->
CorpusId
->
Maybe
TabType
->
Maybe
ListId
->
IO
NgramsTable
getTableNgrams
c
cId
maybeTabType
maybeListId
=
do
getTableNgrams
::
MonadIO
m
=>
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
ngramsType
=
case
maybeTabType
of
Nothing
->
Ngrams
.
Sources
-- panic (lieu <> "Indicate the Table")
...
...
@@ -299,8 +305,13 @@ getTableNgrams c cId maybeTabType maybeListId = do
Nothing
->
defaultList
c
cId
Just
lId
->
pure
lId
let
defaultLimit
=
10
-- TODO
limit_
=
maybe
defaultLimit
identity
mlimit
offset_
=
maybe
0
identity
moffset
(
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
...
...
src/Gargantext/API/Node.hs
View file @
6b6a0c8a
...
...
@@ -48,7 +48,7 @@ import Database.PostgreSQL.Simple (Connection)
import
GHC.Generics
(
Generic
)
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.Database.Types.Node
import
Gargantext.Database.Utils
(
runCmd
)
...
...
@@ -141,7 +141,7 @@ nodeAPI conn p id
-- TODO gather it
:<|>
getTable
conn
id
:<|>
tableNgramsPatch'
conn
id
:<|>
getTableNgrams
'
conn
id
:<|>
getTableNgrams
conn
id
:<|>
getPairing
conn
id
:<|>
getChart
conn
id
...
...
@@ -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'
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
s
=
pure
s
...
...
src/Gargantext/Database/Schema/Ngrams.hs
View file @
6b6a0c8a
...
...
@@ -24,13 +24,13 @@ Ngrams connection to the Database.
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.Map
(
Map
,
fromList
,
lookup
,
fromListWith
)
import
Data.Profunctor.Product.TH
(
makeAdaptorAndInstance
)
import
Data.Set
(
Set
)
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.SqlQQ
(
sql
)
import
Database.PostgreSQL.Simple.ToField
(
toField
)
...
...
@@ -38,7 +38,6 @@ import Database.PostgreSQL.Simple.ToRow (toRow)
import
Database.PostgreSQL.Simple.Types
(
Values
(
..
),
QualifiedIdentifier
(
..
))
import
Debug.Trace
(
trace
)
import
GHC.Generics
(
Generic
)
import
Gargantext.Core.Types
(
CorpusId
)
import
Gargantext.Core.Types
-- (fromListTypeId, ListType, NodePoly(Node))
import
Gargantext.Database.Config
(
nodeTypeId
,
userMaster
)
import
Gargantext.Database.Root
(
getRoot
)
...
...
@@ -201,8 +200,9 @@ queryInsertNgrams = [sql|
getNgramsTableDb
::
DPS
.
Connection
->
NodeType
->
NgramsType
->
NgramsTableParamUser
->
Limit
->
Offset
->
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
...
...
@@ -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
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
pure
(
ngramsTableData
,
mapToParent
,
mapToChildren
)
...
...
@@ -237,15 +237,17 @@ data NgramsTableData = NgramsTableData { _ntd_ngrams :: Text
getNgramsTableData
::
DPS
.
Connection
->
NodeType
->
NgramsType
->
NgramsTableParamUser
->
NgramsTableParamMaster
->
Limit
->
Offset
->
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
)
<$>
map
(
\
(
t
,
n
,
nt
,
w
)
->
NgramsTableData
t
n
(
fromListTypeId
nt
)
w
)
<$>
DPS
.
query
conn
querySelectTableNgrams
params
where
nodeTId
=
nodeTypeId
nodeT
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|
, COALESCE(tu.ngrams_type,tm.ngrams_type) AS ngrams_type
, SUM(COALESCE(tu.weight,tm.weight)) AS weight
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