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
153
Issues
153
List
Board
Labels
Milestones
Merge Requests
9
Merge Requests
9
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
d669e7da
Commit
d669e7da
authored
Feb 16, 2021
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[ngrams] add score update endpoint + sorting
parent
9ba4f597
Pipeline
#1408
failed with stage
Changes
4
Pipelines
1
Show 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 @
d669e7da
...
@@ -133,6 +133,7 @@ type NodeAPI a = Get '[JSON] (Node a)
...
@@ -133,6 +133,7 @@ type NodeAPI a = Get '[JSON] (Node a)
:<|>
"ngrams"
:>
TableNgramsApi
:<|>
"ngrams"
:>
TableNgramsApi
:<|>
"category"
:>
CatApi
:<|>
"category"
:>
CatApi
:<|>
"score"
:>
ScoreApi
:<|>
"search"
:>
(
Search
.
API
Search
.
SearchResult
)
:<|>
"search"
:>
(
Search
.
API
Search
.
SearchResult
)
:<|>
"share"
:>
Share
.
API
:<|>
"share"
:>
Share
.
API
...
@@ -212,6 +213,7 @@ nodeAPI p uId id' = withAccess (Proxy :: Proxy (NodeAPI a)) Proxy uId (PathNode
...
@@ -212,6 +213,7 @@ nodeAPI p uId id' = withAccess (Proxy :: Proxy (NodeAPI a)) Proxy uId (PathNode
:<|>
apiNgramsTableCorpus
id'
:<|>
apiNgramsTableCorpus
id'
:<|>
catApi
id'
:<|>
catApi
id'
:<|>
scoreApi
id'
:<|>
Search
.
api
id'
:<|>
Search
.
api
id'
:<|>
Share
.
api
(
RootId
$
NodeId
uId
)
id'
:<|>
Share
.
api
(
RootId
$
NodeId
uId
)
id'
-- Pairing Tools
-- Pairing Tools
...
@@ -260,6 +262,27 @@ catApi = putCat
...
@@ -260,6 +262,27 @@ catApi = putCat
putCat
::
CorpusId
->
NodesToCategory
->
Cmd
err
[
Int
]
putCat
::
CorpusId
->
NodesToCategory
->
Cmd
err
[
Int
]
putCat
cId
cs'
=
nodeNodesCategory
$
map
(
\
n
->
(
cId
,
n
,
ntc_category
cs'
))
(
ntc_nodesId
cs'
)
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)
-- TODO adapt FacetDoc -> ListDoc (and add type of document as column)
-- Pairing utilities to move elsewhere
-- Pairing utilities to move elsewhere
...
...
src/Gargantext/API/Table.hs
View file @
d669e7da
...
@@ -45,11 +45,11 @@ import Gargantext.API.Ngrams.Types (TabType(..))
...
@@ -45,11 +45,11 @@ import Gargantext.API.Ngrams.Types (TabType(..))
import
Gargantext.API.Prelude
(
GargServer
)
import
Gargantext.API.Prelude
(
GargServer
)
import
Gargantext.Core.Types
(
Offset
,
Limit
,
TableResult
(
..
))
import
Gargantext.Core.Types
(
Offset
,
Limit
,
TableResult
(
..
))
import
Gargantext.Core.Utils.Prefix
(
unPrefix
,
unPrefixSwagger
)
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.Learn
(
FavOrTrash
(
..
),
moreLike
)
import
Gargantext.Database.Action.Search
import
Gargantext.Database.Action.Search
import
Gargantext.Database.Admin.Types.Node
import
Gargantext.Database.Admin.Types.Node
import
Gargantext.Database.Prelude
-- (Cmd, CmdM)
import
Gargantext.Database.Prelude
-- (Cmd, CmdM)
import
Gargantext.Database.Query.Facet
(
FacetDoc
,
runViewDocuments
,
runCountDocuments
,
OrderBy
(
..
),
runViewAuthorsDoc
)
import
Gargantext.Prelude
import
Gargantext.Prelude
------------------------------------------------------------------------
------------------------------------------------------------------------
...
...
src/Gargantext/Database/Query/Facet.hs
View file @
d669e7da
...
@@ -24,6 +24,10 @@ module Gargantext.Database.Query.Facet
...
@@ -24,6 +24,10 @@ module Gargantext.Database.Query.Facet
,
runCountDocuments
,
runCountDocuments
,
filterWith
,
filterWith
,
Category
,
Score
,
Title
,
Pair
(
..
)
,
Pair
(
..
)
,
Facet
(
..
)
,
Facet
(
..
)
,
FacetDoc
,
FacetDoc
...
@@ -73,10 +77,11 @@ import Gargantext.Database.Schema.Node
...
@@ -73,10 +77,11 @@ import Gargantext.Database.Schema.Node
--instance ToJSON Facet
--instance ToJSON Facet
type
Category
=
Int
type
Category
=
Int
type
Score
=
Double
type
Title
=
Text
type
Title
=
Text
-- TODO remove Title
-- 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 FacetSources = FacetDoc
-- type FacetAuthors = FacetDoc
-- type FacetAuthors = FacetDoc
-- type FacetTerms = FacetDoc
-- type FacetTerms = FacetDoc
...
@@ -346,17 +351,17 @@ filterWith :: (PGOrd date, PGOrd title, PGOrd category, PGOrd score, hyperdata ~
...
@@ -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
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
=>
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
DateAsc
)
=
asc
facetDoc_created
orderWith
(
Just
DateDesc
)
=
desc
facetDoc_created
orderWith
(
Just
DateDesc
)
=
desc
facetDoc_created
orderWith
(
Just
TitleAsc
)
=
asc
facetDoc_title
orderWith
(
Just
TitleAsc
)
=
asc
facetDoc_title
orderWith
(
Just
TitleDesc
)
=
desc
facetDoc_title
orderWith
(
Just
TitleDesc
)
=
desc
facetDoc_title
orderWith
(
Just
ScoreAsc
)
=
asc
facetDoc_
category
orderWith
(
Just
ScoreAsc
)
=
asc
facetDoc_
score
orderWith
(
Just
ScoreDesc
)
=
desc
facetDoc_category
orderWith
(
Just
ScoreDesc
)
=
desc
NullsLast
facetDoc_score
orderWith
(
Just
SourceAsc
)
=
asc
facetDoc_source
orderWith
(
Just
SourceAsc
)
=
asc
facetDoc_source
orderWith
(
Just
SourceDesc
)
=
desc
facetDoc_source
orderWith
(
Just
SourceDesc
)
=
desc
facetDoc_source
...
...
src/Gargantext/Database/Query/Table/NodeNode.hs
View file @
d669e7da
...
@@ -25,6 +25,7 @@ module Gargantext.Database.Query.Table.NodeNode
...
@@ -25,6 +25,7 @@ module Gargantext.Database.Query.Table.NodeNode
,
selectDocNodes
,
selectDocNodes
,
selectDocs
,
selectDocs
,
nodeNodesCategory
,
nodeNodesCategory
,
nodeNodesScore
,
getNodeNode
,
getNodeNode
,
insertNodeNode
,
insertNodeNode
,
deleteNodeNode
,
deleteNodeNode
...
@@ -130,7 +131,7 @@ _nodeNodeCategory cId dId c = map (\(PGS.Only a) -> a) <$> runPGSQuery favQuery
...
@@ -130,7 +131,7 @@ _nodeNodeCategory cId dId c = map (\(PGS.Only a) -> a) <$> runPGSQuery favQuery
RETURNING node2_id;
RETURNING node2_id;
|]
|]
nodeNodesCategory
::
[(
CorpusId
,
DocId
,
Int
)]
->
Cmd
err
[
Int
]
nodeNodesCategory
::
[(
CorpusId
,
DocId
,
Int
)]
->
Cmd
err
[
Int
]
nodeNodesCategory
inputData
=
map
(
\
(
PGS
.
Only
a
)
->
a
)
nodeNodesCategory
inputData
=
map
(
\
(
PGS
.
Only
a
)
->
a
)
<$>
runPGSQuery
catQuery
(
PGS
.
Only
$
Values
fields
inputData
)
<$>
runPGSQuery
catQuery
(
PGS
.
Only
$
Values
fields
inputData
)
where
where
...
@@ -144,6 +145,31 @@ nodeNodesCategory inputData = map (\(PGS.Only a) -> a)
...
@@ -144,6 +145,31 @@ nodeNodesCategory inputData = map (\(PGS.Only a) -> a)
RETURNING nn1.node2_id
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
::
HasDBid
NodeType
=>
CorpusId
->
Cmd
err
Int
selectCountDocs
cId
=
runCountOpaQuery
(
queryCountDocs
cId
)
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