Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
humanities
gargantext
Commits
83e263f6
Commit
83e263f6
authored
Nov 04, 2015
by
PkSM3
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[UPDATE] json format for getting groups
parent
331bbfe4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
7 deletions
+8
-7
ngrams.py
rest_v1_0/ngrams.py
+8
-7
No files found.
rest_v1_0/ngrams.py
View file @
83e263f6
...
...
@@ -242,11 +242,11 @@ class Group(APIView):
# 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
# 3. DG <- Do a directed graph of pairs_list
# 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
G
=
nx
.
Graph
()
...
...
@@ -267,20 +267,21 @@ class Group(APIView):
# for nn in ngrams_ngrams.all():
# group[nn.ngramx_id] = group.get(nn.ngramx_id, []) + [nn.ngramy_id]
groups
=
{}
for
c
in
sinonims_cliques
:
groups
=
{
"nodes"
:
{}
,
"links"
:
{}
}
for
c
lique
in
sinonims_cliques
:
max_deg
=
-
1
mainNode
=
-
1
mainNode_sinonims
=
[]
for
node
in
c
:
for
node
in
clique
:
groups
[
"nodes"
][
node
]
=
"nom_"
+
str
(
node
)
node_outdeg
=
DG
.
out_degree
(
node
)
if
node_outdeg
>
max_deg
:
max_deg
=
node_outdeg
mainNode
=
node
for
node
in
c
:
for
node
in
c
lique
:
if
mainNode
!=
node
:
mainNode_sinonims
.
append
(
node
)
groups
[
int
(
mainNode
)
]
=
mainNode_sinonims
groups
[
"links"
][
mainNode
]
=
mainNode_sinonims
return
JsonHttpResponse
(
groups
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment