Commit 2b86f00f authored by pksm3's avatar pksm3

Merge branch 'master' of ssh://delanoe.org:1979/gargantext into samuel

parents ef4a79ae 79c77e3e
This diff is collapsed.
...@@ -140,9 +140,11 @@ def project(request, project_id): ...@@ -140,9 +140,11 @@ def project(request, project_id):
user = request.user user = request.user
date = datetime.datetime.now() date = datetime.datetime.now()
type_corpus = NodeType.objects.get(name='Corpus')
project = Node.objects.get(id=project_id) project = Node.objects.get(id=project_id)
corpora = project.children.all() corpora = project.children.filter(type=type_corpus)
number = project.children.count() number = len(corpora)
# DONUT corpora representation # DONUT corpora representation
...@@ -418,39 +420,63 @@ def json_node_link(request): ...@@ -418,39 +420,63 @@ def json_node_link(request):
''' '''
Create the HttpResponse object with the graph dataset. Create the HttpResponse object with the graph dataset.
''' '''
response = HttpResponse(content_type='text/json')
response['Content-Disposition'] = 'attachment; filename="graph.json"'
# writer = csv.writer(response)
#
# file = open('/srv/gargantext/tests/graphsam/randomgraphgen.json', 'r')
# for line in file.readlines():
# writer.writerow(line)
matrix = defaultdict(lambda : defaultdict(float))
cooc = Node.objects.get(id=61311)
for cooccurrence in NodeNgramNgram.objects.filter(node=cooc):
matrix[cooccurrence.ngramx.terms][cooccurrence.ngramy.terms] = cooccurrence.score
matrix[cooccurrence.ngramy.terms][cooccurrence.ngramx.terms] = cooccurrence.score
import pandas as pd import pandas as pd
from copy import copy from copy import copy
import numpy as np import numpy as np
import networkx as nx import networkx as nx
from networkx.readwrite import json_graph
from gargantext_web.api import JsonHttpResponse from gargantext_web.api import JsonHttpResponse
#from analysis.louvain import * #from analysis.louvain import *
matrix = defaultdict(lambda : defaultdict(float))
labels = dict()
cooc = Node.objects.get(id=61314)
for cooccurrence in NodeNgramNgram.objects.filter(node=cooc):
labels[cooccurrence.ngramx.id] = cooccurrence.ngramx.terms
labels[cooccurrence.ngramy.id] = cooccurrence.ngramy.terms
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) df = pd.DataFrame(matrix).T.fillna(0)
x = copy(df.values) x = copy(df.values)
x = x / x.sum(axis=1) x = x / x.sum(axis=1)
matrix_filtered = np.where(x > .2, 1, 0)
# Removing unconnected nodes
threshold = min(x.max(axis=1))
matrix_filtered = np.where(x > threshold, 1, 0)
#matrix_filtered = np.where(x > threshold, x, 0)
G = nx.from_numpy_matrix(matrix_filtered) G = nx.from_numpy_matrix(matrix_filtered)
G = nx.relabel_nodes(G, dict(enumerate(df.columns))) G = nx.relabel_nodes(G, dict(enumerate([ labels[x] for x in list(df.columns)])))
from networkx.readwrite import json_graph #G = nx.relabel_nodes(G, dict(enumerate(df.columns)))
# Removing too connected nodes (find automatic way to do it)
outdeg = G.degree()
to_remove = [n for n in outdeg if outdeg[n] >= 10]
G.remove_nodes_from(to_remove)
for node in G.nodes():
try:
#node,type(labels[node])
G.node[node]['label'] = node
# G.node[node]['color'] = '19,180,300'
except Exception as error:
print(error)
data = json_graph.node_link_data(G) data = json_graph.node_link_data(G)
# data = json_graph.node_link_data(G, attrs={\
# 'source':'source',\
# 'target':'target',\
# 'weight':'weight',\
# #'label':'label',\
# #'color':'color',\
# 'id':'id',})
#print(data)
return JsonHttpResponse(data) return JsonHttpResponse(data)
......
...@@ -60,7 +60,8 @@ ...@@ -60,7 +60,8 @@
{% load staticfiles %} {% load staticfiles %}
<script src="{% static "js/jquery/jquery-1.9.1.min.js"%}"></script> <!-- <script src="{% static "js/jquery/jquery-1.9.1.min.js"%}"></script> -->
<script src="{% static "js/easy/jquery.easypiechart.js"%}"></script> <script src="{% static "js/easy/jquery.easypiechart.js"%}"></script>
<script type="text/javascript"> <script type="text/javascript">
......
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