Commit 0ef141b6 authored by Administrator's avatar Administrator

[FEATURE] Automatic maps for newbies: OK

parent 42c94068
......@@ -17,6 +17,7 @@ def create_whitelist(user, corpus):
try:
whitelist_type = NodeType.objects.get(name='WhiteList')
blacklist_type = NodeType.objects.get(name='BlackList')
type_document = NodeType.objects.get(name='Document')
except:
whitelist_type = NodeType(name='WhiteList')
whitelist_type.save()
......@@ -24,8 +25,8 @@ def create_whitelist(user, corpus):
blacklist_type = NodeType(name='BlackList')
blacklist_type.save()
white_list = Node.objects.create(name='WhiteList Corpus' + str(corpus.id), user=user, parent=corpus, type=whitelist_type)
black_list = Node.objects.create(name='BlackList Corpus' + str(corpus.id), user=user, parent=corpus, type=blacklist_type)
white_list = Node.objects.create(name='WhiteList Corpus ' + str(corpus.id), user=user, parent=corpus, type=whitelist_type)
black_list = Node.objects.create(name='BlackList Corpus ' + str(corpus.id), user=user, parent=corpus, type=blacklist_type)
# delete avant pour éviter les doublons
# try:
......@@ -61,7 +62,7 @@ def create_whitelist(user, corpus):
LIMIT
100
;
""" % (white_list.id, corpus.id, whitelist_type.id)
""" % (white_list.id, corpus.id, type_document.id)
cursor.execute(query_whitelist)
......@@ -132,3 +133,5 @@ def create_cooc(user=None, corpus=None, whitelist=None):
cursor.execute(query_cooc)
return cooc
......@@ -27,14 +27,15 @@ urlpatterns = patterns('',
url(r'^project/(\d+)/corpus/(\d+)/$', views.corpus),
url(r'^project/(\d+)/corpus/(\d+)/delete/$', views.delete_corpus),
url(r'^graph$', views.explorer_graph),
url(r'^corpus/(\d+)/explorer$', views.explorer_graph),
url(r'^chart$', views.explorer_chart),
url(r'^matrix$', views.explorer_matrix),
url(r'^exploration$', views.exploration),
#url(r'^exploration$', views.exploration),
url(r'^chart/corpus/(\d+)/data.csv$', views.send_csv),
url(r'^graph.json$', views.json_node_link),
url(r'^corpus/(\d+)/node_link.json$', views.node_link),
url(r'^corpus/(\d+)/adjancy_matrix$', views.node_link),
url(r'^api/nodes$', gargantext_web.api.NodesController.get),
url(r'^api/corpus/(\d+)/ngrams$', gargantext_web.api.CorpusController.ngrams),
......
......@@ -172,7 +172,6 @@ def project(request, project_id):
corpus_view['name'] = corpus.name
corpus_view['count'] = corpus.children.count()
for node_resource in Node_Resource.objects.filter(node=corpus):
donut_part[node_resource.resource.type] += docs_count
list_corpora[node_resource.resource.type.name].append(corpus_view)
......@@ -187,8 +186,6 @@ def project(request, project_id):
for key in donut_part.keys() ]
if request.method == 'POST':
#form = CorpusForm(request.POST, request.FILES)
#print(str(request.POST))
......@@ -379,14 +376,16 @@ def delete_corpus(request, project_id, corpus_id):
Node.objects.filter(id=corpus_id).all().delete()
return HttpResponseRedirect('/project/' + project_id)
def explorer_graph(request):
def explorer_graph(request, corpus_id):
t = get_template('explorer.html')
user = request.user
date = datetime.datetime.now()
corpus = Node.objects.get(id=corpus_id)
html = t.render(Context({\
'user': user,\
'date': date,\
'corpus': corpus,\
}))
return HttpResponse(html)
......@@ -470,7 +469,7 @@ def send_csv(request, corpus_id):
return response
def json_node_link(request):
def node_link(request, corpus_id):
'''
Create the HttpResponse object with the graph dataset.
'''
......@@ -481,11 +480,22 @@ def json_node_link(request):
import networkx as nx
from networkx.readwrite import json_graph
from gargantext_web.api import JsonHttpResponse
from analysis.louvain import best_partition
from analysis.functions import create_whitelist, create_cooc
matrix = defaultdict(lambda : defaultdict(float))
labels = dict()
cooc = Node.objects.get(id=81249)
corpus = Node.objects.get(id=corpus_id)
type_cooc = NodeType.objects.get(name="Cooccurrence")
if Node.objects.filter(type=type_cooc, parent=corpus).first() is None:
print("Coocurrences do not exist yet, create it.")
whitelist = create_whitelist(request.user, corpus)
cooc = create_cooc(user=request.user, corpus=corpus, whitelist=whitelist)
print(cooc.id, "Cooc created")
else:
cooc = Node.objects.filter(type=type_cooc, parent=corpus).first()
for cooccurrence in NodeNgramNgram.objects.filter(node=cooc):
labels[cooccurrence.ngramx.id] = cooccurrence.ngramx.terms
......@@ -494,7 +504,6 @@ def json_node_link(request):
matrix[cooccurrence.ngramx.id][cooccurrence.ngramy.id] = cooccurrence.score
matrix[cooccurrence.ngramy.id][cooccurrence.ngramx.id] = cooccurrence.score
df = pd.DataFrame(matrix).T.fillna(0)
x = copy(df.values)
x = x / x.sum(axis=1)
......@@ -535,7 +544,6 @@ def json_node_link(request):
return JsonHttpResponse(data)
def graph_it(request):
'''The new multimodal graph.'''
t = get_template('graph-it.html')
......@@ -565,4 +573,3 @@ def ngrams(request):
}))
return HttpResponse(html)
......@@ -125,7 +125,7 @@
<div class="col-md-4">
<div class="jumbotron">
<h3><a href="/graph">Visualizations</a></h3>
<h3><a href="/corpus/{{ corpus.id }}/explorer">Visualizations</a></h3>
<ol>
<li>Matrix</li>
<li>Static maps</li>
......
......@@ -60,7 +60,7 @@
<li>
<a>
<div id="graphid" style="visibility: hidden;">/graph.json</div>
<div id="graphid" style="visibility: hidden;">/corpus/{{ corpus.id }}/node_link.json</div>
</a>
</li>
......
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