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
175
Issues
175
List
Board
Labels
Milestones
Merge Requests
10
Merge Requests
10
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
0ee4f4f5
Unverified
Commit
0ee4f4f5
authored
Jan 10, 2019
by
Nicolas Pouillard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[NGRAMS-TABLE] WIP add ngramsType param to PUT
parent
359dc4b5
Pipeline
#116
canceled with stage
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
17 deletions
+25
-17
Ngrams.hs
src/Gargantext/API/Ngrams.hs
+23
-15
Ngrams.hs
src/Gargantext/Database/Schema/Ngrams.hs
+2
-2
No files found.
src/Gargantext/API/Ngrams.hs
View file @
0ee4f4f5
...
...
@@ -57,6 +57,7 @@ import GHC.Generics (Generic)
import
Gargantext.Core.Utils.Prefix
(
unPrefix
)
import
Gargantext.Database.Types.Node
(
NodeType
(
..
))
import
Gargantext.Database.Schema.Node
(
defaultList
,
HasNodeError
)
import
Gargantext.Database.Schema.Ngrams
(
NgramsType
,
NgramsTypeId
,
ngramsTypeId
)
import
qualified
Gargantext.Database.Schema.Ngrams
as
Ngrams
import
Gargantext.Database.Schema.NodeNgram
import
Gargantext.Database.Schema.NodeNgramsNgrams
...
...
@@ -244,6 +245,7 @@ type TableNgramsApiGet = Summary " Table Ngrams API Get"
:>
Get
'[
J
SON
]
(
Versioned
NgramsTable
)
type
TableNgramsApi
=
Summary
" Table Ngrams API Change"
:>
QueryParam
"ngramsType"
TabType
:>
QueryParam
"list"
ListId
:>
ReqBody
'[
J
SON
]
(
Versioned
NgramsTablePatch
)
:>
Put
'[
J
SON
]
(
Versioned
NgramsTablePatch
)
...
...
@@ -268,9 +270,9 @@ ngramError nne = throwError $ _NgramError # nne
-- `GraphList` and that the patch is `Replace CandidateList StopList` then
-- the list is going to be `StopList` while it should keep `GraphList`.
-- However this should not happen in non conflicting situations.
mkListsUpdate
::
ListId
->
NgramsTablePatch
->
[(
ListId
,
NgramsTypeId
,
NgramsTerm
,
ListTypeId
)]
mkListsUpdate
lId
patches
=
[
(
lId
,
ng
,
listTypeId
lt
)
mkListsUpdate
::
ListId
->
NgramsT
ype
->
NgramsT
ablePatch
->
[(
ListId
,
NgramsTypeId
,
NgramsTerm
,
ListTypeId
)]
mkListsUpdate
lId
nt
patches
=
[
(
lId
,
ng
ramsTypeId
nt
,
ng
,
listTypeId
lt
)
|
(
ng
,
patch
)
<-
patches
^..
ntp_ngrams_patches
.
ifolded
.
withIndex
,
lt
<-
patch
^..
patch_list
.
new
]
...
...
@@ -285,20 +287,34 @@ mkChildrenGroups lId addOrRem patches =
,
child
<-
patch
^..
patch_children
.
to
addOrRem
.
folded
]
ngramsTypeFromTabType
::
Maybe
TabType
->
NgramsType
ngramsTypeFromTabType
maybeTabType
=
let
lieu
=
"Garg.API.Ngrams: "
::
Text
in
case
maybeTabType
of
Nothing
->
Ngrams
.
Sources
-- panic (lieu <> "Indicate the Table")
Just
tab
->
case
tab
of
Sources
->
Ngrams
.
Sources
Authors
->
Ngrams
.
Authors
Institutes
->
Ngrams
.
Institutes
Terms
->
Ngrams
.
NgramsTerms
_
->
panic
$
lieu
<>
"No Ngrams for this tab"
-- Apply the given patch to the DB and returns the patch to be applied on the
-- cilent.
-- TODO:
-- In this perliminary version the OT aspect is missing, therefore the version
-- number is always 1 and the returned patch is always empty.
tableNgramsPatch
::
(
HasNgramError
err
,
HasNodeError
err
)
=>
CorpusId
->
Maybe
ListId
=>
CorpusId
->
Maybe
TabType
->
Maybe
ListId
->
Versioned
NgramsTablePatch
->
Cmd
err
(
Versioned
NgramsTablePatch
)
tableNgramsPatch
corpusId
maybeList
(
Versioned
version
patch
)
=
do
tableNgramsPatch
corpusId
maybe
TabType
maybe
List
(
Versioned
version
patch
)
=
do
when
(
version
/=
1
)
$
ngramError
UnsupportedVersion
let
ngramsType
=
ngramsTypeFromTabType
maybeTabType
listId
<-
maybe
(
defaultList
corpusId
)
pure
maybeList
updateNodeNgrams
$
NodeNgramsUpdate
{
_nnu_lists_update
=
mkListsUpdate
listId
patch
{
_nnu_lists_update
=
mkListsUpdate
listId
ngramsType
patch
,
_nnu_rem_children
=
mkChildrenGroups
listId
_rem
patch
,
_nnu_add_children
=
mkChildrenGroups
listId
_add
patch
}
...
...
@@ -312,15 +328,7 @@ getTableNgrams :: HasNodeError err
->
Cmd
err
(
Versioned
NgramsTable
)
getTableNgrams
cId
maybeTabType
maybeListId
mlimit
moffset
=
do
let
lieu
=
"Garg.API.Ngrams: "
::
Text
let
ngramsType
=
case
maybeTabType
of
Nothing
->
Ngrams
.
Sources
-- panic (lieu <> "Indicate the Table")
Just
tab
->
case
tab
of
Sources
->
Ngrams
.
Sources
Authors
->
Ngrams
.
Authors
Institutes
->
Ngrams
.
Institutes
Terms
->
Ngrams
.
NgramsTerms
_
->
panic
$
lieu
<>
"No Ngrams for this tab"
let
ngramsType
=
ngramsTypeFromTabType
maybeTabType
listId
<-
maybe
(
defaultList
cId
)
pure
maybeListId
let
...
...
src/Gargantext/Database/Schema/Ngrams.hs
View file @
0ee4f4f5
...
...
@@ -109,8 +109,8 @@ instance ToField NgramsTypeId where
toField
(
NgramsTypeId
n
)
=
toField
n
instance
FromField
NgramsTypeId
where
fromField
f
ie
ld
mdata
=
do
n
<-
fromField
f
ie
ld
mdata
fromField
fld
mdata
=
do
n
<-
fromField
fld
mdata
if
(
n
::
Int
)
>
0
then
return
$
NgramsTypeId
n
else
mzero
...
...
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