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
a57a4185
Commit
a57a4185
authored
Oct 22, 2015
by
delanoe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FEAT] Adding apax function to REST API to get cooc/graph for explorer.
parent
f0cc9050
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
7 deletions
+12
-7
cooccurrences.py
analysis/cooccurrences.py
+3
-3
functions.py
analysis/functions.py
+4
-2
graph.py
rest_v1_0/graph.py
+5
-2
No files found.
analysis/cooccurrences.py
View file @
a57a4185
...
@@ -17,7 +17,8 @@ def do_cooc(corpus=None
...
@@ -17,7 +17,8 @@ def do_cooc(corpus=None
,
n_min
=
2
,
n_max
=
None
,
n_min
=
2
,
n_max
=
None
,
start
=
None
,
end
=
None
,
start
=
None
,
end
=
None
,
limit
=
1000
,
limit
=
1000
,
isMonopartite
=
True
):
,
isMonopartite
=
True
,
apax
=
2
):
'''
'''
Compute the cooccurence matrix and save it, returning NodeNgramNgram.node_id
Compute the cooccurence matrix and save it, returning NodeNgramNgram.node_id
For the moment list of paramters are not supported because, lists need to
For the moment list of paramters are not supported because, lists need to
...
@@ -149,8 +150,7 @@ def do_cooc(corpus=None
...
@@ -149,8 +150,7 @@ def do_cooc(corpus=None
# Cooc is symetric, take only the main cooccurrences and cut at the limit
# Cooc is symetric, take only the main cooccurrences and cut at the limit
cooc_query
=
cooc_query
.
filter
(
NodeNgramX
.
ngram_id
<
NodeNgramY
.
ngram_id
)
cooc_query
=
cooc_query
.
filter
(
NodeNgramX
.
ngram_id
<
NodeNgramY
.
ngram_id
)
cooc_query
=
cooc_query
.
having
(
cooc_score
>
1
)
cooc_query
=
cooc_query
.
having
(
cooc_score
>
apax
)
#.having(cooc_score > 1)
if
isMonopartite
:
if
isMonopartite
:
cooc_query
=
cooc_query
.
group_by
(
NodeNgramX
.
ngram_id
,
NodeNgramY
.
ngram_id
)
cooc_query
=
cooc_query
.
group_by
(
NodeNgramX
.
ngram_id
,
NodeNgramY
.
ngram_id
)
...
...
analysis/functions.py
View file @
a57a4185
...
@@ -30,7 +30,7 @@ def diag_null(x):
...
@@ -30,7 +30,7 @@ def diag_null(x):
return
x
-
x
*
scipy
.
eye
(
x
.
shape
[
0
])
return
x
-
x
*
scipy
.
eye
(
x
.
shape
[
0
])
def
do_distance
(
cooc_id
,
field1
=
None
,
field2
=
None
,
isMonopartite
=
True
):
def
do_distance
(
cooc_id
,
field1
=
None
,
field2
=
None
,
isMonopartite
=
True
,
apax
=
2
):
'''
'''
do_distance :: Int -> (Graph, Partition, {ids}, {weight})
do_distance :: Int -> (Graph, Partition, {ids}, {weight})
'''
'''
...
@@ -119,6 +119,7 @@ def get_cooc(request=None, corpus=None
...
@@ -119,6 +119,7 @@ def get_cooc(request=None, corpus=None
,
field1
=
'ngrams'
,
field2
=
'ngrams'
,
field1
=
'ngrams'
,
field2
=
'ngrams'
,
cooc_id
=
None
,
type
=
'node_link'
,
size
=
1000
,
cooc_id
=
None
,
type
=
'node_link'
,
size
=
1000
,
start
=
None
,
end
=
None
,
start
=
None
,
end
=
None
,
apax
=
2
):
):
'''
'''
get_ccoc : to compute the graph.
get_ccoc : to compute the graph.
...
@@ -139,7 +140,8 @@ def get_cooc(request=None, corpus=None
...
@@ -139,7 +140,8 @@ def get_cooc(request=None, corpus=None
#cooc_id = get_or_create_node(nodetype='Cooccurrence', corpus=corpus).id
#cooc_id = get_or_create_node(nodetype='Cooccurrence', corpus=corpus).id
cooc_id
=
do_cooc
(
corpus
=
corpus
,
field1
=
field1
,
field2
=
field2
cooc_id
=
do_cooc
(
corpus
=
corpus
,
field1
=
field1
,
field2
=
field2
,
miam_id
=
miam_id
,
group_id
=
group_id
,
stop_id
=
stop_id
,
limit
=
size
,
miam_id
=
miam_id
,
group_id
=
group_id
,
stop_id
=
stop_id
,
limit
=
size
,
isMonopartite
=
isMonopartite
)
,
isMonopartite
=
isMonopartite
,
apax
=
apax
)
G
,
partition
,
ids
,
weight
=
do_distance
(
cooc_id
,
field1
=
field1
,
field2
=
field2
,
isMonopartite
=
isMonopartite
)
G
,
partition
,
ids
,
weight
=
do_distance
(
cooc_id
,
field1
=
field1
,
field2
=
field2
,
isMonopartite
=
isMonopartite
)
...
...
rest_v1_0/graph.py
View file @
a57a4185
...
@@ -21,19 +21,21 @@ class Graph(APIView):
...
@@ -21,19 +21,21 @@ class Graph(APIView):
format_
=
request
.
GET
.
get
(
'format'
,
'json'
)
format_
=
request
.
GET
.
get
(
'format'
,
'json'
)
type_
=
request
.
GET
.
get
(
'type'
,
'node_link'
)
type_
=
request
.
GET
.
get
(
'type'
,
'node_link'
)
apax
=
request
.
GET
.
get
(
'apax'
,
2
)
corpus
=
session
.
query
(
Node
)
.
filter
(
Node
.
id
==
corpus_id
)
.
first
()
corpus
=
session
.
query
(
Node
)
.
filter
(
Node
.
id
==
corpus_id
)
.
first
()
accepted_field1
=
[
'ngrams'
,
'journal'
,
'source'
,
'authors'
]
accepted_field1
=
[
'ngrams'
,
'journal'
,
'source'
,
'authors'
]
accepted_field2
=
[
'ngrams'
,]
accepted_field2
=
[
'ngrams'
,]
options
=
[
'start'
,
'end'
,
'apax'
]
if
field1
in
accepted_field1
:
if
field1
in
accepted_field1
:
if
field2
in
accepted_field2
:
if
field2
in
accepted_field2
:
if
start
is
not
None
and
end
is
not
None
:
if
start
is
not
None
and
end
is
not
None
:
data
=
get_cooc
(
corpus
=
corpus
,
field1
=
field1
,
field2
=
field2
,
start
=
start
,
end
=
end
)
data
=
get_cooc
(
corpus
=
corpus
,
field1
=
field1
,
field2
=
field2
,
start
=
start
,
end
=
end
,
apax
=
apax
)
else
:
else
:
data
=
get_cooc
(
corpus
=
corpus
,
field1
=
field1
,
field2
=
field2
)
data
=
get_cooc
(
corpus
=
corpus
,
field1
=
field1
,
field2
=
field2
,
apax
=
apax
)
if
format_
==
'json'
:
if
format_
==
'json'
:
return
JsonHttpResponse
(
data
)
return
JsonHttpResponse
(
data
)
else
:
else
:
...
@@ -41,4 +43,5 @@ class Graph(APIView):
...
@@ -41,4 +43,5 @@ class Graph(APIView):
'Warning USAGE'
:
'One field for each range:'
'Warning USAGE'
:
'One field for each range:'
,
'field1'
:
accepted_field1
,
'field1'
:
accepted_field1
,
'field2'
:
accepted_field2
,
'field2'
:
accepted_field2
,
'options'
:
options
})
})
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