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
158
Issues
158
List
Board
Labels
Milestones
Merge Requests
11
Merge Requests
11
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
1bc86c43
Commit
1bc86c43
authored
Feb 16, 2021
by
Przemyslaw Kaminski
Committed by
Alexandre Delanoë
Mar 09, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[ngrams] add score update endpoint + sorting
parent
285bb18d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
8 deletions
+62
-8
Node.hs
src/Gargantext/API/Node.hs
+23
-0
Table.hs
src/Gargantext/API/Table.hs
+2
-2
Facet.hs
src/Gargantext/Database/Query/Facet.hs
+10
-5
NodeNode.hs
src/Gargantext/Database/Query/Table/NodeNode.hs
+27
-1
No files found.
src/Gargantext/API/Node.hs
View file @
1bc86c43
...
...
@@ -133,6 +133,7 @@ type NodeAPI a = Get '[JSON] (Node a)
:<|>
"ngrams"
:>
TableNgramsApi
:<|>
"category"
:>
CatApi
:<|>
"score"
:>
ScoreApi
:<|>
"search"
:>
(
Search
.
API
Search
.
SearchResult
)
:<|>
"share"
:>
Share
.
API
...
...
@@ -212,6 +213,7 @@ nodeAPI p uId id' = withAccess (Proxy :: Proxy (NodeAPI a)) Proxy uId (PathNode
:<|>
apiNgramsTableCorpus
id'
:<|>
catApi
id'
:<|>
scoreApi
id'
:<|>
Search
.
api
id'
:<|>
Share
.
api
(
RootId
$
NodeId
uId
)
id'
-- Pairing Tools
...
...
@@ -260,6 +262,27 @@ catApi = putCat
putCat
::
CorpusId
->
NodesToCategory
->
Cmd
err
[
Int
]
putCat
cId
cs'
=
nodeNodesCategory
$
map
(
\
n
->
(
cId
,
n
,
ntc_category
cs'
))
(
ntc_nodesId
cs'
)
------------------------------------------------------------------------
type
ScoreApi
=
Summary
" To Score NodeNodes"
:>
ReqBody
'[
J
SON
]
NodesToScore
:>
Put
'[
J
SON
]
[
Int
]
data
NodesToScore
=
NodesToScore
{
nts_nodesId
::
[
NodeId
]
,
nts_score
::
Int
}
deriving
(
Generic
)
-- TODO unPrefix "ntc_" FromJSON, ToJSON, ToSchema, adapt frontend.
instance
FromJSON
NodesToScore
instance
ToJSON
NodesToScore
instance
ToSchema
NodesToScore
scoreApi
::
CorpusId
->
GargServer
ScoreApi
scoreApi
=
putScore
where
putScore
::
CorpusId
->
NodesToScore
->
Cmd
err
[
Int
]
putScore
cId
cs'
=
nodeNodesScore
$
map
(
\
n
->
(
cId
,
n
,
nts_score
cs'
))
(
nts_nodesId
cs'
)
------------------------------------------------------------------------
-- TODO adapt FacetDoc -> ListDoc (and add type of document as column)
-- Pairing utilities to move elsewhere
...
...
src/Gargantext/API/Table.hs
View file @
1bc86c43
...
...
@@ -45,11 +45,11 @@ import Gargantext.API.Ngrams.Types (TabType(..))
import
Gargantext.API.Prelude
(
GargServer
)
import
Gargantext.Core.Types
(
Offset
,
Limit
,
TableResult
(
..
))
import
Gargantext.Core.Utils.Prefix
(
unPrefix
,
unPrefixSwagger
)
import
Gargantext.Database.Query.Facet
(
FacetDoc
,
runViewDocuments
,
runCountDocuments
,
OrderBy
(
..
),
runViewAuthorsDoc
)
import
Gargantext.Database.Action.Learn
(
FavOrTrash
(
..
),
moreLike
)
import
Gargantext.Database.Action.Search
import
Gargantext.Database.Admin.Types.Node
import
Gargantext.Database.Prelude
-- (Cmd, CmdM)
import
Gargantext.Database.Query.Facet
(
FacetDoc
,
runViewDocuments
,
runCountDocuments
,
OrderBy
(
..
),
runViewAuthorsDoc
)
import
Gargantext.Prelude
------------------------------------------------------------------------
...
...
@@ -75,7 +75,7 @@ data TableQuery = TableQuery
,
tq_limit
::
Int
,
tq_orderBy
::
OrderBy
,
tq_view
::
TabType
,
tq_query
::
Text
,
tq_query
::
Text
}
deriving
(
Generic
)
type
FacetTableResult
=
TableResult
FacetDoc
...
...
src/Gargantext/Database/Query/Facet.hs
View file @
1bc86c43
...
...
@@ -24,6 +24,10 @@ module Gargantext.Database.Query.Facet
,
runCountDocuments
,
filterWith
,
Category
,
Score
,
Title
,
Pair
(
..
)
,
Facet
(
..
)
,
FacetDoc
...
...
@@ -73,10 +77,11 @@ import Gargantext.Database.Schema.Node
--instance ToJSON Facet
type
Category
=
Int
type
Score
=
Double
type
Title
=
Text
-- TODO remove Title
type
FacetDoc
=
Facet
NodeId
UTCTime
Title
HyperdataDocument
(
Maybe
Category
)
(
Maybe
Double
)
(
Maybe
Doubl
e
)
type
FacetDoc
=
Facet
NodeId
UTCTime
Title
HyperdataDocument
(
Maybe
Category
)
(
Maybe
Double
)
(
Maybe
Scor
e
)
-- type FacetSources = FacetDoc
-- type FacetAuthors = FacetDoc
-- type FacetTerms = FacetDoc
...
...
@@ -346,17 +351,17 @@ filterWith :: (PGOrd date, PGOrd title, PGOrd category, PGOrd score, hyperdata ~
filterWith
o
l
order
q
=
limit'
l
$
offset'
o
$
orderBy
(
orderWith
order
)
q
orderWith
::
(
PGOrd
b1
,
PGOrd
b2
,
PGOrd
b3
)
orderWith
::
(
PGOrd
b1
,
PGOrd
b2
,
PGOrd
b3
,
PGOrd
b4
)
=>
Maybe
OrderBy
->
Order
(
Facet
id
(
Column
b1
)
(
Column
b2
)
(
Column
SqlJsonb
)
(
Column
b3
)
ngramCount
score
)
->
Order
(
Facet
id
(
Column
b1
)
(
Column
b2
)
(
Column
SqlJsonb
)
(
Column
b3
)
ngramCount
(
Column
b4
)
)
orderWith
(
Just
DateAsc
)
=
asc
facetDoc_created
orderWith
(
Just
DateDesc
)
=
desc
facetDoc_created
orderWith
(
Just
TitleAsc
)
=
asc
facetDoc_title
orderWith
(
Just
TitleDesc
)
=
desc
facetDoc_title
orderWith
(
Just
ScoreAsc
)
=
asc
facetDoc_
category
orderWith
(
Just
ScoreDesc
)
=
desc
facetDoc_category
orderWith
(
Just
ScoreAsc
)
=
asc
facetDoc_
score
orderWith
(
Just
ScoreDesc
)
=
desc
NullsLast
facetDoc_score
orderWith
(
Just
SourceAsc
)
=
asc
facetDoc_source
orderWith
(
Just
SourceDesc
)
=
desc
facetDoc_source
...
...
src/Gargantext/Database/Query/Table/NodeNode.hs
View file @
1bc86c43
...
...
@@ -25,6 +25,7 @@ module Gargantext.Database.Query.Table.NodeNode
,
selectDocNodes
,
selectDocs
,
nodeNodesCategory
,
nodeNodesScore
,
getNodeNode
,
insertNodeNode
,
deleteNodeNode
...
...
@@ -130,7 +131,7 @@ _nodeNodeCategory cId dId c = map (\(PGS.Only a) -> a) <$> runPGSQuery favQuery
RETURNING node2_id;
|]
nodeNodesCategory
::
[(
CorpusId
,
DocId
,
Int
)]
->
Cmd
err
[
Int
]
nodeNodesCategory
::
[(
CorpusId
,
DocId
,
Int
)]
->
Cmd
err
[
Int
]
nodeNodesCategory
inputData
=
map
(
\
(
PGS
.
Only
a
)
->
a
)
<$>
runPGSQuery
catQuery
(
PGS
.
Only
$
Values
fields
inputData
)
where
...
...
@@ -144,6 +145,31 @@ nodeNodesCategory inputData = map (\(PGS.Only a) -> a)
RETURNING nn1.node2_id
|]
------------------------------------------------------------------------
-- | Score management
_nodeNodeScore
::
CorpusId
->
DocId
->
Int
->
Cmd
err
[
Int
]
_nodeNodeScore
cId
dId
c
=
map
(
\
(
PGS
.
Only
a
)
->
a
)
<$>
runPGSQuery
scoreQuery
(
c
,
cId
,
dId
)
where
scoreQuery
::
PGS
.
Query
scoreQuery
=
[
sql
|
UPDATE nodes_nodes SET score = ?
WHERE node1_id = ? AND node2_id = ?
RETURNING node2_id;
|]
nodeNodesScore
::
[(
CorpusId
,
DocId
,
Int
)]
->
Cmd
err
[
Int
]
nodeNodesScore
inputData
=
map
(
\
(
PGS
.
Only
a
)
->
a
)
<$>
runPGSQuery
catScore
(
PGS
.
Only
$
Values
fields
inputData
)
where
fields
=
map
(
\
t
->
QualifiedIdentifier
Nothing
t
)
[
"int4"
,
"int4"
,
"int4"
]
catScore
::
PGS
.
Query
catScore
=
[
sql
|
UPDATE nodes_nodes as nn0
SET score = nn1.score
FROM (?) as nn1(node1_id, node2_id, score)
WHERE nn0.node1_id = nn1.node1_id
AND nn0.node2_id = nn1.node2_id
RETURNING nn1.node2_id
|]
------------------------------------------------------------------------
selectCountDocs
::
HasDBid
NodeType
=>
CorpusId
->
Cmd
err
Int
selectCountDocs
cId
=
runCountOpaQuery
(
queryCountDocs
cId
)
...
...
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