Commit 650c8fea authored by delanoe's avatar delanoe

Merge branch 'samuel' into unstable

parents 2a11a46c 156363ba
...@@ -15,6 +15,7 @@ from rest_framework.authentication import SessionAuthentication, BasicAuthentica ...@@ -15,6 +15,7 @@ from rest_framework.authentication import SessionAuthentication, BasicAuthentica
from node.models import Node from node.models import Node
from gargantext_web.db import session, cache, Node, NodeNgram from gargantext_web.db import session, cache, Node, NodeNgram
from ngram.lists import listIds, listNgramIds from ngram.lists import listIds, listNgramIds
from gargantext_web.db import get_or_create_node
@login_required @login_required
...@@ -93,7 +94,7 @@ class NgramEdit(APIView): ...@@ -93,7 +94,7 @@ class NgramEdit(APIView):
""" """
Delete a ngram from a list Delete a ngram from a list
""" """
print(ngram_ids) print("to del",ngram_ids)
for ngram_id in ngram_ids.split('+'): for ngram_id in ngram_ids.split('+'):
print('ngram_id', ngram_id) print('ngram_id', ngram_id)
ngram_id = int(ngram_id) ngram_id = int(ngram_id)
...@@ -101,7 +102,21 @@ class NgramEdit(APIView): ...@@ -101,7 +102,21 @@ class NgramEdit(APIView):
.filter(NodeNgram.node_id==list_id) .filter(NodeNgram.node_id==list_id)
.filter(NodeNgram.ngram_id==ngram_id).delete() .filter(NodeNgram.ngram_id==ngram_id).delete()
) )
session.commit()
# [ = = = = del from map-list = = = = ]
list_id = session.query(Node).filter(Node.id==list_id).first()
corpus = session.query(Node).filter(Node.id==list_id.parent_id , Node.type_id==cache.NodeType['Corpus'].id).first()
node_mapList = get_or_create_node(nodetype='MapList', corpus=corpus )
results = session.query(NodeNgram).filter(NodeNgram.node_id==node_mapList.id ).all()
ngram_2del = [int(i) for i in ngram_ids.split('+')]
ngram_2del = session.query(NodeNgram).filter(NodeNgram.node_id==node_mapList.id , NodeNgram.ngram_id.in_(ngram_2del) ).all()
for map_node in ngram_2del:
session.delete(map_node)
session.commit() session.commit()
# [ = = = = / del from map-list = = = = ]
return Response(None, 204) return Response(None, 204)
class NgramCreate(APIView): class NgramCreate(APIView):
......
...@@ -346,75 +346,120 @@ class Group(APIView): ...@@ -346,75 +346,120 @@ class Group(APIView):
for subform in group_new[mainform]: for subform in group_new[mainform]:
gdict.append(subform) gdict.append(subform)
GDict.append( gdict ) GDict.append( gdict )
import pprint existing_group_id = self.get_group_id(corpus_id)
pprint.pprint( GDict ) grouped_ngrams = (session
# existing_group_id = self.get_group_id(corpus_id) .query(NodeNgramNgram)
# grouped_ngrams = (session .filter(NodeNgramNgram.node_id==existing_group_id)
# .query(NodeNgramNgram) )
# .filter(NodeNgramNgram.node_id==existing_group_id)
# )
# [ - - - new group = old clique + new clique - - - ] #
# # [ - - - new group = old clique + new clique - - - ] # NewGroups = {}
# NewGroups = {} Rels_2_delete = {}
# Rels_2_delete = {} for ng in grouped_ngrams:
print(ng)
for i in range(len(GDict)):
clique_i = GDict[i]
neighbours = {}
for node in clique_i:
if node==ng.ngramx_id:
neighbours[ng.ngramy_id] = True
if node==ng.ngramy_id:
neighbours[ng.ngramx_id] = True
if len(list(neighbours.keys()))>0:
voisinage = {}
for node_ in clique_i:
voisinage[node_] = True
for node_ in neighbours:
voisinage[node_] = True
clique_i = list(voisinage.keys())
Rels_2_delete[ng.id] = True
if i not in NewGroups:
NewGroups[i] = {}
for node in clique_i:
NewGroups[i][node] = True
for i in NewGroups:
NewGroups[i] = list(NewGroups[i].keys())
# [ - - - / new group = old clique + new clique - - - ] #
# [ - - - considering main form of the query - - - ] #
for i in range(len(GDict)):
ordered = []
for j in range(len(NewGroups[i])):
if NewGroups[i][j]!=GDict[i][0]:
ordered.append( NewGroups[i][j] )
NewGroups[i] = [ GDict[i][0] ] + ordered
# [ - - - / considering main form of the query - - - ] #
# [ - - - deleting old clique - - - ] #
for rel_id in Rels_2_delete:
session.query(NodeNgramNgram).filter(NodeNgramNgram.id==rel_id ).delete()
session.commit()
# [ - - - / deleting old clique - - - ] #
# [ - - - doing links of new clique and adding to DB - - - ] #
from itertools import combinations
for i in NewGroups:
edges = combinations(NewGroups[i], 2)
for n in edges:
n1=n[0]
n2=n[1]
nodengramngram = NodeNgramNgram(node_id=existing_group_id, ngramx_id=n1 , ngramy_id=n2, score=1.0)
session.add(nodengramngram)
session.commit()
# [ - - - / doing links of new clique and adding to DB - - - ] #
# import networkx as nx
# G = nx.Graph()
# DG = nx.DiGraph()
# for ng in grouped_ngrams: # for ng in grouped_ngrams:
# print(ng) # n_x = ( session.query(Ngram).filter(Ngram.id==ng.ngramx_id) ).first()
# for i in range(len(GDict)): # n_y = ( session.query(Ngram).filter(Ngram.id==ng.ngramy_id) ).first()
# clique_i = GDict[i] # G.add_edge( str(ng.ngramx_id)+" "+n_x.terms , str(ng.ngramy_id)+" "+n_y.terms )
# neighbours = {} # DG.add_edge( str(ng.ngramx_id)+" "+n_x.terms , str(ng.ngramy_id)+" "+n_y.terms )
# for node in clique_i:
# if node==ng.ngramx_id: # # group = dict(list())
# neighbours[ng.ngramy_id] = True # sinonims_cliques = nx.find_cliques( G )
# if node==ng.ngramy_id: # # for nn in ngrams_ngrams.all():
# neighbours[ng.ngramx_id] = True # # group[nn.ngramx_id] = group.get(nn.ngramx_id, []) + [nn.ngramy_id]
# if len(list(neighbours.keys()))>0:
# voisinage = {} # groups = { "nodes": {} , "links": {} }
# for node_ in clique_i: # for clique in sinonims_cliques:
# voisinage[node_] = True # max_deg = -1
# for node_ in neighbours: # mainNode = -1
# voisinage[node_] = True # mainNode_sinonims = []
# clique_i = list(voisinage.keys()) # for node in clique:
# Rels_2_delete[ng.id] = True # groups["nodes"][node] = False
# node_outdeg = DG.out_degree(node)
# if i not in NewGroups: # if node_outdeg>max_deg:
# NewGroups[i] = {} # max_deg = node_outdeg
# for node in clique_i: # mainNode = node
# NewGroups[i][node] = True # for node in clique:
# if mainNode!=node:
# for i in NewGroups: # mainNode_sinonims.append( node )
# NewGroups[i] = list(NewGroups[i].keys()) # groups["links"][ mainNode ] = mainNode_sinonims
# # [ - - - / new group = old clique + new clique - - - ] #
# import pprint
# print("GDict:")
# # [ - - - considering main form of the query - - - ] # # pprint.pprint( GDict )
# for i in range(len(GDict)): # print("")
# ordered = [] # print("NewGroups:")
# for j in range(len(NewGroups[i])): # pprint.pprint( NewGroups )
# if NewGroups[i][j]!=GDict[i][0]: # print("")
# ordered.append( NewGroups[i][j] ) # print("Ids to delete:")
# NewGroups[i] = [ GDict[i][0] ] + ordered # pprint.pprint( Rels_2_delete )
# # [ - - - / considering main form of the query - - - ] # # print("")
# print('groups["links"]:')
# pprint.pprint( groups["links"] )
# print("")
# # [ - - - deleting old clique - - - ] #
# for rel_id in Rels_2_delete:
# session.query(NodeNgramNgram).filter(NodeNgramNgram.id==rel_id ).delete()
# session.commit()
# # [ - - - / deleting old clique - - - ] #
# # [ - - - doing links of new clique and adding to DB - - - ] #
# from itertools import combinations
# for i in NewGroups:
# edges = combinations(NewGroups[i], 2)
# for n in edges:
# n1=n[0]
# n2=n[1]
# nodengramngram = NodeNgramNgram(node_id=existing_group_id, ngramx_id=n1 , ngramy_id=n2, score=1.0)
# session.add(nodengramngram)
# session.commit()
# # [ - - - / doing links of new clique and adding to DB - - - ] #
return JsonHttpResponse(True, 201) return JsonHttpResponse(True, 201)
......
...@@ -514,15 +514,26 @@ $("#Save_All").click(function(){ ...@@ -514,15 +514,26 @@ $("#Save_All").click(function(){
var list_id = $("#list_id").val() var list_id = $("#list_id").val()
var corpus_id = getIDFromURL( "corpus" ) // not used var corpus_id = getIDFromURL( "corpus" ) // not used
CRUD( list_id , "" , nodes_2del , [] , "DELETE" ) // $.when(
CRUD( list_id , "/keep" , nodes_2keep , [] , "PUT" ) // ).then(function() {
CRUD( corpus_id , "/group" , [] , nodes_2group , "PUT" ) // // window.location.reload()
// });
window.location.reload()
CRUD( list_id , "" , nodes_2del , [] , "DELETE" ),
$.doTimeout( 1000, function(){
CRUD( list_id , "/keep" , nodes_2keep , [] , "PUT" )
$.doTimeout( 1000, function(){
CRUD( corpus_id , "/group" , [] , nodes_2group , "PUT" )
$.doTimeout( 1000, function(){
window.location.reload()
});
});
});
}); });
function CRUD( parent_id , action , nodes , args , http_method ) { function CRUD( parent_id , action , nodes , args , http_method ) {
console.log( http_method + " : " + action )
var the_url = window.location.origin+"/api/node/"+parent_id+"/ngrams"+action+"/"+nodes.join("+"); var the_url = window.location.origin+"/api/node/"+parent_id+"/ngrams"+action+"/"+nodes.join("+");
the_url = the_url.replace(/\/$/, ""); //remove trailing slash the_url = the_url.replace(/\/$/, ""); //remove trailing slash
if(nodes.length>0 || Object.keys(args).length>0) { if(nodes.length>0 || Object.keys(args).length>0) {
...@@ -537,10 +548,12 @@ function CRUD( parent_id , action , nodes , args , http_method ) { ...@@ -537,10 +548,12 @@ function CRUD( parent_id , action , nodes , args , http_method ) {
console.log(http_method + " ok!!") console.log(http_method + " ok!!")
console.log(nodes) console.log(nodes)
console.log(data) console.log(data)
return true;
}, },
error: function(result) { error: function(result) {
console.log("Data not found in #Save_All"); console.log("Data not found in #Save_All");
console.log(result) console.log(result)
return false;
} }
}); });
......
...@@ -220,6 +220,7 @@ input[type=radio]:checked + label { ...@@ -220,6 +220,7 @@ input[type=radio]:checked + label {
<script type="text/javascript" src="{% static "js/jquery/jquery.min.js" %}"></script> <script type="text/javascript" src="{% static "js/jquery/jquery.min.js" %}"></script>
<script src="{% static "js/charts/bootstrap.min.js" %}"></script> <script src="{% static "js/charts/bootstrap.min.js" %}"></script>
<script src="{% static "js/libs/jquery/jquery.ba-dotimeout.min.js" %}" type="text/javascript"></script>
<script type="text/javascript" src="{% static "js/jquery/jquery.dynatable.js" %}"></script> <script type="text/javascript" src="{% static "js/jquery/jquery.dynatable.js" %}"></script>
<!-- custom-lib for dynatable.js and dc.js --> <!-- custom-lib for dynatable.js and dc.js -->
......
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