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
d6b0a4fa
Commit
d6b0a4fa
authored
May 05, 2016
by
delanoe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FEAT] Integration distance, need to change the measure of diff between graphs.
parent
a5449bd7
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
173 additions
and
35 deletions
+173
-35
intersection.py
graphExplorer/intersection.py
+117
-0
extras_explorerjs.js
static/js/graphExplorer/extras_explorerjs.js
+56
-35
No files found.
graphExplorer/intersection.py
0 → 100644
View file @
d6b0a4fa
from
gargantext.models
import
Node
,
Ngram
,
NodeNgram
,
NodeNgramNgram
,
\
NodeHyperdata
,
HyperdataKey
from
gargantext.util.db
import
session
,
aliased
,
bulk_insert
,
func
from
gargantext.util.lists
import
WeightedMatrix
,
UnweightedList
,
Translations
from
gargantext.util.http
import
JsonHttpResponse
from
sqlalchemy
import
desc
,
asc
,
or_
,
and_
import
datetime
def
getCorpusIntersection
(
request
,
corpuses_ids
):
FinalDict
=
False
if
request
.
method
==
'POST'
and
"nodeids"
in
request
.
POST
and
len
(
request
.
POST
[
"nodeids"
])
>
0
:
import
ast
import
networkx
as
nx
node_ids
=
[
int
(
i
)
for
i
in
(
ast
.
literal_eval
(
request
.
POST
[
"nodeids"
]
))
]
# Here are the visible nodes of the initial semantic map.
corpuses_ids
=
corpuses_ids
.
split
(
'a'
)
corpuses_ids
=
[
int
(
i
)
for
i
in
corpuses_ids
]
print
(
corpuses_ids
)
# corpus[1] will be the corpus to compare
def
get_score
(
corpus_id
):
cooc_ids
=
(
session
.
query
(
Node
.
id
)
.
filter
(
Node
.
user_id
==
request
.
user
.
id
,
Node
.
parent_id
==
corpus_id
,
Node
.
typename
==
'COOCCURRENCES'
)
.
first
()
)
if
len
(
cooc_ids
)
==
0
:
return
JsonHttpResponse
(
FinalDict
)
# If corpus[1] has a coocurrence.id then lets continue
Coocs
=
{}
G
=
nx
.
Graph
()
# undirected graph only
# because direction doesnt matter here
# coocs is triangular matrix
ngrams_data
=
(
session
.
query
(
NodeNgramNgram
)
.
filter
(
NodeNgramNgram
.
node_id
==
cooc_ids
[
0
]
,
or_
(
NodeNgramNgram
.
ngram1_id
.
in_
(
node_ids
)
,
NodeNgramNgram
.
ngram2_id
.
in_
(
node_ids
)
)
)
.
group_by
(
NodeNgramNgram
)
.
all
()
)
for
ngram
in
ngrams_data
:
# are there visible nodes in the X-axis of corpus to compare ?
G
.
add_edge
(
ngram
.
ngram1_id
,
ngram
.
ngram2_id
,
weight
=
ngram
.
weight
)
print
(
corpus_id
,
ngram
)
for
e
in
G
.
edges_iter
()
:
n1
=
e
[
0
]
n2
=
e
[
1
]
# print( G[n1][n2]["weight"] , "\t", n1,",",n2 )
if
n1
not
in
Coocs
:
Coocs
[
n1
]
=
0
if
n2
not
in
Coocs
:
Coocs
[
n2
]
=
0
Coocs
[
n1
]
+=
G
[
n1
][
n2
][
"weight"
]
Coocs
[
n2
]
+=
G
[
n1
][
n2
][
"weight"
]
return
(
Coocs
,
G
)
Coocs_0
,
G_0
=
get_score
(
corpuses_ids
[
0
]
)
Coocs_1
,
G_1
=
get_score
(
corpuses_ids
[
1
]
)
FinalDict
=
{}
measure
=
'cooc'
if
measure
==
'jacquard'
:
for
node
in
node_ids
:
if
node
in
G_1
.
nodes
()
and
node
in
G_0
.
nodes
():
neighbors_0
=
set
(
G_0
.
neighbors
(
node
))
neighbors_1
=
set
(
G_1
.
neighbors
(
node
))
jacquard
=
len
(
neighbors_0
.
intersection
(
neighbors_1
))
/
len
(
neighbors_0
.
union
(
neighbors_1
))
FinalDict
[
node
]
=
jacquard
*
3
elif
node
in
G_0
.
nodes
()
and
node
not
in
G_1
.
nodes
()
:
FinalDict
[
node
]
=
2
elif
node
not
in
G_0
.
nodes
()
and
node
in
G_1
.
nodes
()
:
FinalDict
[
node
]
=
1
else
:
FinalDict
[
node
]
=
0
elif
measure
==
'cooc'
:
for
node
in
node_ids
:
if
node
in
G_1
.
nodes
()
and
node
in
G_0
.
nodes
():
score_0
=
Coocs_0
[
node
]
/
G_0
.
degree
(
node
)
score_1
=
Coocs_1
[
node
]
/
G_1
.
degree
(
node
)
FinalDict
[
node
]
=
5
*
score_0
/
score_1
elif
node
in
G_0
.
nodes
()
and
node
not
in
G_1
.
nodes
()
:
FinalDict
[
node
]
=
0.5
elif
node
not
in
G_0
.
nodes
()
and
node
in
G_1
.
nodes
()
:
FinalDict
[
node
]
=
0.2
else
:
FinalDict
[
node
]
=
0
print
(
FinalDict
)
#print(node,score)
# Getting AVG-COOC of each ngram that exists in the cooc-matrix of the compared-corpus.
return
JsonHttpResponse
(
FinalDict
)
static/js/graphExplorer/extras_explorerjs.js
View file @
d6b0a4fa
...
@@ -671,7 +671,7 @@ function getCookie(name) {
...
@@ -671,7 +671,7 @@ function getCookie(name) {
// Just for Garg
// Just for Garg
function
printCorpuses
()
{
function
printCorpuses
()
{
console
.
clear
()
console
.
clear
()
console
.
log
(
"!!!!!!!!
in printCorpuses()
!!!!!!!! "
)
console
.
log
(
"!!!!!!!!
Corpus chosen, going to make the diff
!!!!!!!! "
)
pr
(
corpusesList
)
pr
(
corpusesList
)
var
selected
=
$
(
'input[name=optradio]:checked'
)[
0
].
id
.
split
(
"_"
)
var
selected
=
$
(
'input[name=optradio]:checked'
)[
0
].
id
.
split
(
"_"
)
...
@@ -680,18 +680,18 @@ function printCorpuses() {
...
@@ -680,18 +680,18 @@ function printCorpuses() {
var
pageurl
=
window
.
location
.
href
.
split
(
"/"
)
var
pageurl
=
window
.
location
.
href
.
split
(
"/"
)
var
cid
;
var
cid
;
for
(
var
i
in
pageurl
)
{
for
(
var
i
in
pageurl
)
{
if
(
pageurl
[
i
]
==
"corp
us
"
)
{
if
(
pageurl
[
i
]
==
"corp
ora
"
)
{
cid
=
parseInt
(
i
);
cid
=
parseInt
(
i
);
break
;
break
;
}
}
}
}
var
current_corpus
=
pageurl
[
cid
+
1
];
var
current_corpus
=
pageurl
[
cid
+
1
];
pr
(
"corpus id, selected: "
+
corpusesList
[
sel_p
][
"corpuses"
][
sel_c
][
"id"
]
)
pr
(
"corpus id, selected: "
+
sel_c
)
pr
(
"current corpus: "
+
current_corpus
)
pr
(
"current corpus: "
+
current_corpus
)
var
the_ids
=
[]
var
the_ids
=
[]
the_ids
.
push
(
current_corpus
)
the_ids
.
push
(
current_corpus
)
the_ids
.
push
(
corpusesList
[
sel_p
][
"corpuses"
][
sel_c
][
"id"
]
)
the_ids
.
push
(
sel_c
)
$
(
"#closecorpuses"
).
click
();
$
(
"#closecorpuses"
).
click
();
...
@@ -702,7 +702,7 @@ function printCorpuses() {
...
@@ -702,7 +702,7 @@ function printCorpuses() {
console
.
log
(
thenodes
)
console
.
log
(
thenodes
)
$
.
ajax
({
$
.
ajax
({
type
:
'GET'
,
type
:
'GET'
,
url
:
window
.
location
.
origin
+
'/
api/corpus
intersection/'
+
the_ids
.
join
(
"a"
),
url
:
window
.
location
.
origin
+
'/
explorer/
intersection/'
+
the_ids
.
join
(
"a"
),
data
:
"nodeids="
+
JSON
.
stringify
(
thenodes
),
data
:
"nodeids="
+
JSON
.
stringify
(
thenodes
),
type
:
'POST'
,
type
:
'POST'
,
beforeSend
:
function
(
xhr
)
{
beforeSend
:
function
(
xhr
)
{
...
@@ -720,7 +720,7 @@ function printCorpuses() {
...
@@ -720,7 +720,7 @@ function printCorpuses() {
cancelSelection
(
false
)
cancelSelection
(
false
)
ChangeGraphAppearanceByAtt
(
true
)
ChangeGraphAppearanceByAtt
(
true
)
console
.
log
(
"
YOLOYOLYOLYOYKOYYKYOY
"
)
console
.
log
(
"
Getting the clusters
"
)
clustersBy
(
"inter"
,
"color"
)
clustersBy
(
"inter"
,
"color"
)
clustersBy
(
"inter"
,
"size"
)
clustersBy
(
"inter"
,
"size"
)
...
@@ -814,44 +814,65 @@ function GetUserPortfolio() {
...
@@ -814,44 +814,65 @@ function GetUserPortfolio() {
if
(
Object
.
keys
(
corpusesList
).
length
>
0
)
if
(
Object
.
keys
(
corpusesList
).
length
>
0
)
return
true
;
return
true
;
var
query_url
=
window
.
location
.
origin
+
'/api/
userportfolio/project/'
+
project_id
+
'/corpuses
'
var
query_url
=
window
.
location
.
origin
+
'/api/
nodes?types[]=PROJECT&types[]=CORPUS&pagination_limit=100
'
$
.
ajax
({
$
.
ajax
({
type
:
'GET'
,
type
:
'GET'
,
dataType
:
'JSON'
,
url
:
query_url
,
url
:
query_url
,
success
:
function
(
data
)
{
success
:
function
(
data
)
{
var
html_
=
""
var
html_
=
""
var
portfolio
=
{}
html_
+=
'<div class="panel-group" id="accordion">'
+
"
\n
"
html_
+=
'<div class="panel-group" id="accordion">'
+
"
\n
"
html_
+=
' <form id="corpuses_form" role="form">'
+
"
\n
"
html_
+=
' <form id="corpuses_form" role="form">'
+
"
\n
"
corpusesList
=
data
;
for
(
var
record
in
data
[
"records"
])
{
for
(
var
k1
in
data
)
{
console
.
log
(
" ici le record "
+
record
)
var
v1
=
data
[
k1
]
if
(
data
[
"records"
][
record
][
"typename"
]
===
'PROJECT'
)
{
var
project_id
=
data
[
"records"
][
record
][
"id"
]
var
project_name
=
data
[
"records"
][
record
][
"name"
]
portfolio
[
project_id
]
=
project_name
html_
+=
' <div class="panel panel-default">'
+
"
\n
"
html_
+=
' <div class="panel panel-default">'
+
"
\n
"
html_
+=
' <div class="panel-heading">'
+
"
\n
"
html_
+=
' <div class="panel-heading">'
+
"
\n
"
html_
+=
' <h4 class="panel-title">'
+
"
\n
"
html_
+=
' <h4 class="panel-title">'
+
"
\n
"
html_
+=
' <a data-toggle="collapse" data-parent="#accordion" href="#collapse_'
+
k1
+
'">'
+
v1
[
"proj_name"
]
+
'</a>'
+
"
\n
"
html_
+=
' <a data-toggle="collapse" data-parent="#accordion" href="#collapse_'
+
project_id
+
'">'
+
project_name
+
'</a>'
+
"
\n
"
html_
+=
' </h4>'
+
"
\n
"
html_
+=
' </h4>'
+
"
\n
"
html_
+=
' </div>'
+
"
\n
"
html_
+=
' </div>'
+
"
\n
"
html_
+=
' <div id="collapse_'
+
k1
+
'" class="panel-collapse collapse">'
+
"
\n
"
html_
+=
' <div id="collapse_'
+
project_id
+
'" class="panel-collapse collapse">'
+
"
\n
"
html_
+=
' <div class="panel-body" style="input[type=radio] {display: none;}">'
+
"
\n
"
html_
+=
' <div class="panel-body" style="input[type=radio] {display: none;}">'
+
"
\n
"
html_
+=
' <ul>'
+
"
\n
"
html_
+=
' <ul>'
+
"
\n
"
for
(
var
c
in
v1
[
"corpuses"
])
{
var
Ci
=
v1
[
"corpuses"
][
c
]
for
(
var
record2
in
data
[
"records"
])
{
if
(
Ci
[
"id"
]
!=
corpus_id
)
{
if
(
data
[
"records"
][
record2
][
"typename"
]
==
'CORPUS'
)
{
var
corpus_parent_id
=
data
[
"records"
][
record2
][
"parent_id"
]
if
(
corpus_parent_id
!==
null
)
{
if
(
corpus_parent_id
==
project_id
)
{
var
corpus_id
=
data
[
"records"
][
record2
][
"id"
]
var
corpus_name
=
data
[
"records"
][
record2
][
"name"
]
portfolio
[
corpus_id
]
=
corpus_name
html_
+=
' <li>'
+
"
\n
"
html_
+=
' <li>'
+
"
\n
"
html_
+=
' <div class="radio">'
+
"
\n
"
html_
+=
' <div class="radio">'
+
"
\n
"
html_
+=
' <label><input type="radio" id="'
+
k1
+
"_"
+
c
+
'" name="optradio">'
+
"
\n
"
html_
+=
' <label><input type="radio" id="'
+
project_id
+
"_"
+
corpus_id
+
'" name="optradio">'
+
"
\n
"
html_
+=
' <a target="_blank" href="/project/'
+
k1
+
'/corpus/'
+
Ci
[
"id"
]
+
'/">'
+
Ci
[
"name"
]
+
' ('
+
Ci
[
"c"
]
+
' docs.)
</a>'
+
"
\n
"
html_
+=
' <a target="_blank" href="/projects/'
+
project_id
+
'/corpora/'
+
corpus_id
+
'/">'
+
corpus_name
+
'
</a>'
+
"
\n
"
html_
+=
' </label>'
+
"
\n
"
html_
+=
' </label>'
+
"
\n
"
html_
+=
' </div>'
+
"
\n
"
html_
+=
' </div>'
+
"
\n
"
html_
+=
' </li>'
+
"
\n
"
html_
+=
' </li>'
+
"
\n
"
}
}
}
}
}
}
html_
+=
' </ul>'
+
"
\n
"
html_
+=
' </ul>'
+
"
\n
"
html_
+=
' </div>'
+
"
\n
"
html_
+=
' </div>'
+
"
\n
"
html_
+=
' </div>'
+
"
\n
"
html_
+=
' </div>'
+
"
\n
"
html_
+=
' </div>'
+
"
\n
"
html_
+=
' </div>'
+
"
\n
"
}
}
}
html_
+=
' </form>'
+
"
\n
"
html_
+=
' </form>'
+
"
\n
"
html_
+=
'</div>'
+
"
\n
"
html_
+=
'</div>'
+
"
\n
"
...
@@ -860,8 +881,8 @@ function GetUserPortfolio() {
...
@@ -860,8 +881,8 @@ function GetUserPortfolio() {
$
(
'#corpuses_form input:radio'
).
change
(
function
()
{
$
(
'#corpuses_form input:radio'
).
change
(
function
()
{
$
(
"#add_corpus_tab"
).
prop
(
"disabled"
,
false
)
$
(
"#add_corpus_tab"
).
prop
(
"disabled"
,
false
)
var
selected
=
$
(
'input[name=optradio]:checked'
)[
0
].
id
.
split
(
"_"
)
var
selected
=
$
(
'input[name=optradio]:checked'
)[
0
].
id
.
split
(
"_"
)
var
sel_p
=
selected
[
0
],
sel_c
=
selected
[
1
]
var
sel_p
_id
=
selected
[
0
],
sel_c_id
=
selected
[
1
]
$
(
"#selected_corpus"
).
html
(
"<center>"
+
data
[
sel_p
][
"proj_name"
]
+
" , "
+
data
[
sel_p
][
"corpuses"
][
sel_c
][
"name"
]
+
"</center><br>"
)
$
(
"#selected_corpus"
).
html
(
"<center>"
+
portfolio
[
sel_p_id
]
+
" , "
+
portfolio
[
sel_c_id
]
+
"</center><br>"
)
});
});
...
...
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