Commit 8cc92549 authored by delanoe's avatar delanoe

[FEAT] Temporal Graph implemented. Ok.

parent 7814f5b8
......@@ -5,7 +5,7 @@ from .nodes import Node
import datetime
__all__ = ['NodeHyperdata']
__all__ = ['NodeHyperdata', 'HyperdataKey']
class classproperty(object):
......
from gargantext.models import Node, Ngram, NodeNgram, NodeNgramNgram, \
NodeHyperdata
NodeHyperdata, HyperdataKey
from gargantext.util.db import session, aliased, bulk_insert, func
from gargantext.util.lists import WeightedMatrix, UnweightedList, Translations
......@@ -21,7 +21,7 @@ def countCooccurrences( corpus=None
For the moment list of paramters are not supported because, lists need to
be merged before.
corpus :: Corpus
mapList_id :: Int
groupList_id :: Int
......@@ -32,10 +32,10 @@ def countCooccurrences( corpus=None
'''
# TODO : add hyperdata here
# Security test
field1,field2 = str(field1), str(field2)
# Get node
if not coocNode_id:
coocNode_id0 = ( session.query( Node.id )
......@@ -56,20 +56,20 @@ def countCooccurrences( corpus=None
coocNode_id = coocNode.id
else :
coocNode_id = coocNode_id[0]
if reset == True :
session.query( NodeNgramNgram ).filter( NodeNgramNgram.node_id == coocNode_id ).delete()
session.commit()
NodeNgramX = aliased(NodeNgram)
# Simple Cooccurrences
cooc_score = func.count(NodeNgramX.node_id).label('cooc_score')
# A kind of Euclidean distance cooccurrences
#cooc_score = func.sqrt(func.sum(NodeNgramX.weight * NodeNgramY.weight)).label('cooc_score')
if isMonopartite :
NodeNgramY = aliased(NodeNgram)
......@@ -89,7 +89,7 @@ def countCooccurrences( corpus=None
)
else :
NodeNgramY = aliased(NodeNgram)
cooc_query = (session.query( NodeHyperdataNgram.ngram_id
, NodeNgramY.ngram_id
, cooc_score
......@@ -142,17 +142,13 @@ def countCooccurrences( corpus=None
# TODO : more complexe date format here.
date_start = datetime.datetime.strptime (str(start), "%Y-%m-%d")
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 == 'publication_date')
.filter( Start.value_datetime >= date_start_utc)
.filter( Start.key == 'publication_date')
.filter( Start.value_utc >= date_start_utc)
)
......@@ -160,26 +156,23 @@ def countCooccurrences( corpus=None
# TODO : more complexe date format here.
date_end = datetime.datetime.strptime (str(end), "%Y-%m-%d")
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 == 'publication_date' )
.filter( End.value_datetime <= date_end_utc )
.filter( End.key == 'publication_date')
.filter( End.value_utc <= date_end_utc )
)
if isMonopartite:
# 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.having(cooc_score > threshold)
if isMonopartite:
cooc_query = cooc_query.group_by(NodeNgramX.ngram_id, NodeNgramY.ngram_id)
else:
......@@ -192,6 +185,6 @@ def countCooccurrences( corpus=None
mapList = UnweightedList( mapList_id )
group_list = Translations ( groupList_id )
cooc = matrix & (mapList * group_list)
cooc.save(coocNode_id)
return(coocNode_id)
......@@ -94,10 +94,10 @@
<!-- FIXME a pop up for advanced mode of graphs --!>
<a type="button" class="btn btn-default
{% if view == "conditional" %}active{%endif%}"
href="/projects/{{project.id}}/corpora/{{ corpus.id }}/explorer?field1=ngrams&amp;field2=ngrams&amp;distance=conditional&amp;bridgeness=5">Graphs (Conditional)</a>
data-url="/projects/{{project.id}}/corpora/{{ corpus.id }}/explorer?field1=ngrams&amp;field2=ngrams&amp;distance=conditional&amp;bridgeness=5" onclick='gotoexplorer(this)' >Graphs (Conditional)</a>
<a type="button" class="btn btn-default
{% if view == "distributional" %}active{%endif%}"
href="/projects/{{project.id}}/corpora/{{ corpus.id }}/explorer?field1=ngrams&amp;field2=ngrams&amp;distance=distributional&amp;bridgeness=5">Graphs (Distributional)</a>
data-url="/projects/{{project.id}}/corpora/{{ corpus.id }}/explorer?field1=ngrams&amp;field2=ngrams&amp;distance=distributional&amp;bridgeness=5" onclick='gotoexplorer(this)' >Graphs (Distributional)</a>
<!--
<a type="button" class="btn btn-default
{% if view == "journalTerms" %}active{%endif%}"
......@@ -198,6 +198,37 @@
});});
</script>
<script type="text/javascript">
function gotoexplorer(elem) {
var url_ = $(elem).data("url")
if (TheBuffer==false)
return window.open(url_,'_blank');
var current_timerange = TheBuffer
var time_limits = [new Date(oldest[0],oldest[1]-1,oldest[2]), new Date(latest[0],latest[1]-1,latest[2] ) ];
time_limits[0] = new Date(time_limits[0].setDate(time_limits[0].getDate()-1) );
time_limits[1] = new Date(time_limits[1].setDate(time_limits[1].getDate()+1) );
if( ( +current_timerange[0]===+time_limits[0] ) && ( +current_timerange[1]===+time_limits[1] ) ) {
url_ = url_ // rien
} else {
var start__ = new Date(current_timerange[0].setDate(current_timerange[0].getDate()+1) );
var end__ = new Date(current_timerange[1].setDate(current_timerange[1].getDate()-1) );
var start_ = start__.getFullYear()+"-"+(start__.getMonth()+1)+"-"+(start__.getDay()+1)
var end_ = end__.getFullYear()+"-"+(end__.getMonth()+1)+"-"+(end__.getDay()+1)
url_ += "&start=" + start_ + "&end="+end_;
// url_ += "&start=" + start__.getFullYear() + "&end="+end__.getFullYear();
}
return window.open(url_,'_blank');
}
</script>
{% if debug == False %}
<!-- Piwik -->
<script type="text/javascript">
......@@ -222,3 +253,7 @@
</body>
</html>
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