Commit 02743abe authored by Administrator's avatar Administrator

Merge branch 'samuel' into unstable

parents fb804833 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():
......
......@@ -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),
......
......@@ -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
......@@ -174,12 +175,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))
......@@ -191,7 +195,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,
......@@ -201,5 +204,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)
......@@ -40,7 +40,7 @@ def getGlobalStats(request ):
alist = ["bar","foo"]
if request.method == "POST":
N = 1000
N = 10
query = request.POST["query"]
print ("LOG::TIME:_ "+datetime.datetime.now().isoformat()+" query =", query )
print ("LOG::TIME:_ "+datetime.datetime.now().isoformat()+" N =", N )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment