Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
humanities
gargantext
Commits
8079ad7b
Commit
8079ad7b
authored
Sep 13, 2016
by
Romain Loth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
api: add total count of publications in tfidf relevancy view (for graphexplorer)
parent
309a940e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
21 deletions
+16
-21
nodes.py
gargantext/views/api/nodes.py
+16
-21
No files found.
gargantext/views/api/nodes.py
View file @
8079ad7b
...
@@ -144,7 +144,7 @@ class NodeListHaving(APIView):
...
@@ -144,7 +144,7 @@ class NodeListHaving(APIView):
Takes IDs of corpus and ngram and returns list of relevent documents in json format
Takes IDs of corpus and ngram and returns list of relevent documents in json format
according to TFIDF score (order is decreasing).
according to TFIDF score (order is decreasing).
2016-09: add total counts to output json
'''
'''
def
get
(
self
,
request
,
corpus_id
):
def
get
(
self
,
request
,
corpus_id
):
parameters
=
get_parameters
(
request
)
parameters
=
get_parameters
(
request
)
...
@@ -178,26 +178,18 @@ class NodeListHaving(APIView):
...
@@ -178,26 +178,18 @@ class NodeListHaving(APIView):
.
filter
(
Node
.
typename
==
'DOCUMENT'
,
Node
.
parent_id
==
corpus
.
id
)
.
filter
(
Node
.
typename
==
'DOCUMENT'
,
Node
.
parent_id
==
corpus
.
id
)
.
filter
(
or_
(
*
[
NodeNodeNgram
.
ngram_id
==
ngram_id
for
ngram_id
in
ngram_ids
]))
.
filter
(
or_
(
*
[
NodeNodeNgram
.
ngram_id
==
ngram_id
for
ngram_id
in
ngram_ids
]))
.
group_by
(
Node
)
.
group_by
(
Node
)
)
# get the total count before applying limit
nodes_count
=
nodes_query
.
count
()
# now the query with the limit
nodes_results_query
=
(
nodes_query
.
order_by
(
func
.
sum
(
NodeNodeNgram
.
score
)
.
desc
())
.
order_by
(
func
.
sum
(
NodeNodeNgram
.
score
)
.
desc
())
.
limit
(
limit
)
.
limit
(
limit
)
)
)
# print("\n")
# print("in TFIDF:")
for
node
,
score
in
nodes_results_query
:
# print("\tcorpus_id:",corpus_id)
# convert query result to a list of dicts
# if nodes_query is None:
# print("TFIDF error, juste take sums")
# nodes_query = (session
# .query(Node, func.sum(NodeNgram.weight))
# .join(NodeNgram, NodeNgram.node_id == Node.id)
# .filter(Node.parent_id == corpus_id)
# .filter(Node.typename == 'DOCUMENT')
# .filter(or_(*[NodeNgram.ngram_id==ngram_id for ngram_id in ngram_ids]))
# .group_by(Node)
# .order_by(func.sum(NodeNgram.weight).desc())
# .limit(limit)
# )
for
node
,
score
in
nodes_query
:
print
(
node
,
score
)
print
(
node
,
score
)
print
(
"
\t
corpus:"
,
corpus_id
,
"
\t
"
,
node
.
name
)
print
(
"
\t
corpus:"
,
corpus_id
,
"
\t
"
,
node
.
name
)
node_dict
=
{
node_dict
=
{
...
@@ -209,7 +201,10 @@ class NodeListHaving(APIView):
...
@@ -209,7 +201,10 @@ class NodeListHaving(APIView):
node_dict
[
key
]
=
node
.
hyperdata
[
key
]
node_dict
[
key
]
=
node
.
hyperdata
[
key
]
nodes_list
.
append
(
node_dict
)
nodes_list
.
append
(
node_dict
)
return
JsonHttpResponse
(
nodes_list
)
return
JsonHttpResponse
({
'count'
:
nodes_count
,
'records'
:
nodes_list
})
...
...
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