Commit be06df46 authored by delanoe's avatar delanoe

[FEAT] Graph, with mapList only.

parent 2b17dfca
...@@ -9,22 +9,20 @@ from sqlalchemy import desc, asc, or_, and_ ...@@ -9,22 +9,20 @@ from sqlalchemy import desc, asc, or_, and_
#import inspect #import inspect
import datetime import datetime
def do_cooc(corpus=None def do_cooc( corpus=None
, field1='ngrams', field2='ngrams' , field1='ngrams' , field2='ngrams'
, mainList_id=None, groupList_id=None , start=None , end=None
, coocNode_id=None , mapList_id=None , groupList_id=None
, start=None, end=None , n_min=1, n_max=None , limit=1000
, n_min=1, n_max=None , limit=1000 , coocNode_id=None , reset=True
, isMonopartite=True , isMonopartite=True , threshold = 3):
, threshold = 3
, reset=True):
''' '''
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
be merged before. be merged before.
corpus :: Corpus corpus :: Corpus
mainList_id :: Int mapList_id :: Int
groupList_id :: Int groupList_id :: Int
For the moment, start and end are simple, only year is implemented yet For the moment, start and end are simple, only year is implemented yet
...@@ -191,9 +189,9 @@ def do_cooc(corpus=None ...@@ -191,9 +189,9 @@ def do_cooc(corpus=None
cooc_query = cooc_query.order_by(desc('cooc_score')) cooc_query = cooc_query.order_by(desc('cooc_score'))
matrix = WeightedMatrix(cooc_query) matrix = WeightedMatrix(cooc_query)
mainList = UnweightedList( mainList_id ) mapList = UnweightedList( mapList_id )
group_list = Translations ( groupList_id ) group_list = Translations ( groupList_id )
cooc = matrix & (mainList * group_list) cooc = matrix & (mapList * group_list)
cooc.save(coocNode_id) cooc.save(coocNode_id)
return(coocNode_id) return(coocNode_id)
...@@ -29,7 +29,7 @@ def get_cooc( request=None, corpus=None ...@@ -29,7 +29,7 @@ def get_cooc( request=None, corpus=None
, distance='conditional' , distance='conditional'
, size=1000 , size=1000
, bridgeness=5 , bridgeness=5
, mainList_id = None , groupList_id = None , mapList_id = None , groupList_id = None
): ):
''' '''
get_ccoc : to compute the graph. get_ccoc : to compute the graph.
...@@ -38,15 +38,15 @@ def get_cooc( request=None, corpus=None ...@@ -38,15 +38,15 @@ def get_cooc( request=None, corpus=None
data = {} data = {}
if mainList_id == None : if mapList_id == None :
mainList_id = ( session.query ( Node.id ) mapList_id = ( session.query ( Node.id )
.filter( Node.typename == "MAINLIST" .filter( Node.typename == "MAPLIST"
, Node.parent_id == corpus.id , Node.parent_id == corpus.id
) )
.first() .first()
) )
if mainList_id == None : if mapList_id == None :
raise ValueError("MAINLIST node needed for cooccurrences") raise ValueError("MAPLIST node needed for cooccurrences")
if groupList_id == None : if groupList_id == None :
...@@ -79,7 +79,7 @@ def get_cooc( request=None, corpus=None ...@@ -79,7 +79,7 @@ def get_cooc( request=None, corpus=None
cooc_id = do_cooc( corpus=corpus cooc_id = do_cooc( corpus=corpus
#, field1="ngrams", field2="ngrams" #, field1="ngrams", field2="ngrams"
, mainList_id=int(mainList_id[0]), groupList_id=int(groupList_id[0]) , mapList_id=int(mapList_id[0]), groupList_id=int(groupList_id[0])
#, isMonopartite=True #, isMonopartite=True
, start=start , end =end , start=start , end =end
, threshold = threshold #, limit=size , threshold = threshold #, limit=size
......
from gargantext.util.http import APIView, APIException, JsonHttpResponse, requires_auth
#from rest_framework.authentication import SessionAuthentication, BasicAuthentication #from rest_framework.authentication import SessionAuthentication, BasicAuthentication
from gargantext.util.db import session from gargantext.util.db import session
from gargantext.models.nodes import Node from gargantext.models.nodes import Node
from graphExplorer.functions import get_cooc from graphExplorer.functions import get_cooc
from gargantext.util.http import APIView, APIException\
, JsonHttpResponse, requires_auth
# TODO check authentication # TODO check authentication
......
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