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
331bbfe4
Commit
331bbfe4
authored
Nov 04, 2015
by
PkSM3
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[UPDATE] GET groups as dictionary using DG and G
parent
a2acaa19
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
57 deletions
+55
-57
ngrams.py
rest_v1_0/ngrams.py
+47
-24
NGrams_dyna_chart_and_table.js
static/js/NGrams_dyna_chart_and_table.js
+8
-33
No files found.
rest_v1_0/ngrams.py
View file @
331bbfe4
...
@@ -223,7 +223,7 @@ class Group(APIView):
...
@@ -223,7 +223,7 @@ class Group(APIView):
REST API to manage groups of Ngrams
REST API to manage groups of Ngrams
Groups can be synonyms, a cathegory or ngrams groups with stems or lems.
Groups can be synonyms, a cathegory or ngrams groups with stems or lems.
'''
'''
def
get_group_id
(
node_id
):
def
get_group_id
(
self
,
node_id
):
node_id
=
int
(
node_id
)
node_id
=
int
(
node_id
)
corpus
=
session
.
query
(
Node
)
.
filter
(
Node
.
id
==
node_id
)
.
first
()
corpus
=
session
.
query
(
Node
)
.
filter
(
Node
.
id
==
node_id
)
.
first
()
group
=
get_or_create_node
(
corpus
=
corpus
,
nodetype
=
'Group'
)
group
=
get_or_create_node
(
corpus
=
corpus
,
nodetype
=
'Group'
)
...
@@ -231,35 +231,58 @@ class Group(APIView):
...
@@ -231,35 +231,58 @@ class Group(APIView):
def
get
(
self
,
request
,
corpus_id
):
def
get
(
self
,
request
,
corpus_id
):
# query ngrams
# query ngrams
group_id
=
get_group_id
(
corpus_id
)
group_id
=
self
.
get_group_id
(
corpus_id
)
#api/node/$corpus_id/ngrams?ngram_id=12
#api/node/$corpus_id/ngrams?ngram_id=12
ngram_id
=
request
.
GET
.
get
(
'ngram_id'
,
False
)
# ngram_id = 1 #request.GET.get('ngram_id', False)
ngram_id
=
int
(
node_id
)
# ngram_id = int(node_id)
# #api/node/$corpus_id/ngrams?all=True
# all_option = request.GET.get('all', False)
# all_option = 1 #int(all_option)
#api/node/$corpus_id/ngrams?all=True
all_option
=
request
.
GET
.
get
(
'all'
,
False
)
all_option
=
int
(
all_option
)
# IMPORTANT: Algorithm for getting the groups:
# 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
if
ngram_id
>
0
or
all_option
==
1
:
import
networkx
as
nx
G
=
nx
.
Graph
()
DG
=
nx
.
DiGraph
()
ngrams_ngrams
=
(
session
ngrams_ngrams
=
(
session
.
query
(
NodeNgramNgram
)
.
query
(
NodeNgramNgram
)
.
filter
(
NodeNgramNgram
.
node_id
==
group_id
)
.
filter
(
NodeNgramNgram
.
node_id
==
group_id
)
)
)
# ngramy_id=476996, score=1.0, node_id=75081, id=1282846, ngramx_id=493431
if
ngram_id
>
0
:
for
ng
in
ngrams_ngrams
:
ngrams_ngrams
=
ngrams_ngrams
.
filter
(
NodeNgramNgram
.
ngramx_id
==
ngram_id
)
# n_x = ( session.query(Ngram).filter(Ngram.id==ng.ngramx_id) ).first()
# n_y = ( session.query(Ngram).filter(Ngram.id==ng.ngramy_id) ).first()
else
:
G
.
add_edge
(
ng
.
ngramx_id
,
ng
.
ngramy_id
)
raise
APIException
(
'Missing parameter: "ngram_id" as Integer'
,
400
)
DG
.
add_edge
(
ng
.
ngramx_id
,
ng
.
ngramy_id
)
group
=
dict
(
list
())
# group = dict(list())
sinonims_cliques
=
nx
.
find_cliques
(
G
)
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]
return
JsonHttpResponse
(
group
)
groups
=
{}
for
c
in
sinonims_cliques
:
max_deg
=
-
1
mainNode
=
-
1
mainNode_sinonims
=
[]
for
node
in
c
:
node_outdeg
=
DG
.
out_degree
(
node
)
if
node_outdeg
>
max_deg
:
max_deg
=
node_outdeg
mainNode
=
node
for
node
in
c
:
if
mainNode
!=
node
:
mainNode_sinonims
.
append
(
node
)
groups
[
int
(
mainNode
)
]
=
mainNode_sinonims
return
JsonHttpResponse
(
groups
)
def
post
(
self
,
request
,
node_id
):
def
post
(
self
,
request
,
node_id
):
...
...
static/js/NGrams_dyna_chart_and_table.js
View file @
331bbfe4
...
@@ -209,6 +209,7 @@ function getRecords() {
...
@@ -209,6 +209,7 @@ function getRecords() {
return
MyTable
.
data
(
'dynatable'
).
settings
.
dataset
.
originalRecords
;
return
MyTable
.
data
(
'dynatable'
).
settings
.
dataset
.
originalRecords
;
}
}
// new
function
group_mode
(
elem
)
{
function
group_mode
(
elem
)
{
GState
=
1
GState
=
1
var
elem_id
=
$
(
elem
).
data
(
"stuff"
)
var
elem_id
=
$
(
elem
).
data
(
"stuff"
)
...
@@ -226,6 +227,7 @@ function group_mode ( elem ) {
...
@@ -226,6 +227,7 @@ function group_mode ( elem ) {
MyTable
.
data
(
'dynatable'
).
dom
.
update
();
MyTable
.
data
(
'dynatable'
).
dom
.
update
();
}
}
// new
function
SaveSinonims
(
gheader
,
gcontent
)
{
function
SaveSinonims
(
gheader
,
gcontent
)
{
console
.
log
(
"GHEADER:"
)
console
.
log
(
"GHEADER:"
)
$
(
gheader
).
children
(
'span'
).
each
(
function
()
{
$
(
gheader
).
children
(
'span'
).
each
(
function
()
{
...
@@ -237,6 +239,7 @@ function SaveSinonims( gheader , gcontent) {
...
@@ -237,6 +239,7 @@ function SaveSinonims( gheader , gcontent) {
});
});
}
}
// new
$
(
'#group_box_content'
).
bind
(
"DOMSubtreeModified"
,
function
(){
$
(
'#group_box_content'
).
bind
(
"DOMSubtreeModified"
,
function
(){
console
.
log
(
$
(
this
).
has
(
"span"
).
length
)
console
.
log
(
$
(
this
).
has
(
"span"
).
length
)
var
groupdiv
=
"#group_box"
var
groupdiv
=
"#group_box"
...
@@ -257,6 +260,7 @@ $('#group_box_content').bind("DOMSubtreeModified",function(){
...
@@ -257,6 +260,7 @@ $('#group_box_content').bind("DOMSubtreeModified",function(){
}
}
})
})
// new
function
add2group
(
elem
)
{
function
add2group
(
elem
)
{
var
elem_id
=
$
(
elem
).
data
(
"stuff"
)
var
elem_id
=
$
(
elem
).
data
(
"stuff"
)
...
@@ -285,6 +289,7 @@ function add2group ( elem ) {
...
@@ -285,6 +289,7 @@ function add2group ( elem ) {
MyTable
.
data
(
'dynatable'
).
dom
.
update
();
MyTable
.
data
(
'dynatable'
).
dom
.
update
();
}
}
// new
function
clickngram_action
(
elem
)
{
function
clickngram_action
(
elem
)
{
var
elem_id
=
$
(
elem
).
data
(
"stuff"
)
var
elem_id
=
$
(
elem
).
data
(
"stuff"
)
AjaxRecords
[
elem_id
].
state
=
(
AjaxRecords
[
elem_id
].
state
==
(
System
[
0
][
"states"
].
length
-
2
))?
0
:(
AjaxRecords
[
elem_id
].
state
+
1
);
AjaxRecords
[
elem_id
].
state
=
(
AjaxRecords
[
elem_id
].
state
==
(
System
[
0
][
"states"
].
length
-
2
))?
0
:(
AjaxRecords
[
elem_id
].
state
+
1
);
...
@@ -292,6 +297,7 @@ function clickngram_action ( elem ) {
...
@@ -292,6 +297,7 @@ function clickngram_action ( elem ) {
MyTable
.
data
(
'dynatable'
).
dom
.
update
();
MyTable
.
data
(
'dynatable'
).
dom
.
update
();
}
}
// modified
function
transformContent
(
rec_id
)
{
function
transformContent
(
rec_id
)
{
var
elem
=
AjaxRecords
[
rec_id
];
var
elem
=
AjaxRecords
[
rec_id
];
var
result
=
{}
var
result
=
{}
...
@@ -301,7 +307,7 @@ function transformContent(rec_id) {
...
@@ -301,7 +307,7 @@ function transformContent(rec_id) {
plus_event
=
" <a class=
\"
plusclass
\"
onclick=
\"
group_mode(this.parentNode.parentNode)
\"
>(+)</a>"
plus_event
=
" <a class=
\"
plusclass
\"
onclick=
\"
group_mode(this.parentNode.parentNode)
\"
>(+)</a>"
if
(
GState
==
1
)
{
if
(
GState
==
1
)
{
if
(
elem
.
state
!=
1
&&
elem
.
state
!=
3
)
{
// if deleted and already grouped, no Up button
if
(
elem
.
state
!=
1
&&
elem
.
state
!=
3
)
{
// if deleted and already grouped, no Up button
plus_event
=
" <a class=
\"
plusclass
\"
onclick=
\"
add2group(this.parentNode.parentNode)
\"
>(
↑
)</a>"
plus_event
=
" <a class=
\"
plusclass
\"
onclick=
\"
add2group(this.parentNode.parentNode)
\"
>(
▲
)</a>"
}
}
}
}
result
[
"id"
]
=
elem
[
"id"
]
result
[
"id"
]
=
elem
[
"id"
]
...
@@ -389,11 +395,6 @@ function Mark_NGram( ngram_id , old_flag , new_flag ) {
...
@@ -389,11 +395,6 @@ function Mark_NGram( ngram_id , old_flag , new_flag ) {
return
new_flag
;
return
new_flag
;
}
}
function
GroupNGrams
()
{
for
(
var
i
in
FlagsBuffer
[
"to_group"
]){
console
.
log
(
AjaxRecords
[
i
]
)
}
}
//generic enough
//generic enough
function
ulWriter
(
rowIndex
,
record
,
columns
,
cellWriter
)
{
function
ulWriter
(
rowIndex
,
record
,
columns
,
cellWriter
)
{
...
@@ -414,6 +415,7 @@ function ulWriter(rowIndex, record, columns, cellWriter) {
...
@@ -414,6 +415,7 @@ function ulWriter(rowIndex, record, columns, cellWriter) {
}
}
function
SelectAll
(
the_checkbox
)
{
function
SelectAll
(
the_checkbox
)
{
console
.
log
(
the_checkbox
)
var
current_flag
=
$
(
"input[type='radio'][name='radios']:checked"
).
val
()
var
current_flag
=
$
(
"input[type='radio'][name='radios']:checked"
).
val
()
$
(
"tbody tr"
).
each
(
function
(
i
,
row
)
{
$
(
"tbody tr"
).
each
(
function
(
i
,
row
)
{
var
id
=
$
(
row
).
data
(
'stuff'
)
var
id
=
$
(
row
).
data
(
'stuff'
)
...
@@ -739,34 +741,10 @@ function Main_test( data , initial) {
...
@@ -739,34 +741,10 @@ function Main_test( data , initial) {
}
}
function
SearchFilters
(
elem
)
{
var
MODE
=
elem
.
value
;
if
(
MODE
==
"filter_all"
)
{
var
result
=
Main_test
(
AjaxRecords
,
MODE
)
console
.
log
(
result
)
return
;
}
// if( MODE == "filter_stoplist") {
// }
// if( MODE == "filter_miamlist") {
// }
}
console
.
log
(
window
.
location
.
href
+
"/ngrams.json"
)
console
.
log
(
window
.
location
.
href
+
"/ngrams.json"
)
$
.
ajax
({
$
.
ajax
({
url
:
window
.
location
.
href
+
"/ngrams.json"
,
url
:
window
.
location
.
href
+
"/ngrams.json"
,
success
:
function
(
data
){
success
:
function
(
data
){
// Building the Score-Selector
// Building the Score-Selector
var
FirstScore
=
data
.
scores
.
initial
var
FirstScore
=
data
.
scores
.
initial
var
possible_scores
=
Object
.
keys
(
data
.
ngrams
[
0
].
scores
);
var
possible_scores
=
Object
.
keys
(
data
.
ngrams
[
0
].
scores
);
...
@@ -781,7 +759,6 @@ $.ajax({
...
@@ -781,7 +759,6 @@ $.ajax({
var
result
=
Main_test
(
data
,
FirstScore
)
var
result
=
Main_test
(
data
,
FirstScore
)
console
.
log
(
result
)
console
.
log
(
result
)
// Listener for onchange Score-Selector
// Listener for onchange Score-Selector
scores_div
+=
"<select>"
+
"
\n
"
;
scores_div
+=
"<select>"
+
"
\n
"
;
$
(
"#ScoresBox"
).
html
(
scores_div
)
$
(
"#ScoresBox"
).
html
(
scores_div
)
...
@@ -791,7 +768,5 @@ $.ajax({
...
@@ -791,7 +768,5 @@ $.ajax({
console
.
log
(
result
)
console
.
log
(
result
)
});
});
}
}
});
});
\ No newline at end of file
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