Commit 83e263f6 authored by PkSM3's avatar PkSM3

[UPDATE] json format for getting groups

parent 331bbfe4
...@@ -242,11 +242,11 @@ class Group(APIView): ...@@ -242,11 +242,11 @@ class Group(APIView):
# IMPORTANT: Algorithm for getting the groups: # IMPORTANT: Algorithm for getting the groups:
# 1. pairs_list <- Get all pairs from get_group_id # 1. pairs_list <- Get all pairs from get_group_id()
# 2. G <- Do a non-directed graph of pairs_list # 2. G <- Do a non-directed graph of pairs_list
# 3. DG <- Do a directed graph of pairs_list # 3. DG <- Do a directed graph of pairs_list
# 4. cliques_list <- find_cliques of G # 4. cliques_list <- find_cliques of G
# 5. groups <- Iterate in G and set the mainNode per each clique: take the highest max_outdegree-node of each clique, using DG # 5. groups <- Iterate in sinonims_cliques and set the mainNode per each clique: take the highest max_outdegree-node of each clique, using DG
import networkx as nx import networkx as nx
G = nx.Graph() G = nx.Graph()
...@@ -267,20 +267,21 @@ class Group(APIView): ...@@ -267,20 +267,21 @@ class Group(APIView):
# for nn in ngrams_ngrams.all(): # for nn in ngrams_ngrams.all():
# group[nn.ngramx_id] = group.get(nn.ngramx_id, []) + [nn.ngramy_id] # group[nn.ngramx_id] = group.get(nn.ngramx_id, []) + [nn.ngramy_id]
groups = {} groups = { "nodes": {} , "links": {} }
for c in sinonims_cliques: for clique in sinonims_cliques:
max_deg = -1 max_deg = -1
mainNode = -1 mainNode = -1
mainNode_sinonims = [] mainNode_sinonims = []
for node in c: for node in clique:
groups["nodes"][node] = "nom_"+str(node)
node_outdeg = DG.out_degree(node) node_outdeg = DG.out_degree(node)
if node_outdeg>max_deg: if node_outdeg>max_deg:
max_deg = node_outdeg max_deg = node_outdeg
mainNode = node mainNode = node
for node in c: for node in clique:
if mainNode!=node: if mainNode!=node:
mainNode_sinonims.append( node ) mainNode_sinonims.append( node )
groups[ int(mainNode) ] = mainNode_sinonims groups["links"][ mainNode ] = mainNode_sinonims
return JsonHttpResponse(groups) return JsonHttpResponse(groups)
......
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