Commit 2fac6579 authored by delanoe's avatar delanoe

Merge branch 'samuel' into unstable

parents 2a7f88bd e4eda860
...@@ -333,25 +333,86 @@ class Group(APIView): ...@@ -333,25 +333,86 @@ class Group(APIView):
raise APIException('Missing parameter: "{\'data\' : [\'source\': Int, \'target\': [Int]}"', 400) raise APIException('Missing parameter: "{\'data\' : [\'source\': Int, \'target\': [Int]}"', 400)
def put(self , request , corpus_id ): def put(self , request , corpus_id ):
print(request)
print("= = = = = = = = = = = = = = ") group_rawreq = dict(request.data)
print("PUUUUUT:")
print("corpus_id:",corpus_id) GDict = []
group_id = self.get_group_id(corpus_id) group_new = {}
ngrams_ngrams = (session for g in group_rawreq:
gdict = []
mainform = int(g.replace("[]",""))
gdict.append(mainform)
group_new[mainform] = list(map(int, group_rawreq[g]))
for subform in group_new[mainform]:
gdict.append(subform)
GDict.append( gdict )
existing_group_id = self.get_group_id(corpus_id)
grouped_ngrams = (session
.query(NodeNgramNgram) .query(NodeNgramNgram)
.filter(NodeNgramNgram.node_id==group_id) .filter(NodeNgramNgram.node_id==existing_group_id)
) )
for ng in ngrams_ngrams:
print(ng) # [ - - - new group = old clique + new clique - - - ] #
print("= = = = = = = = = = = = = = ") Clique_Changes = {}
print("FIN") Rels_2_delete = {}
# GroupsJSON = self.get( request , corpus_id ) for ng in grouped_ngrams:
# # Groups = json.loads(GroupsJSON[0].decode("utf-8")) for i in range(len(GDict)):
# Groups = {} clique_i = GDict[i]
# for g in GroupsJSON: neighbours = {}
# Groups = g.decode("utf-8") for node in clique_i:
# print(Groups) 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 Clique_Changes:
Clique_Changes[i] = {}
for node in clique_i:
Clique_Changes[i][node] = True
for i in Clique_Changes:
Clique_Changes[i] = list(Clique_Changes[i].keys())
# [ - - - / new group = old clique + new clique - - - ] #
# import networkx as nx
# G = nx.Graph()
# DG = nx.DiGraph()
# for ng in grouped_ngrams:
# n_x = ( session.query(Ngram).filter(Ngram.id==ng.ngramx_id) ).first()
# n_y = ( session.query(Ngram).filter(Ngram.id==ng.ngramy_id) ).first()
# G.add_edge( n_x.terms , n_y.terms )
# DG.add_edge( n_x.terms , n_y.terms )
# # G.add_edge( ng.ngramx_id , ng.ngramy_id )
# # DG.add_edge( ng.ngramx_id , ng.ngramy_id )
# sinonims_cliques = nx.find_cliques( G )
# groups = { "nodes": {} , "links": {} }
# for clique in sinonims_cliques:
# max_deg = -1
# mainNode = -1
# mainNode_sinonims = []
# for node in clique:
# groups["nodes"][node] = False
# node_outdeg = DG.out_degree(node)
# if node_outdeg>max_deg:
# max_deg = node_outdeg
# mainNode = node
# for node in clique:
# if mainNode!=node:
# mainNode_sinonims.append( node )
# groups["links"][ mainNode ] = mainNode_sinonims
# import pprint
# pprint.pprint( groups["links"] )
# print("= = = = = = = = = = = = = = ")
return JsonHttpResponse(True, 201) return JsonHttpResponse(True, 201)
class Keep(APIView): class Keep(APIView):
......
...@@ -322,6 +322,7 @@ function clickngram_action ( elem ) { ...@@ -322,6 +322,7 @@ function clickngram_action ( elem ) {
// $("#Clean_All, #Save_All").attr( "disabled", "disabled" ); // $("#Clean_All, #Save_All").attr( "disabled", "disabled" );
// } // }
// modified // modified
function transformContent(rec_id) { function transformContent(rec_id) {
var elem = AjaxRecords[rec_id]; var elem = AjaxRecords[rec_id];
...@@ -841,17 +842,21 @@ $.when( ...@@ -841,17 +842,21 @@ $.when(
// Deleting subforms from the ngrams-table, clean start baby! // Deleting subforms from the ngrams-table, clean start baby!
if( Object.keys(ngrams_groups.links).length>0 ) { if( Object.keys(ngrams_groups.links).length>0 ) {
var subforms = {}
var _forms = { "main":{} , "sub":{} }
for(var i in ngrams_groups.links) { for(var i in ngrams_groups.links) {
_forms["main"][i] = true
for(var j in ngrams_groups.links[i]) { for(var j in ngrams_groups.links[i]) {
subforms[ ngrams_groups.links[i][j] ] = true _forms["sub"][ ngrams_groups.links[i][j] ] = true
} }
} }
var ngrams_data_ = [] var ngrams_data_ = []
for(var i in ngrams_data.ngrams) { for(var i in ngrams_data.ngrams) {
if(subforms[ngrams_data.ngrams[i].id]) { if(_forms["sub"][ngrams_data.ngrams[i].id]) {
ngrams_groups["nodes"][ngrams_data.ngrams[i].id] = ngrams_data.ngrams[i] ngrams_groups["nodes"][ngrams_data.ngrams[i].id] = ngrams_data.ngrams[i]
} else { } else {
if( _forms["main"][ ngrams_data.ngrams[i].id ] )
ngrams_data.ngrams[i].name = "*"+ngrams_data.ngrams[i].name
ngrams_data_.push( ngrams_data.ngrams[i] ) ngrams_data_.push( ngrams_data.ngrams[i] )
} }
} }
......
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