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
8fcee783
Commit
8fcee783
authored
Dec 03, 2014
by
Administrator
Browse files
Options
Browse Files
Download
Plain Diff
[FEATURE] Adding adjacency matrix (need to adapt json).
parents
a792a315
ddfbe4f6
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
19 deletions
+42
-19
functions.py
analysis/functions.py
+10
-4
urls.py
gargantext_web/urls.py
+11
-9
views.py
gargantext_web/views.py
+20
-5
matrix.html
templates/matrix.html
+1
-1
No files found.
analysis/functions.py
View file @
8fcee783
...
@@ -133,7 +133,7 @@ def create_cooc(user=None, corpus=None, whitelist=None, size=200):
...
@@ -133,7 +133,7 @@ def create_cooc(user=None, corpus=None, whitelist=None, size=200):
cursor
.
execute
(
query_cooc
)
cursor
.
execute
(
query_cooc
)
return
cooc
return
cooc
def
get_cooc
(
request
=
None
,
corpus_id
=
None
,
type
=
"node_link"
):
def
get_cooc
(
request
=
None
,
corpus_id
=
None
,
cooc_id
=
None
,
type
=
"node_link"
):
import
pandas
as
pd
import
pandas
as
pd
from
copy
import
copy
from
copy
import
copy
import
numpy
as
np
import
numpy
as
np
...
@@ -192,13 +192,19 @@ def get_cooc(request=None, corpus_id=None, type="node_link"):
...
@@ -192,13 +192,19 @@ def get_cooc(request=None, corpus_id=None, type="node_link"):
for
node
in
G
.
nodes
():
for
node
in
G
.
nodes
():
try
:
try
:
#node,type(labels[node])
#node,type(labels[node])
G
.
node
[
node
][
'label'
]
=
node
G
.
node
[
node
][
'label'
]
=
node
G
.
node
[
node
][
'size'
]
=
weight
[
node
]
G
.
node
[
node
][
'name'
]
=
node
G
.
node
[
node
][
'size'
]
=
weight
[
node
]
G
.
node
[
node
][
'group'
]
=
partition
[
node
]
# G.node[node]['color'] = '19,180,300'
# G.node[node]['color'] = '19,180,300'
G
.
add_edge
(
node
,
partition
[
node
],
weight
=
2
)
except
Exception
as
error
:
except
Exception
as
error
:
print
(
error
)
print
(
error
)
data
=
json_graph
.
node_link_data
(
G
)
if
type
==
"node_link"
:
data
=
json_graph
.
node_link_data
(
G
)
elif
type
==
"adjacency"
:
data
=
json_graph
.
adjacency_data
(
G
)
# data = json_graph.node_link_data(G, attrs={\
# data = json_graph.node_link_data(G, attrs={\
# 'source':'source',\
# 'source':'source',\
# 'target':'target',\
# 'target':'target',\
...
...
gargantext_web/urls.py
View file @
8fcee783
...
@@ -11,12 +11,13 @@ import gargantext_web.api
...
@@ -11,12 +11,13 @@ import gargantext_web.api
admin
.
autodiscover
()
admin
.
autodiscover
()
urlpatterns
=
patterns
(
''
,
urlpatterns
=
patterns
(
''
,
# url(r'^$', 'gargantext_web.views.home', name='home'),
#
url(r'^blog/', include('blog.urls')),
#
Admin views
url
(
r'^admin/'
,
include
(
admin
.
site
.
urls
)),
url
(
r'^admin/'
,
include
(
admin
.
site
.
urls
)),
url
(
r'^login/'
,
include
(
admin
.
site
.
urls
)),
url
(
r'^login/'
,
include
(
admin
.
site
.
urls
)),
url
(
r'^grappelli/'
,
include
(
'grappelli.urls'
)),
url
(
r'^grappelli/'
,
include
(
'grappelli.urls'
)),
# User views
url
(
r'^$'
,
views
.
home
),
url
(
r'^$'
,
views
.
home
),
url
(
r'^projects/$'
,
views
.
projects
),
url
(
r'^projects/$'
,
views
.
projects
),
...
@@ -27,21 +28,22 @@ urlpatterns = patterns('',
...
@@ -27,21 +28,22 @@ urlpatterns = patterns('',
url
(
r'^project/(\d+)/corpus/(\d+)/$'
,
views
.
corpus
),
url
(
r'^project/(\d+)/corpus/(\d+)/$'
,
views
.
corpus
),
url
(
r'^project/(\d+)/corpus/(\d+)/delete/$'
,
views
.
delete_corpus
),
url
(
r'^project/(\d+)/corpus/(\d+)/delete/$'
,
views
.
delete_corpus
),
# Visualizations
url
(
r'^corpus/(\d+)/explorer$'
,
views
.
explorer_graph
),
url
(
r'^corpus/(\d+)/explorer$'
,
views
.
explorer_graph
),
url
(
r'^chart$'
,
views
.
explorer_chart
),
url
(
r'^corpus/(\d+)/matrix$'
,
views
.
explorer_matrix
),
url
(
r'^matrix$'
,
views
.
explorer_matrix
),
#url(r'^exploration$', views.exploration),
# Getting data
url
(
r'^chart/corpus/(\d+)/data.csv$'
,
views
.
send_csv
),
url
(
r'^chart/corpus/(\d+)/data.csv$'
,
views
.
send_csv
),
url
(
r'^corpus/(\d+)/node_link.json$'
,
views
.
node_link
),
url
(
r'^corpus/(\d+)/node_link.json$'
,
views
.
node_link
),
url
(
r'^corpus/(\d+)/adjancy_matrix$'
,
views
.
node_link
),
url
(
r'^corpus/(\d+)/adjacency.json$'
,
views
.
adjacency
),
# REST views
url
(
r'^api/nodes$'
,
gargantext_web
.
api
.
NodesController
.
get
),
url
(
r'^api/nodes$'
,
gargantext_web
.
api
.
NodesController
.
get
),
url
(
r'^api/corpus/(\d+)/ngrams$'
,
gargantext_web
.
api
.
CorpusController
.
ngrams
),
url
(
r'^api/corpus/(\d+)/ngrams$'
,
gargantext_web
.
api
.
CorpusController
.
ngrams
),
url
(
r'^api/corpus/(\d+)/metadata$'
,
gargantext_web
.
api
.
CorpusController
.
metadata
),
url
(
r'^api/corpus/(\d+)/metadata$'
,
gargantext_web
.
api
.
CorpusController
.
metadata
),
url
(
r'^api/corpus/(\d+)/data$'
,
gargantext_web
.
api
.
CorpusController
.
data
),
url
(
r'^api/corpus/(\d+)/data$'
,
gargantext_web
.
api
.
CorpusController
.
data
),
# Tests (to be removed soon)
url
(
r'^graph-it$'
,
views
.
graph_it
),
url
(
r'^graph-it$'
,
views
.
graph_it
),
url
(
r'^ngrams$'
,
views
.
ngrams
),
url
(
r'^ngrams$'
,
views
.
ngrams
),
)
)
...
...
gargantext_web/views.py
View file @
8fcee783
...
@@ -26,7 +26,6 @@ from collections import defaultdict
...
@@ -26,7 +26,6 @@ from collections import defaultdict
from
parsing.FileParsers
import
*
from
parsing.FileParsers
import
*
# SOME FUNCTIONS
# SOME FUNCTIONS
def
query_to_dicts
(
query_string
,
*
query_args
):
def
query_to_dicts
(
query_string
,
*
query_args
):
...
@@ -391,14 +390,16 @@ def explorer_graph(request, corpus_id):
...
@@ -391,14 +390,16 @@ def explorer_graph(request, corpus_id):
return
HttpResponse
(
html
)
return
HttpResponse
(
html
)
def
explorer_matrix
(
request
):
def
explorer_matrix
(
request
,
corpus_id
):
t
=
get_template
(
'matrix.html'
)
t
=
get_template
(
'matrix.html'
)
user
=
request
.
user
user
=
request
.
user
date
=
datetime
.
datetime
.
now
()
date
=
datetime
.
datetime
.
now
()
corpus
=
Node
.
objects
.
get
(
id
=
corpus_id
)
html
=
t
.
render
(
Context
({
\
html
=
t
.
render
(
Context
({
\
'user'
:
user
,
\
'user'
:
user
,
\
'date'
:
date
,
\
'date'
:
date
,
\
'corpus'
:
corpus
,
\
}))
}))
return
HttpResponse
(
html
)
return
HttpResponse
(
html
)
...
@@ -470,16 +471,30 @@ def send_csv(request, corpus_id):
...
@@ -470,16 +471,30 @@ def send_csv(request, corpus_id):
return
response
return
response
# To get the data
from
gargantext_web.api
import
JsonHttpResponse
from
analysis.functions
import
get_cooc
def
node_link
(
request
,
corpus_id
):
def
node_link
(
request
,
corpus_id
):
'''
'''
Create the HttpResponse object with the
graph
dataset.
Create the HttpResponse object with the
node_link
dataset.
'''
'''
from
gargantext_web.api
import
JsonHttpResponse
from
analysis.functions
import
get_cooc
data
=
get_cooc
(
request
=
request
,
corpus_id
=
corpus_id
,
type
=
"node_link"
)
data
=
get_cooc
(
request
=
request
,
corpus_id
=
corpus_id
,
type
=
"node_link"
)
return
JsonHttpResponse
(
data
)
return
JsonHttpResponse
(
data
)
def
adjacency
(
request
,
corpus_id
):
'''
Create the HttpResponse object with the adjacency dataset.
'''
data
=
get_cooc
(
request
=
request
,
corpus_id
=
corpus_id
,
type
=
"adjacency"
)
return
JsonHttpResponse
(
data
)
def
graph_it
(
request
):
def
graph_it
(
request
):
'''The new multimodal graph.'''
'''The new multimodal graph.'''
t
=
get_template
(
'graph-it.html'
)
t
=
get_template
(
'graph-it.html'
)
...
...
templates/matrix.html
View file @
8fcee783
...
@@ -43,7 +43,7 @@ var svg = d3.select("body").append("svg")
...
@@ -43,7 +43,7 @@ var svg = d3.select("body").append("svg")
.
append
(
"g"
)
.
append
(
"g"
)
.
attr
(
"transform"
,
"translate("
+
margin
.
left
+
","
+
margin
.
top
+
")"
);
.
attr
(
"transform"
,
"translate("
+
margin
.
left
+
","
+
margin
.
top
+
")"
);
d3
.
json
(
"
{% static "
img
/
miserables
.
json
" %}
, function(miserables) {
d3
.
json
(
"
localhost:8000/corpus/{{ corpus.id }}/node_link.json"
,
function
(
miserables
)
{
var
matrix
=
[],
var
matrix
=
[],
nodes
=
miserables
.
nodes
,
nodes
=
miserables
.
nodes
,
n
=
nodes
.
length
;
n
=
nodes
.
length
;
...
...
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