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
20f0882a
Commit
20f0882a
authored
Oct 19, 2015
by
delanoe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FEAT] GRAPH REST API with start=YEAR & end=YEAR filter. More precise date can be computed next.
parent
831b933b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
6 deletions
+26
-6
cooccurrences.py
analysis/cooccurrences.py
+14
-4
functions.py
analysis/functions.py
+3
-1
graph.py
rest_v1_0/graph.py
+9
-1
No files found.
analysis/cooccurrences.py
View file @
20f0882a
...
...
@@ -8,6 +8,7 @@ from gargantext_web.db import Node, Ngram, NodeNgram, NodeNgramNgram, \
from
gargantext_web.db
import
session
,
cache
,
get_or_create_node
,
bulk_insert
from
analysis.lists
import
WeightedMatrix
,
UnweightedList
,
Translations
import
inspect
import
datetime
def
do_cooc
(
corpus
=
None
,
field1
=
'ngrams'
,
field2
=
'ngrams'
...
...
@@ -116,22 +117,31 @@ def do_cooc(corpus=None
# Cooc between the dates start and end
if
start
is
not
None
:
#date_start = datetime.datetime.strptime ("2001-2-3 10:11:12", "%Y-%m-%d %H:%M:%S")
# TODO : more complexe date format here.
date_start
=
datetime
.
datetime
.
strptime
(
str
(
start
),
"
%
Y"
)
date_start_utc
=
date_start
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
Start
=
aliased
(
NodeHyperdata
)
StartFormat
=
aliased
(
Hyperdata
)
cooc_query
=
(
cooc_query
.
join
(
Start
,
Start
.
node_id
==
Node
.
id
)
.
join
(
StartFormat
,
StartFormat
.
id
==
Start
.
hyperdata_id
)
.
filter
(
StartFormat
.
name
==
'
datetim
e'
)
.
filter
(
Start
.
value_datetime
>=
start
)
.
filter
(
StartFormat
.
name
==
'
publication_dat
e'
)
.
filter
(
Start
.
value_datetime
>=
date_start_utc
)
)
if
end
is
not
None
:
# TODO : more complexe date format here.
date_end
=
datetime
.
datetime
.
strptime
(
str
(
end
),
"
%
Y"
)
date_end_utc
=
date_end
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
End
=
aliased
(
NodeHyperdata
)
EndFormat
=
aliased
(
Hyperdata
)
cooc_query
=
(
cooc_query
.
join
(
End
,
End
.
node_id
==
Node
.
id
)
.
join
(
EndFormat
,
EndFormat
.
id
==
End
.
hyperdata_id
)
.
filter
(
EndFormat
.
name
==
'
datetim
e'
)
.
filter
(
End
.
value_datetime
<=
end
)
.
filter
(
EndFormat
.
name
==
'
publication_dat
e'
)
.
filter
(
End
.
value_datetime
<=
date_end_utc
)
)
...
...
analysis/functions.py
View file @
20f0882a
...
...
@@ -139,7 +139,9 @@ def get_cooc(request=None, corpus=None
#cooc_id = get_or_create_node(nodetype='Cooccurrence', corpus=corpus).id
cooc_id
=
do_cooc
(
corpus
=
corpus
,
field1
=
field1
,
field2
=
field2
,
miam_id
=
miam_id
,
group_id
=
group_id
,
stop_id
=
stop_id
,
limit
=
size
,
isMonopartite
=
isMonopartite
)
,
isMonopartite
=
isMonopartite
,
start
=
start
,
end
=
end
)
G
,
partition
,
ids
,
weight
=
do_distance
(
cooc_id
,
field1
=
field1
,
field2
=
field2
,
isMonopartite
=
isMonopartite
)
...
...
rest_v1_0/graph.py
View file @
20f0882a
...
...
@@ -11,9 +11,14 @@ class Graph(APIView):
Graph.get :: Get graph data as REST api.
Get all the parameters first
graph?field1=ngrams&field2=ngrams&
graph?field1=ngrams&field2=ngrams&start=''&end=''
'''
field1
=
request
.
GET
.
get
(
'field1'
,
'ngrams'
)
field2
=
request
.
GET
.
get
(
'field2'
,
'ngrams'
)
start
=
request
.
GET
.
get
(
'start'
,
None
)
end
=
request
.
GET
.
get
(
'end'
,
None
)
format_
=
request
.
GET
.
get
(
'format'
,
'json'
)
type_
=
request
.
GET
.
get
(
'type'
,
'node_link'
)
...
...
@@ -25,7 +30,10 @@ class Graph(APIView):
if
field1
in
accepted_field1
:
if
field2
in
accepted_field2
:
data
=
get_cooc
(
corpus
=
corpus
,
field1
=
field1
,
field2
=
field2
)
if
start
is
not
None
and
end
is
not
None
:
data
=
get_cooc
(
corpus
=
corpus
,
field1
=
field1
,
field2
=
field2
,
start
=
start
,
end
=
end
)
else
:
data
=
get_cooc
(
corpus
=
corpus
,
field1
=
field1
,
field2
=
field2
)
if
format_
==
'json'
:
return
JsonHttpResponse
(
data
)
else
:
...
...
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