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
f954b076
Commit
f954b076
authored
Dec 18, 2014
by
PkSM3
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[UPDATE] clean results for tfidf query
parent
36b23a48
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
34 deletions
+18
-34
views.py
gargantext_web/views.py
+18
-34
No files found.
gargantext_web/views.py
View file @
f954b076
...
@@ -538,50 +538,34 @@ def tfidf(request, corpus_id, ngram_id):
...
@@ -538,50 +538,34 @@ def tfidf(request, corpus_id, ngram_id):
corpus
=
Node
.
objects
.
get
(
id
=
corpus_id
)
corpus
=
Node
.
objects
.
get
(
id
=
corpus_id
)
ngram
=
Ngram
.
objects
.
get
(
id
=
ngramsids
[
0
])
#not used
ngram
=
Ngram
.
objects
.
get
(
id
=
ngramsids
[
0
])
#not used
print
(
"********
-1 01
*******"
)
print
(
"********
web/views.tfidf
*******"
)
print
(
"first ngram:"
)
print
(
"first ngram:"
)
print
(
ngram
)
print
(
ngram
)
node_node_ngrams
=
NodeNodeNgram
.
objects
.
filter
(
nodex
=
corpus
,
ngram__in
=
ngramsids
)
.
order_by
(
'-score'
)
node_node_ngrams
=
NodeNodeNgram
.
objects
.
filter
(
nodex
=
corpus
,
ngram__in
=
ngramsids
)
.
order_by
(
'-score'
)
# print(node_node_ngrams)
# print(node_node_ngrams)
goodDict
=
{}
goodDict
=
{}
for
x
in
node_node_ngrams
:
for
x
in
node_node_ngrams
:
# print(x.nodey)
# print("\t",x.nodey.id)
# print
goodDict
[
x
.
nodey
.
id
]
=
x
.
nodey
goodDict
[
x
.
nodey
.
id
]
=
x
.
nodey
print
(
"imma here"
)
#
print("imma here")
print
(
"arguments... nodes ids:"
)
#
print("arguments... nodes ids:")
print
(
ngramsids
)
#
print(ngramsids)
print
(
"with tfidf:"
)
#
print ("with tfidf:")
print
(
node_node_ngrams
)
#
print(node_node_ngrams)
print
(
"corpus:"
)
#
print("corpus:")
print
(
NodeNodeNgram
.
objects
.
filter
(
nodex
=
corpus
))
#
print(NodeNodeNgram.objects.filter(nodex=corpus))
tfidf_list
=
[]
tfidf_list
=
[]
for
x
in
goodDict
:
for
x
in
goodDict
:
print
(
goodDict
[
x
]
.
metadata
.
keys
())
pub
=
goodDict
[
x
]
# getting the unique publication
print
finalpub
=
{}
pub
=
{
"id"
:
goodDict
[
x
]
.
id
,
if
"title"
in
pub
.
metadata
:
finalpub
[
"title"
]
=
pub
.
metadata
[
'title'
]
"title"
:
goodDict
[
x
]
.
metadata
[
'title'
],
if
"publication_date"
in
pub
.
metadata
:
finalpub
[
"publication_date"
]
=
pub
.
metadata
[
'publication_date'
]
"publication_date"
:
goodDict
[
x
]
.
metadata
[
'publication_date'
],
if
"journal"
in
pub
.
metadata
:
finalpub
[
"journal"
]
=
pub
.
metadata
[
'journal'
]
"journal"
:
goodDict
[
x
]
.
metadata
[
'journal'
]
if
"authors"
in
pub
.
metadata
:
finalpub
[
"authors"
]
=
pub
.
metadata
[
'authors'
]
}
if
"fields"
in
pub
.
metadata
:
finalpub
[
"fields"
]
=
pub
.
metadata
[
'fields'
]
# tel = {'id': goodDict[x].id, "title":goodDict[x].metadata['title'], 'sape': 4139}
tfidf_list
.
append
(
finalpub
)
# doing a dictionary with only available atributes
# print(elem)
if
len
(
tfidf_list
)
==
6
:
break
# max 6 papers
tfidf_list
.
append
(
pub
)
print
(
"********-1 02*******"
)
data
=
json
.
dumps
(
tfidf_list
)
# only for tests
# TODO add test if metadata present
# tfidf_list = [ dict(
# id=x.nodey.id,
# title=x.nodey.metadata['title'],
# publication_date=x.nodey.metadata['publication_date'],
# journal=x.nodey.metadata['journal'],
# #abstract=x.nodey.metadata['abstract'],
# )
# for x in node_node_ngrams]
data
=
json
.
dumps
(
tfidf_list
[:
6
])
# max 6 papers
return
JsonHttpResponse
(
data
)
return
JsonHttpResponse
(
data
)
...
...
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