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
094ca259
Commit
094ca259
authored
Nov 30, 2015
by
delanoe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FEAT] Graph visualization improved. Bridgeness score implemented.
parent
18fb1332
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
15 deletions
+57
-15
functions.py
analysis/functions.py
+51
-14
graph.py
rest_v1_0/graph.py
+2
-1
menu.html
templates/corpus/menu.html
+4
-0
No files found.
analysis/functions.py
View file @
094ca259
...
...
@@ -15,7 +15,7 @@ from analysis.cooccurrences import do_cooc
from
analysis.distance
import
do_distance
import
pandas
as
pd
from
copy
import
copy
from
copy
import
copy
,
deepcopy
import
numpy
as
np
import
scipy
import
networkx
as
nx
...
...
@@ -34,6 +34,7 @@ def get_cooc(request=None, corpus=None
,
start
=
None
,
end
=
None
,
hapax
=
1
,
distance
=
'conditional'
,
bridgeness
=
5
):
'''
get_ccoc : to compute the graph.
...
...
@@ -60,7 +61,6 @@ def get_cooc(request=None, corpus=None
G
,
partition
,
ids
,
weight
=
do_distance
(
cooc_id
,
field1
=
"ngrams"
,
field2
=
"ngrams"
,
isMonopartite
=
True
,
distance
=
distance
)
if
type
==
"node_link"
:
nodesB_dict
=
{}
for
node_id
in
G
.
nodes
():
...
...
@@ -68,9 +68,9 @@ def get_cooc(request=None, corpus=None
#node,type(labels[node])
G
.
node
[
node_id
][
'pk'
]
=
ids
[
node_id
][
1
]
nodesB_dict
[
ids
[
node_id
][
1
]
]
=
True
# TODO the query below is not optimized (do it do_distance).
the_label
=
session
.
query
(
Ngram
.
terms
)
.
filter
(
Ngram
.
id
==
node_id
)
.
first
()
the_label
=
", "
.
join
(
the_label
)
# TODO the query below is not optimized (do it do_distance).
G
.
node
[
node_id
][
'label'
]
=
the_label
G
.
node
[
node_id
][
'size'
]
=
weight
[
node_id
]
...
...
@@ -81,25 +81,62 @@ def get_cooc(request=None, corpus=None
pass
#PrintException()
#print("error01: ",error)
B
=
json_graph
.
node_link_data
(
G
)
links
=
[]
i
=
1
if
bridgeness
>
0
:
com_link
=
defaultdict
(
lambda
:
defaultdict
(
list
))
com_ids
=
defaultdict
(
list
)
for
k
,
v
in
partition
.
items
():
com_ids
[
v
]
.
append
(
k
)
for
e
in
G
.
edges_iter
():
s
=
e
[
0
]
t
=
e
[
1
]
info
=
{
"s"
:
ids
[
s
][
1
]
,
"t"
:
ids
[
t
][
1
]
,
"w"
:
G
[
ids
[
s
][
1
]][
ids
[
t
][
1
]][
"weight"
]
}
# print(info)
links
.
append
(
info
)
i
+=
1
# print(B)
weight
=
G
[
ids
[
s
][
1
]][
ids
[
t
][
1
]][
"weight"
]
if
bridgeness
<
0
:
info
=
{
"s"
:
ids
[
s
][
1
]
,
"t"
:
ids
[
t
][
1
]
,
"w"
:
weight
}
links
.
append
(
info
)
else
:
if
partition
[
s
]
==
partition
[
t
]:
info
=
{
"s"
:
ids
[
s
][
1
]
,
"t"
:
ids
[
t
][
1
]
,
"w"
:
weight
}
links
.
append
(
info
)
if
bridgeness
>
0
:
if
partition
[
s
]
<
partition
[
t
]:
com_link
[
partition
[
s
]][
partition
[
t
]]
.
append
((
s
,
t
,
weight
))
if
bridgeness
>
0
:
for
c1
in
com_link
.
keys
():
for
c2
in
com_link
[
c1
]
.
keys
():
index
=
round
(
bridgeness
*
len
(
com_link
[
c1
][
c2
])
/
(
len
(
com_ids
[
c1
])
+
len
(
com_ids
[
c2
])))
#print((c1,len(com_ids[c1])), (c2,len(com_ids[c2])), index)
if
index
>
0
:
for
link
in
sorted
(
com_link
[
c1
][
c2
],
key
=
lambda
x
:
x
[
2
],
reverse
=
True
)[:
index
]:
#print(c1, c2, link[2])
info
=
{
"s"
:
link
[
0
],
"t"
:
link
[
1
],
"w"
:
link
[
2
]}
links
.
append
(
info
)
B
=
json_graph
.
node_link_data
(
G
)
B
[
"links"
]
=
[]
B
[
"links"
]
=
links
if
field1
==
field2
==
'ngrams'
:
data
[
"nodes"
]
=
B
[
"nodes"
]
data
[
"links"
]
=
B
[
"links"
]
...
...
rest_v1_0/graph.py
View file @
094ca259
...
...
@@ -23,6 +23,7 @@ class Graph(APIView):
type_
=
request
.
GET
.
get
(
'type'
,
'node_link'
)
hapax
=
request
.
GET
.
get
(
'hapax'
,
1
)
distance
=
request
.
GET
.
get
(
'distance'
,
'conditional'
)
bridgeness
=
int
(
request
.
GET
.
get
(
'bridgeness'
,
-
1
))
corpus
=
session
.
query
(
Node
)
.
filter
(
Node
.
id
==
corpus_id
)
.
first
()
...
...
@@ -39,7 +40,7 @@ class Graph(APIView):
,
hapax
=
hapax
,
distance
=
distance
)
else
:
data
=
get_cooc
(
corpus
=
corpus
,
field1
=
field1
,
field2
=
field2
,
hapax
=
hapax
,
distance
=
distance
)
,
hapax
=
hapax
,
distance
=
distance
,
bridgeness
=
bridgeness
)
if
format_
==
'json'
:
return
JsonHttpResponse
(
data
)
else
:
...
...
templates/corpus/menu.html
View file @
094ca259
...
...
@@ -93,6 +93,10 @@
<h3>
Networks
</h3>
<ol>
<li
data-url=
"/project/{{project.id}}/corpus/{{ corpus.id }}/explorer?field1=ngrams&field2=ngrams"
onclick=
'gotoexplorer(this)'
><a>
Terms
</a></li>
<ul>
<li
data-url=
"/project/{{project.id}}/corpus/{{ corpus.id }}/explorer?field1=ngrams&field2=ngrams&distance=distributional&bridgeness=5"
onclick=
'gotoexplorer(this)'
><a>
Macro
</a></li>
<li
data-url=
"/project/{{project.id}}/corpus/{{ corpus.id }}/explorer?field1=ngrams&field2=ngrams&distance=conditional&bridgeness=5"
onclick=
'gotoexplorer(this)'
><a>
Macro
</a></li>
</ul>
<li
data-url=
"/project/{{project.id}}/corpus/{{ corpus.id }}/explorer?field1=journal&field2=ngrams"
onclick=
'gotoexplorer(this)'
><a>
Journals and Terms
</a></li>
<li>
Authors and Terms
</li>
</ol>
...
...
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