Commit 42871df2 authored by delanoe's avatar delanoe

[GRAPH explorer] Parameters checked (and mini tutorial to user for each case).

parent a8b083b9
...@@ -299,8 +299,9 @@ RULE_TINA = "^((VBD,|VBG,|VBN,|CD.?,|JJ.?,|\?,){0,2}?(N.?.?,|\?,)+?(CD.,)??)\ ...@@ -299,8 +299,9 @@ RULE_TINA = "^((VBD,|VBG,|VBN,|CD.?,|JJ.?,|\?,){0,2}?(N.?.?,|\?,)+?(CD.,)??)\
# Graph constraints to compute the graph: # Graph constraints to compute the graph:
# Modes: live graph generation, graph asynchronously computed or errors detected # Modes: live graph generation, graph asynchronously computed or errors detected
# here are the maximum size of corpus and maplist required to compute the graph # here are the maximum size of corpus and maplist required to compute the graph
graph_constraints = {'corpus' : 400 graph_constraints = {'corpusMax' : 400
,'mapList': 50 ,'corpusMin' : 10
,'mapList' : 50
} }
...@@ -58,7 +58,7 @@ def get_graph( request=None , corpus=None ...@@ -58,7 +58,7 @@ def get_graph( request=None , corpus=None
if mapList_size.count() < graph_constraints['mapList']: if mapList_size.count() < graph_constraints['mapList']:
# Do not compute the graph if mapList is not big enough # Do not compute the graph if mapList is not big enough
return {'nodes':[], 'links':[]} return {'nodes':[], 'links':[0,0,0]}
# case of corpus not big enough # case of corpus not big enough
...@@ -103,7 +103,7 @@ def get_graph( request=None , corpus=None ...@@ -103,7 +103,7 @@ def get_graph( request=None , corpus=None
# Finally test if the size of the corpora is big enough # Finally test if the size of the corpora is big enough
# -------------------------------- # --------------------------------
if corpus_size_query.count() > graph_constraints['corpus']: if corpus_size_query.count() > graph_constraints['corpusMax']:
# Then compute cooc asynchronously with celery # Then compute cooc asynchronously with celery
scheduled(countCooccurrences)( corpus_id=corpus.id scheduled(countCooccurrences)( corpus_id=corpus.id
#, field1="ngrams", field2="ngrams" #, field1="ngrams", field2="ngrams"
...@@ -115,7 +115,11 @@ def get_graph( request=None , corpus=None ...@@ -115,7 +115,11 @@ def get_graph( request=None , corpus=None
) )
# Dic hack to inform user that graph is computed asynchronously # Dic hack to inform user that graph is computed asynchronously
# (Impossible graph: no nodes with one link) # (Impossible graph: no nodes with one link)
return {'nodes':[], 'links':[1]} return {'nodes':[], 'links':[0]}
elif corpus_size_query.count() <= graph_constraints['corpusMin']:
# Do not compute the graph if corpus is not big enough
return {'nodes':[], 'links':[0,0]}
else: else:
# If graph_constraints are ok then compute the graph in live # If graph_constraints are ok then compute the graph in live
......
...@@ -6,6 +6,7 @@ from graph.graph import get_graph ...@@ -6,6 +6,7 @@ from graph.graph import get_graph
from gargantext.util.http import APIView, APIException\ from gargantext.util.http import APIView, APIException\
, JsonHttpResponse, requires_auth , JsonHttpResponse, requires_auth
from gargantext.constants import graph_constraints
from traceback import format_tb from traceback import format_tb
def compress_graph(graphdata): def compress_graph(graphdata):
...@@ -150,6 +151,33 @@ class Graph(APIView): ...@@ -150,6 +151,33 @@ class Graph(APIView):
status=200 status=200
) )
# -------------------------------------------- # --------------------------------------------
elif len(data['nodes']) == 0 and len(data['links']) == 2 :
# async data case
return JsonHttpResponse({
'msg': '''Your corpus is too small.
Add more documents (more than %d documents)
in order to get a graph.
You can manage your corpus here:
http://%sgargantext.org/projects/%d/
''' % (graph_constraints['corpusMin'], "dev.", corpus.parent_id),
}, status=400)
elif len(data['nodes']) == 0 and len(data['links']) == 3 :
# async data case
return JsonHttpResponse({
'msg': '''Your map list is too small.
Add some terms (more than %d terms)
in order to get a graph.
You can manage your map terms here:
http://%sgargantext.org/projects/%d/corpora/%d/terms
''' % (graph_constraints['mapList'], "dev.", corpus.parent_id, corpus.id),
}, status=400)
elif len(data['nodes']) == 0 and len(data['links']) == 1 : elif len(data['nodes']) == 0 and len(data['links']) == 1 :
# async data case # async data case
return JsonHttpResponse({ return JsonHttpResponse({
...@@ -164,7 +192,8 @@ class Graph(APIView): ...@@ -164,7 +192,8 @@ class Graph(APIView):
return JsonHttpResponse({ return JsonHttpResponse({
'msg': '''Empty graph warning 'msg': '''Empty graph warning
No cooccurences found in this corpus for the words of this maplist No cooccurences found in this corpus for the words of this maplist
(maybe add more terms to the maplist?)''', (maybe add more terms to the maplist or increase the size of your
corpus ?)''',
}, status=400) }, status=400)
else: else:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment