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
04b72105
Commit
04b72105
authored
Nov 21, 2014
by
Administrator
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FEATURE] REST json_node_link for explorer: ok for simple test (need to add parameters but easy).
parent
4838d9b9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
10 deletions
+55
-10
WorkFlow2.ipynb
WorkFlow2.ipynb
+21
-1
urls.py
gargantext_web/urls.py
+1
-1
views.py
gargantext_web/views.py
+33
-8
No files found.
WorkFlow2.ipynb
View file @
04b72105
{
{
"metadata": {
"metadata": {
"name": "",
"name": "",
"signature": "sha256:
36d4a29aece1cb338b47c8a110423fdbe185517347ed2d43a0d21ce31599a549
"
"signature": "sha256:
bf10746bfd6c692f30c86ce04981cf9327380ae3f73174ac91c2acc8e885880a
"
},
},
"nbformat": 3,
"nbformat": 3,
"nbformat_minor": 0,
"nbformat_minor": 0,
...
@@ -1176,6 +1176,26 @@
...
@@ -1176,6 +1176,26 @@
"outputs": [],
"outputs": [],
"prompt_number": 145
"prompt_number": 145
},
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"cooc.pk"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 163,
"text": [
"61311"
]
}
],
"prompt_number": 163
},
{
{
"cell_type": "code",
"cell_type": "code",
"collapsed": false,
"collapsed": false,
...
...
gargantext_web/urls.py
View file @
04b72105
...
@@ -35,7 +35,7 @@ urlpatterns = patterns('',
...
@@ -35,7 +35,7 @@ urlpatterns = patterns('',
url
(
r'^exploration$'
,
views
.
exploration
),
url
(
r'^exploration$'
,
views
.
exploration
),
url
(
r'^chart/corpus/(\d+)/data.csv$'
,
views
.
send_csv
),
url
(
r'^chart/corpus/(\d+)/data.csv$'
,
views
.
send_csv
),
url
(
r'^graph.json$'
,
views
.
send_graph
),
url
(
r'^graph.json$'
,
views
.
json_node_link
),
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
),
...
...
gargantext_web/views.py
View file @
04b72105
...
@@ -8,7 +8,7 @@ from django.template import Context
...
@@ -8,7 +8,7 @@ from django.template import Context
#from documents.models import Project, Corpus, Document
#from documents.models import Project, Corpus, Document
from
node.models
import
Language
,
ResourceType
,
Resource
from
node.models
import
Language
,
ResourceType
,
Resource
from
node.models
import
Node
,
NodeType
,
Node_Resource
,
Project
,
Corpus
from
node.models
import
Node
,
NodeType
,
Node_Resource
,
Project
,
Corpus
,
NodeNgramNgram
from
node.admin
import
CorpusForm
,
ProjectForm
,
ResourceForm
from
node.admin
import
CorpusForm
,
ProjectForm
,
ResourceForm
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
...
@@ -414,20 +414,45 @@ def send_csv(request, corpus_id):
...
@@ -414,20 +414,45 @@ def send_csv(request, corpus_id):
return
response
return
response
def
send_graph
(
request
):
def
json_node_link
(
request
):
'''
'''
Create the HttpResponse object with the graph dataset.
Create the HttpResponse object with the graph dataset.
'''
'''
response
=
HttpResponse
(
content_type
=
'text/json'
)
response
=
HttpResponse
(
content_type
=
'text/json'
)
response
[
'Content-Disposition'
]
=
'attachment; filename="graph.json"'
response
[
'Content-Disposition'
]
=
'attachment; filename="graph.json"'
writer
=
csv
.
writer
(
response
)
# writer = csv.writer(response)
#
# file = open('/srv/gargantext/tests/graphsam/randomgraphgen.json', 'r')
# for line in file.readlines():
# writer.writerow(line)
file
=
open
(
'/srv/gargantext/tests/graphsam/randomgraphgen.json'
,
'r'
)
for
line
in
file
.
readlines
():
writer
.
writerow
(
line
)
return
response
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
gargantext_web.api
import
JsonHttpResponse
#from analysis.louvain import *
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
)
G
=
nx
.
from_numpy_matrix
(
matrix_filtered
)
G
=
nx
.
relabel_nodes
(
G
,
dict
(
enumerate
(
df
.
columns
)))
from
networkx.readwrite
import
json_graph
data
=
json_graph
.
node_link_data
(
G
)
return
JsonHttpResponse
(
data
)
def
graph_it
(
request
):
def
graph_it
(
request
):
...
@@ -439,4 +464,4 @@ def graph_it(request):
...
@@ -439,4 +464,4 @@ def graph_it(request):
'user'
:
user
,
'user'
:
user
,
'date'
:
date
,
'date'
:
date
,
}))
}))
return
HttpResponse
(
html
)
return
HttpResponse
(
html
)
\ No newline at end of file
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