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
2b86f00f
Commit
2b86f00f
authored
Nov 24, 2014
by
pksm3
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
ssh://delanoe.org:1979/gargantext
into samuel
parents
ef4a79ae
79c77e3e
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
7969 additions
and
583 deletions
+7969
-583
WorkFlow2.ipynb
WorkFlow2.ipynb
+7919
-560
views.py
gargantext_web/views.py
+48
-22
menu.html
templates/menu.html
+2
-1
No files found.
WorkFlow2.ipynb
View file @
2b86f00f
This diff is collapsed.
Click to expand it.
gargantext_web/views.py
View file @
2b86f00f
...
...
@@ -140,9 +140,11 @@ def project(request, project_id):
user
=
request
.
user
date
=
datetime
.
datetime
.
now
()
type_corpus
=
NodeType
.
objects
.
get
(
name
=
'Corpus'
)
project
=
Node
.
objects
.
get
(
id
=
project_id
)
corpora
=
project
.
children
.
all
(
)
number
=
project
.
children
.
count
(
)
corpora
=
project
.
children
.
filter
(
type
=
type_corpus
)
number
=
len
(
corpora
)
# DONUT corpora representation
...
...
@@ -418,39 +420,63 @@ def json_node_link(request):
'''
Create the HttpResponse object with the graph dataset.
'''
response
=
HttpResponse
(
content_type
=
'text/json'
)
response
[
'Content-Disposition'
]
=
'attachment; filename="graph.json"'
# writer = csv.writer(response)
#
# file = open('/srv/gargantext/tests/graphsam/randomgraphgen.json', 'r')
# for line in file.readlines():
# writer.writerow(line)
matrix
=
defaultdict
(
lambda
:
defaultdict
(
float
))
cooc
=
Node
.
objects
.
get
(
id
=
61311
)
for
cooccurrence
in
NodeNgramNgram
.
objects
.
filter
(
node
=
cooc
):
matrix
[
cooccurrence
.
ngramx
.
terms
][
cooccurrence
.
ngramy
.
terms
]
=
cooccurrence
.
score
matrix
[
cooccurrence
.
ngramy
.
terms
][
cooccurrence
.
ngramx
.
terms
]
=
cooccurrence
.
score
import
pandas
as
pd
from
copy
import
copy
import
numpy
as
np
import
networkx
as
nx
from
networkx.readwrite
import
json_graph
from
gargantext_web.api
import
JsonHttpResponse
#from analysis.louvain import *
matrix
=
defaultdict
(
lambda
:
defaultdict
(
float
))
labels
=
dict
()
cooc
=
Node
.
objects
.
get
(
id
=
61314
)
for
cooccurrence
in
NodeNgramNgram
.
objects
.
filter
(
node
=
cooc
):
labels
[
cooccurrence
.
ngramx
.
id
]
=
cooccurrence
.
ngramx
.
terms
labels
[
cooccurrence
.
ngramy
.
id
]
=
cooccurrence
.
ngramy
.
terms
matrix
[
cooccurrence
.
ngramx
.
id
][
cooccurrence
.
ngramy
.
id
]
=
cooccurrence
.
score
matrix
[
cooccurrence
.
ngramy
.
id
][
cooccurrence
.
ngramx
.
id
]
=
cooccurrence
.
score
df
=
pd
.
DataFrame
(
matrix
)
.
T
.
fillna
(
0
)
x
=
copy
(
df
.
values
)
x
=
x
/
x
.
sum
(
axis
=
1
)
matrix_filtered
=
np
.
where
(
x
>
.2
,
1
,
0
)
# Removing unconnected nodes
threshold
=
min
(
x
.
max
(
axis
=
1
))
matrix_filtered
=
np
.
where
(
x
>
threshold
,
1
,
0
)
#matrix_filtered = np.where(x > threshold, x, 0)
G
=
nx
.
from_numpy_matrix
(
matrix_filtered
)
G
=
nx
.
relabel_nodes
(
G
,
dict
(
enumerate
(
df
.
columns
)))
from
networkx.readwrite
import
json_graph
G
=
nx
.
relabel_nodes
(
G
,
dict
(
enumerate
([
labels
[
x
]
for
x
in
list
(
df
.
columns
)])))
#G = nx.relabel_nodes(G, dict(enumerate(df.columns)))
# Removing too connected nodes (find automatic way to do it)
outdeg
=
G
.
degree
()
to_remove
=
[
n
for
n
in
outdeg
if
outdeg
[
n
]
>=
10
]
G
.
remove_nodes_from
(
to_remove
)
for
node
in
G
.
nodes
():
try
:
#node,type(labels[node])
G
.
node
[
node
][
'label'
]
=
node
# G.node[node]['color'] = '19,180,300'
except
Exception
as
error
:
print
(
error
)
data
=
json_graph
.
node_link_data
(
G
)
# data = json_graph.node_link_data(G, attrs={\
# 'source':'source',\
# 'target':'target',\
# 'weight':'weight',\
# #'label':'label',\
# #'color':'color',\
# 'id':'id',})
#print(data)
return
JsonHttpResponse
(
data
)
...
...
templates/menu.html
View file @
2b86f00f
...
...
@@ -60,7 +60,8 @@
{% load staticfiles %}
<script
src=
"{% static "
js
/
jquery
/
jquery-1
.
9
.
1
.
min
.
js
"%}"
></script>
<!-- <script src="{% static "js/jquery/jquery-1.9.1.min.js"%}"></script> -->
<script
src=
"{% static "
js
/
easy
/
jquery
.
easypiechart
.
js
"%}"
></script>
<script
type=
"text/javascript"
>
...
...
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