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
3e5ae6d9
Commit
3e5ae6d9
authored
Nov 12, 2015
by
delanoe
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'samuel' into unstable
parents
4ba68550
99f83f61
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
79 additions
and
94 deletions
+79
-94
ngrams.py
rest_v1_0/ngrams.py
+69
-66
NGrams_dyna_chart_and_table.js
static/js/NGrams_dyna_chart_and_table.js
+10
-28
No files found.
rest_v1_0/ngrams.py
View file @
3e5ae6d9
...
...
@@ -346,73 +346,76 @@ class Group(APIView):
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
)
.
filter
(
NodeNgramNgram
.
node_id
==
existing_group_id
)
)
# [ - - - new group = old clique + new clique - - - ] #
Clique_Changes
=
{}
Rels_2_delete
=
{}
for
ng
in
grouped_ngrams
:
for
i
in
range
(
len
(
GDict
)):
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()
import
pprint
pprint
.
pprint
(
GDict
)
# existing_group_id = self.get_group_id(corpus_id)
# grouped_ngrams = (session
# .query(NodeNgramNgram)
# .filter(NodeNgramNgram.node_id==existing_group_id)
# )
# # [ - - - new group = old clique + new clique - - - ] #
# NewGroups = {}
# Rels_2_delete = {}
# 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("= = = = = = = = = = = = = = ")
# print(ng)
# for i in range(len(GDict)):
# 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 NewGroups:
# NewGroups[i] = {}
# for node in clique_i:
# NewGroups[i][node] = True
# for i in NewGroups:
# NewGroups[i] = list(NewGroups[i].keys())
# # [ - - - / 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
)
class
Keep
(
APIView
):
...
...
static/js/NGrams_dyna_chart_and_table.js
View file @
3e5ae6d9
...
...
@@ -514,40 +514,22 @@ $("#Save_All").click(function(){
var
list_id
=
$
(
"#list_id"
).
val
()
var
corpus_id
=
getIDFromURL
(
"corpus"
)
// not used
// CRUD( list_id , "" , nodes_2del , "DELETE" )
// CRUD( list_id , "/keep" , nodes_2keep , "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
)
}
});
CRUD
(
list_id
,
""
,
nodes_2del
,
[]
,
"DELETE"
)
CRUD
(
list_id
,
"/keep"
,
nodes_2keep
,
[]
,
"PUT"
)
CRUD
(
corpus_id
,
"/group"
,
[]
,
nodes_2group
,
"PUT"
)
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
(
"+"
);
if
(
nodes
.
length
>
0
)
{
the_url
=
the_url
.
replace
(
/
\/
$/
,
""
);
//remove trailing slash
if
(
nodes
.
length
>
0
||
Object
.
keys
(
args
).
length
>
0
)
{
$
.
ajax
({
method
:
http_method
,
url
:
the_url
,
data
:
args
,
beforeSend
:
function
(
xhr
)
{
xhr
.
setRequestHeader
(
"X-CSRFToken"
,
getCookie
(
"csrftoken"
));
},
...
...
@@ -617,7 +599,7 @@ function Main_test( data , initial) {
var
node_info
=
{
"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,
"flag"
:
false
,
"group_plus"
:
true
,
...
...
@@ -842,7 +824,7 @@ $.when(
// Deleting subforms from the ngrams-table, clean start baby!
if
(
Object
.
keys
(
ngrams_groups
.
links
).
length
>
0
)
{
var
_forms
=
{
"main"
:{}
,
"sub"
:{}
}
for
(
var
i
in
ngrams_groups
.
links
)
{
_forms
[
"main"
][
i
]
=
true
...
...
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