Commit a57a4185 authored by delanoe's avatar delanoe

[FEAT] Adding apax function to REST API to get cooc/graph for explorer.

parent f0cc9050
...@@ -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)
......
...@@ -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)
......
...@@ -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
}) })
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