Commit 99f83f61 authored by PkSM3's avatar PkSM3

[UPDATE] group, delete available (one more bugfix remaining in group)

parent e4eda860
...@@ -346,73 +346,76 @@ class Group(APIView): ...@@ -346,73 +346,76 @@ 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 )
existing_group_id = self.get_group_id(corpus_id) import pprint
grouped_ngrams = (session pprint.pprint( GDict )
.query(NodeNgramNgram) # existing_group_id = self.get_group_id(corpus_id)
.filter(NodeNgramNgram.node_id==existing_group_id) # grouped_ngrams = (session
) # .query(NodeNgramNgram)
# .filter(NodeNgramNgram.node_id==existing_group_id)
# [ - - - new group = old clique + new clique - - - ] # # )
Clique_Changes = {}
Rels_2_delete = {} # # [ - - - new group = old clique + new clique - - - ] #
for ng in grouped_ngrams: # NewGroups = {}
for i in range(len(GDict)): # Rels_2_delete = {}
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 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: # for ng in grouped_ngrams:
# n_x = ( session.query(Ngram).filter(Ngram.id==ng.ngramx_id) ).first() # print(ng)
# n_y = ( session.query(Ngram).filter(Ngram.id==ng.ngramy_id) ).first() # for i in range(len(GDict)):
# G.add_edge( n_x.terms , n_y.terms ) # clique_i = GDict[i]
# DG.add_edge( n_x.terms , n_y.terms ) # neighbours = {}
# # G.add_edge( ng.ngramx_id , ng.ngramy_id ) # for node in clique_i:
# # DG.add_edge( ng.ngramx_id , ng.ngramy_id ) # if node==ng.ngramx_id:
# sinonims_cliques = nx.find_cliques( G ) # neighbours[ng.ngramy_id] = True
# groups = { "nodes": {} , "links": {} } # if node==ng.ngramy_id:
# for clique in sinonims_cliques: # neighbours[ng.ngramx_id] = True
# max_deg = -1 # if len(list(neighbours.keys()))>0:
# mainNode = -1 # voisinage = {}
# mainNode_sinonims = [] # for node_ in clique_i:
# for node in clique: # voisinage[node_] = True
# groups["nodes"][node] = False # for node_ in neighbours:
# node_outdeg = DG.out_degree(node) # voisinage[node_] = True
# if node_outdeg>max_deg: # clique_i = list(voisinage.keys())
# max_deg = node_outdeg # Rels_2_delete[ng.id] = True
# mainNode = node
# for node in clique: # if i not in NewGroups:
# if mainNode!=node: # NewGroups[i] = {}
# mainNode_sinonims.append( node ) # for node in clique_i:
# groups["links"][ mainNode ] = mainNode_sinonims # NewGroups[i][node] = True
# import pprint
# pprint.pprint( groups["links"] ) # for i in NewGroups:
# NewGroups[i] = list(NewGroups[i].keys())
# print("= = = = = = = = = = = = = = ") # # [ - - - / 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 - - - ] #
return JsonHttpResponse(True, 201) return JsonHttpResponse(True, 201)
class Keep(APIView): class Keep(APIView):
......
...@@ -514,40 +514,22 @@ $("#Save_All").click(function(){ ...@@ -514,40 +514,22 @@ $("#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" ) CRUD( list_id , "" , nodes_2del , [] , "DELETE" )
// CRUD( list_id , "/keep" , nodes_2keep , "PUT" ) CRUD( list_id , "/keep" , nodes_2keep , [] , "PUT" )
// CRUD( corpus_id , "/group" , nodes_2group , "PUT" ) CRUD( corpus_id , "/group" , [] , nodes_2group , "PUT" )
console.log(nodes_2group)
var the_url = window.location.origin+"/api/node/"+corpus_id+"/ngrams"+"/group"
$.ajax({
method: "PUT",
data: nodes_2group,
url: the_url,
beforeSend: function(xhr) {
xhr.setRequestHeader("X-CSRFToken", getCookie("csrftoken"));
},
success: function(data){
console.log("PUT" + " ok!!")
console.log(nodes_2group)
console.log(data)
},
error: function(result) {
console.log("Data not found in #Save_All");
console.log(result)
}
});
window.location.reload()
}); });
function CRUD( parent_id , action , nodes , http_method ) { function CRUD( parent_id , action , nodes , args , http_method ) {
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("+");
if(nodes.length>0) { the_url = the_url.replace(/\/$/, ""); //remove trailing slash
if(nodes.length>0 || Object.keys(args).length>0) {
$.ajax({ $.ajax({
method: http_method, method: http_method,
url: the_url, url: the_url,
data: args,
beforeSend: function(xhr) { beforeSend: function(xhr) {
xhr.setRequestHeader("X-CSRFToken", getCookie("csrftoken")); xhr.setRequestHeader("X-CSRFToken", getCookie("csrftoken"));
}, },
...@@ -617,7 +599,7 @@ function Main_test( data , initial) { ...@@ -617,7 +599,7 @@ function Main_test( data , initial) {
var node_info = { var node_info = {
"id" : le_ngram.id, "id" : le_ngram.id,
"name": le_ngram.id+"_"+le_ngram.name, "name": le_ngram.name,
"score": le_ngram.scores[FirstScore],//le_ngram.scores.tfidf_sum / le_ngram.scores.occ_uniq, "score": le_ngram.scores[FirstScore],//le_ngram.scores.tfidf_sum / le_ngram.scores.occ_uniq,
"flag":false, "flag":false,
"group_plus": true, "group_plus": true,
...@@ -842,7 +824,7 @@ $.when( ...@@ -842,7 +824,7 @@ $.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 _forms = { "main":{} , "sub":{} } var _forms = { "main":{} , "sub":{} }
for(var i in ngrams_groups.links) { for(var i in ngrams_groups.links) {
_forms["main"][i] = true _forms["main"][i] = true
......
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