Commit 5ba83ead authored by Romain Loth's avatar Romain Loth

Merge branch 'anoe-graph' into romain-reintegration-graphExplorer

(recuperation de la nouvelle façon d'envoyer des messages + statut HTTP pour utilisation côté graphExplorer)
parents c4c26736 dca8b685
...@@ -4,6 +4,7 @@ from . import nodes ...@@ -4,6 +4,7 @@ from . import nodes
from . import metrics from . import metrics
from . import ngramlists from . import ngramlists
from . import analytics from . import analytics
from graphExplorer.rest import Graph
urlpatterns = [ url(r'^nodes$' , nodes.NodeListResource.as_view() ) urlpatterns = [ url(r'^nodes$' , nodes.NodeListResource.as_view() )
, url(r'^nodes/(\d+)$' , nodes.NodeResource.as_view() ) , url(r'^nodes/(\d+)$' , nodes.NodeResource.as_view() )
...@@ -58,4 +59,11 @@ urlpatterns = [ url(r'^nodes$' , nodes.NodeListResource.as_view() ...@@ -58,4 +59,11 @@ urlpatterns = [ url(r'^nodes$' , nodes.NodeListResource.as_view()
, url(r'^ngramlists/maplist$' , ngramlists.MapListGlance.as_view() ) , url(r'^ngramlists/maplist$' , ngramlists.MapListGlance.as_view() )
# fast access to maplist, similarly formatted for termtable # fast access to maplist, similarly formatted for termtable
, url(r'^projects/(\d+)/corpora/(\d+)/explorer$' , Graph.as_view())
# data for graph explorer (json)
# GET /api/projects/43198/corpora/111107/explorer?
# Corresponding view is : /projects/43198/corpora/111107/explorer?
# Parameters (example):
# explorer?field1=ngrams&field2=ngrams&distance=conditional&bridgeness=5&start=1996-6-1&end=2002-10-5
] ]
...@@ -9,6 +9,14 @@ from sqlalchemy import desc, asc, or_, and_ ...@@ -9,6 +9,14 @@ from sqlalchemy import desc, asc, or_, and_
#import inspect #import inspect
import datetime import datetime
def filterMatrix(matrix, mapList_id, groupList_id):
mapList = UnweightedList( mapList_id )
group_list = Translations ( groupList_id )
cooc = matrix & (mapList * group_list)
return cooc
def countCooccurrences( corpus=None def countCooccurrences( corpus=None
, field1='ngrams' , field2='ngrams' , field1='ngrams' , field2='ngrams'
, start=None , end=None , start=None , end=None
...@@ -182,15 +190,14 @@ def countCooccurrences( corpus=None ...@@ -182,15 +190,14 @@ def countCooccurrences( corpus=None
cooc_query = cooc_query.group_by(NodeHyperdataNgram.ngram_id, NodeNgramY.ngram_id) cooc_query = cooc_query.group_by(NodeHyperdataNgram.ngram_id, NodeNgramY.ngram_id)
# Order according some scores # Order according some scores
cooc_query = cooc_query.order_by(desc('cooc_score')) # If ordering is really needed, use Ordered Index (faster)
#cooc_query = cooc_query.order_by(desc('cooc_score'))
matrix = WeightedMatrix(cooc_query) matrix = WeightedMatrix(cooc_query)
mapList = UnweightedList( mapList_id ) cooc = filterMatrix(matrix, mapList_id, groupList_id)
group_list = Translations ( groupList_id )
cooc = matrix & (mapList * group_list)
if save_on_db: if save_on_db:
cooc.save(coocNode_id) cooc.save(coocNode_id)
return(coocNode_id) print("Cooccurrence Matrix saved")
else:
return cooc return cooc
# Gargantext lib # Gargantext lib
from gargantext.util.db import session from gargantext.util.db import session
from gargantext.util.lists import WeightedMatrix, UnweightedList, Translations
from gargantext.util.http import JsonHttpResponse from gargantext.util.http import JsonHttpResponse
from gargantext.models import Node, Ngram, NodeNgram, NodeNgramNgram from gargantext.models import Node, Ngram, NodeNgram, NodeNgramNgram
#from gargantext.util.toolchain.ngram_coocs import compute_coocs #from gargantext.util.toolchain.ngram_coocs import compute_coocs
from graphExplorer.cooccurrences import countCooccurrences from graphExplorer.cooccurrences import countCooccurrences, filterMatrix
from graphExplorer.distances import clusterByDistances from graphExplorer.distances import clusterByDistances
from graphExplorer.bridgeness import filterByBridgeness from graphExplorer.bridgeness import filterByBridgeness
...@@ -63,11 +64,15 @@ def get_graph( request=None , corpus=None ...@@ -63,11 +64,15 @@ def get_graph( request=None , corpus=None
, start=start , end =end , start=start , end =end
, mapList_id=mapList_id , groupList_id=groupList_id , mapList_id=mapList_id , groupList_id=groupList_id
, isMonopartite=True , threshold = threshold , isMonopartite=True , threshold = threshold
, save_on_db = False , save_on_db = True
#, limit=size #, limit=size
) )
else: else:
cooc_matrix = WeightedMatrix(cooc_id) print("Getting data for matrix %d", int(cooc_id))
matrix = WeightedMatrix(int(cooc_id))
print(matrix)
cooc_matrix = filterMatrix(matrix, mapList_id, groupList_id)
# fyi # fyi
after_cooc = datetime.now() after_cooc = datetime.now()
......
...@@ -24,6 +24,8 @@ class Graph(APIView): ...@@ -24,6 +24,8 @@ class Graph(APIView):
corpus = session.query(Node).filter(Node.id==corpus_id).first() corpus = session.query(Node).filter(Node.id==corpus_id).first()
# Get all the parameters in the URL # Get all the parameters in the URL
cooc_id = request.GET.get ('cooc_id' , None )
field1 = str(request.GET.get ('field1' , 'ngrams' )) field1 = str(request.GET.get ('field1' , 'ngrams' ))
field2 = str(request.GET.get ('field2' , 'ngrams' )) field2 = str(request.GET.get ('field2' , 'ngrams' ))
...@@ -40,6 +42,7 @@ class Graph(APIView): ...@@ -40,6 +42,7 @@ class Graph(APIView):
distance = str(request.GET.get ('distance' , 'conditional')) distance = str(request.GET.get ('distance' , 'conditional'))
# Get default value if no map list # Get default value if no map list
if mapList_id == 0 : if mapList_id == 0 :
mapList_id = ( session.query ( Node.id ) mapList_id = ( session.query ( Node.id )
.filter( Node.typename == "MAPLIST" .filter( Node.typename == "MAPLIST"
...@@ -72,19 +75,22 @@ class Graph(APIView): ...@@ -72,19 +75,22 @@ class Graph(APIView):
# Chec the options # Chec the options
accepted_field1 = ['ngrams', 'journal', 'source', 'authors'] accepted_field1 = ['ngrams', 'journal', 'source', 'authors']
accepted_field2 = ['ngrams', ] accepted_field2 = ['ngrams', ]
options = ['start', 'end', 'threshold', 'distance' ] options = ['start', 'end', 'threshold', 'distance', 'cooc_id' ]
# Test function
if field1 in accepted_field1 : if field1 in accepted_field1 :
if field2 in accepted_field2 : if field2 in accepted_field2 :
if start is not None and end is not None : if start is not None and end is not None :
data = get_graph( corpus=corpus data = get_graph( corpus=corpus, cooc_id = cooc_id
#, field1=field1 , field2=field2 #, field1=field1 , field2=field2
, mapList_id = mapList_id , groupList_id = groupList_id , mapList_id = mapList_id , groupList_id = groupList_id
, start=start , end=end , start=start , end=end
, threshold =threshold , distance=distance , threshold =threshold , distance=distance
) )
else: else:
data = get_graph( corpus = corpus data = get_graph( corpus = corpus, cooc_id = cooc_id
#, field1=field1, field2=field2 #, field1=field1, field2=field2
, mapList_id = mapList_id , groupList_id = groupList_id , mapList_id = mapList_id , groupList_id = groupList_id
, threshold = threshold , threshold = threshold
......
...@@ -2,7 +2,7 @@ from django.conf.urls import patterns, url ...@@ -2,7 +2,7 @@ from django.conf.urls import patterns, url
# Module "Graph Explorer" # Module "Graph Explorer"
from graphExplorer.rest import Graph from graphExplorer.rest import Graph
from graphExplorer.views import explorer from graphExplorer.views import explorer, myGraphs
from graphExplorer.intersection import intersection from graphExplorer.intersection import intersection
...@@ -12,8 +12,9 @@ from graphExplorer.intersection import intersection ...@@ -12,8 +12,9 @@ from graphExplorer.intersection import intersection
# ^explorer/$corpus_id/data.json # ^explorer/$corpus_id/data.json
# ^explorer/$corpus_id/intersection # ^explorer/$corpus_id/intersection
urlpatterns = [ url(r'^explorer/intersection/(\w+)$', intersection ) # GET ^api/projects/(\d+)/corpora/(\d+)/explorer$ -> data in json format
, url(r'^projects/(\d+)/corpora/(\d+)/explorer$', explorer )
, url(r'^projects/(\d+)/corpora/(\d+)/graph$' , Graph.as_view()) urlpatterns = [ url(r'^projects/(\d+)/corpora/(\d+)/explorer$' , explorer )
, url(r'^projects/(\d+)/corpora/(\d+)/node_link.json$', Graph.as_view()) , url(r'^projects/(\d+)/corpora/(\d+)/myGraphs$' , myGraphs )
, url(r'^explorer/intersection/(\w+)$' , intersection )
] ]
...@@ -25,21 +25,58 @@ def explorer(request, project_id, corpus_id): ...@@ -25,21 +25,58 @@ def explorer(request, project_id, corpus_id):
# and the project just for project.id in corpusBannerTop # and the project just for project.id in corpusBannerTop
project = cache.Node[project_id] project = cache.Node[project_id]
graphurl = "projects/" + str(project_id) + "/corpora/" + str(corpus_id) + "/node_link.json"
# rendered page : explorer.html # rendered page : explorer.html
return render( return render(
template_name = 'graphExplorer/explorer.html', template_name = 'graphExplorer/explorer.html',
request = request, request = request,
context = {
'debug' : settings.DEBUG ,
'request' : request ,
'user' : request.user ,
'date' : datetime.now() ,
'project' : project ,
'corpus' : corpus ,
'maplist_id': maplist_id ,
'view' : 'graph' ,
},
)
@requires_auth
def myGraphs(request, project_id, corpus_id):
'''
List all of my Graphs
'''
user = cache.User[request.user.id]
# we pass our corpus
corpus = cache.Node[corpus_id]
# and the project just for project.id in corpusBannerTop
project = cache.Node[project_id]
coocs = corpus.children('COOCCURRENCES', order=True).all()
coocs_count = dict()
for cooc in coocs:
cooc_nodes = session.query(NodeNgramNgram).filter(NodeNgramNgram.node_id==cooc.id).count()
coocs_count[cooc.id] = cooc_nodes
return render(
template_name = 'pages/corpora/myGraphs.html',
request = request,
context = { context = {
'debug' : settings.DEBUG, 'debug' : settings.DEBUG,
'request' : request, 'request' : request,
'user' : request.user, 'user' : request.user,
'date' : datetime.now(), 'date' : datetime.now(),
'project' : project, 'project' : project,
'resourcename' : resourcename(corpus),
'corpus' : corpus, 'corpus' : corpus,
'maplist_id': maplist_id, 'view' : 'myGraph',
'graphfile' : graphurl, 'coocs' : coocs,
'view' : 'graph' 'coocs_count' : coocs_count
}, },
) )
...@@ -30,17 +30,9 @@ var mainfile = ["db.json"]; ...@@ -30,17 +30,9 @@ var mainfile = ["db.json"];
// getUrlParam.file = window.location.origin+"/"+$("#graphid").html(); // garg exclusive // getUrlParam.file = window.location.origin+"/"+$("#graphid").html(); // garg exclusive
// var corpusesList = {} // garg exclusive -> corpus comparison // var corpusesList = {} // garg exclusive -> corpus comparison
// getUrlParam.file = "data/testgraph.json"; var current_url = window.location.origin+window.location.pathname+window.location.search
getUrlParam.file = current_url.replace(/projects/g, "api/projects")
if( isUndef(getUrlParam.field1) && isUndef(getUrlParam.field2) ) {
if($("#graphid").length>0) {
getUrlParam.file = window.location.origin+"/"+$("#graphid").html(); // just Garg
}
} else {
var current_url = window.location.origin+window.location.pathname+window.location.search
getUrlParam.file = current_url.replace(/project(.*?)corpus/g, "api/corpus").replace("explorer?","graph?")
}
// if($("#graphid").length>0) // just Garg // if($("#graphid").length>0) // just Garg
// getUrlParam.file = window.location.origin+"/"+$("#graphid").html(); // just Garg // getUrlParam.file = window.location.origin+"/"+$("#graphid").html(); // just Garg
......
...@@ -88,7 +88,7 @@ ...@@ -88,7 +88,7 @@
<li> <li>
<a> <a>
<div id="graphid" style="visibility: hidden;">{{graphfile}}</div> <div id="graphid" style="visibility: hidden;">{{graphurl}}</div>
<input type="hidden" id="maplist_id" value="{{ maplist_id }}"></input> <input type="hidden" id="maplist_id" value="{{ maplist_id }}"></input>
<div id="jquerytemplatenb" style="visibility: hidden;">{{user.id}}</div> <div id="jquerytemplatenb" style="visibility: hidden;">{{user.id}}</div>
</a> </a>
......
{% extends "pages/menu.html" %}
{% block css %}
{% load staticfiles %}
<link rel="stylesheet" href="{% static "lib/bootstrap/3.0.2/bootstrap.css" %}">
<script type="text/javascript" src="{% static "lib/jquery/1.11.1/jquery.min.js" %}"></script>
<script type="text/javascript" src="{% static "lib/gargantext/garganrest.js" %}"></script>
<link rel="stylesheet" href="{% static "lib/jquery/1.11.2/jquery-ui.css" %}">
<script src="{% static "lib/jquery/1.11.1/jquery.min.js" %}" type="text/javascript"></script>
{% endblock %}
{% block content %}
<div class="container theme-showcase" role="main">
<h2>My Graphs </h2>
{% for cooc in coocs %}
<div id="graph_{{cooc.id}}">
<div class="row">
<div class="col-md-1 content"></div>
<div class="col-md-5 content">
<a href="/projects/{{project.id}}/corpora/{{corpus.id}}/explorer?cooc_id={{cooc.id}}">
{{cooc.id}} {{ cooc.name }}
(size =
{% for key, value in coocs_count.items %}
{% if key == cooc.id %}
{{value}}
{% endif %}
{% endfor %}
)
</a>
</div>
<div class="col-md-3 content">
<a href="/projects/{{project.id}}/corpora/{{corpus.id}}/explorer?cooc_id={{cooc.id}}"
title="View Graph">
<button type="button" class="btn btn-default" aria-label="Left Align">
<span class="glyphicon glyphicon-eye-open" aria-hidden="true"></span>
</button>
</a>
<button type="button" class="btn btn-default" data-container="body" data-toggle="popover" data-placement="bottom"
data-content="
<ul>
<li
onclick=&quot;
garganrest.nodes.delete({{cooc.id}}, function(){$('#graph_'+{{cooc.id}}).remove()});
$(this).parent().parent().remove();
&quot;>
<a href='#'>Delete this</a>
</li>
</ul>
">
<span class="glyphicon glyphicon-trash" aria-hidden="true"
title='Delete this graph'></span>
</button>
</div>
</div>
</div>
</li>
{% endfor %}
</ul>
{% endblock %}
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