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
4f8fdd86
Commit
4f8fdd86
authored
Mar 26, 2015
by
PkSM3
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[UPDATE] tfidf ok
parent
bfd825b4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
10 deletions
+27
-10
functions.py
analysis/functions.py
+16
-3
urls.py
gargantext_web/urls.py
+1
-1
views_optimized.py
gargantext_web/views_optimized.py
+9
-5
views.py
scrap_pubmed/views.py
+1
-1
No files found.
analysis/functions.py
View file @
4f8fdd86
...
...
@@ -197,11 +197,11 @@ def get_cooc(request=None, corpus_id=None, cooc_id=None, type='node_link', n=150
partition
=
best_partition
(
G
)
if
type
==
"node_link"
:
for
node
in
G
.
nodes
():
try
:
#node,type(labels[node])
G
.
node
[
node
][
'
id
'
]
=
ids
[
node
]
G
.
node
[
node
][
'
pk
'
]
=
ids
[
node
]
G
.
node
[
node
][
'label'
]
=
node
# G.node[node]['pk'] = ids[str(node)]
G
.
node
[
node
][
'size'
]
=
weight
[
ids
[
node
]]
...
...
@@ -209,8 +209,21 @@ def get_cooc(request=None, corpus_id=None, cooc_id=None, type='node_link', n=150
# G.add_edge(node, "cluster " + str(partition[node]), weight=3)
except
Exception
as
error
:
print
(
"error01: "
,
error
)
data
=
json_graph
.
node_link_data
(
G
)
links
=
[]
i
=
1
for
e
in
G
.
edges_iter
():
s
=
e
[
0
]
t
=
e
[
1
]
info
=
{
"id"
:
i
,
"source"
:
ids
[
s
]
,
"target"
:
ids
[
t
]}
# print(info)
links
.
append
(
info
)
i
+=
1
# print(data)
data
[
"links"
]
=
[]
data
[
"links"
]
=
links
elif
type
==
"adjacency"
:
for
node
in
G
.
nodes
():
...
...
gargantext_web/urls.py
View file @
4f8fdd86
...
...
@@ -52,7 +52,7 @@ urlpatterns = patterns('',
url
(
r'^corpus/(\d+)/node_link.json$'
,
views
.
node_link
),
# => api.analysis('type': 'node_link', 'format' : 'json')
url
(
r'^corpus/(\d+)/adjacency.json$'
,
views
.
adjacency
),
# => api.analysis('type': 'adjacency', 'format' : 'json')
url
(
r'^api/tfidf/(\d+)/(\
d+(?:,\d+)
+)$'
,
views_optimized
.
tfidf
),
url
(
r'^api/tfidf/(\d+)/(\
w
+)$'
,
views_optimized
.
tfidf
),
# url(r'^api/tfidf/(\d+)/(\w+)$', views.tfidf),
url
(
r'^api/tfidf2/(\d+)/(\w+)$'
,
views
.
tfidf2
),
...
...
gargantext_web/views_optimized.py
View file @
4f8fdd86
...
...
@@ -13,6 +13,7 @@ from node.admin import CustomForm
from
gargantext_web.db
import
*
from
gargantext_web.settings
import
DEBUG
,
MEDIA_ROOT
from
gargantext_web.api
import
JsonHttpResponse
import
json
from
parsing.corpustools
import
add_resource
,
parse_resources
,
extract_ngrams
,
compute_tfidf
...
...
@@ -163,12 +164,15 @@ def project(request, project_id):
'number'
:
corpora_count
,
})
def
tfidf
(
request
,
corpus_id
,
ngram_ids
,
limit
=
6
):
def
tfidf
(
request
,
corpus_id
,
ngram_ids
):
"""Takes IDs of corpus and ngram and returns list of relevent documents in json format
according to TFIDF score (order is decreasing).
"""
limit
=
6
nodes_list
=
[]
# filter input
ngram_ids
=
ngram_ids
.
split
(
','
)
ngram_ids
=
ngram_ids
.
split
(
'a'
)
ngram_ids
=
[
int
(
i
)
for
i
in
ngram_ids
]
# request data
nodes_query
=
(
session
.
query
(
Node
,
func
.
sum
(
NodeNodeNgram
.
score
))
...
...
@@ -180,7 +184,6 @@ def tfidf(request, corpus_id, ngram_ids, limit=6):
.
limit
(
limit
)
)
# convert query result to a list of dicts
nodes_list
=
[]
for
node
,
score
in
nodes_query
:
node_dict
=
{
'id'
:
node
.
id
,
...
...
@@ -190,5 +193,6 @@ def tfidf(request, corpus_id, ngram_ids, limit=6):
if
key
in
node
.
metadata
:
node_dict
[
key
]
=
node
.
metadata
[
key
]
nodes_list
.
append
(
node_dict
)
# return the result
return
JsonHttpResponse
(
nodes_list
)
data
=
json
.
dumps
(
nodes_list
)
return
JsonHttpResponse
(
data
)
scrap_pubmed/views.py
View file @
4f8fdd86
...
...
@@ -40,7 +40,7 @@ def getGlobalStats(request ):
alist
=
[
"bar"
,
"foo"
]
if
request
.
method
==
"POST"
:
N
=
10
00
N
=
10
query
=
request
.
POST
[
"query"
]
print
(
"LOG::TIME:_ "
+
datetime
.
datetime
.
now
()
.
isoformat
()
+
" query ="
,
query
)
print
(
"LOG::TIME:_ "
+
datetime
.
datetime
.
now
()
.
isoformat
()
+
" N ="
,
N
)
...
...
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