Commit 7e426b8a authored by delanoe's avatar delanoe

Merge branch 'romain-goodies' into unstable

parents 5b50e991 ca339c4a
......@@ -163,6 +163,10 @@
float: right;
}
.spacer {
margin-top:40px;
}
.favactive {
/* yellow */
color: #FFF50D;
......
......@@ -118,12 +118,8 @@
// * (see also InferCRUDFlags in lib/NGrams_dyna_chart_and_table)
// ---------------------------------------------------------------
// TODO disambiguate annotation.list_id for highlighted MapList items
// -------------------------------------------------------------
// Because MapList annotations are also MiamList,
// we should ensure that list_id is indeed "MapList"
// (ie that it was added last in CompileNgramsHtml)
// otherwise the "if" here will propose MiamList's options
// NB: remember that shown mainlist items are actually main 'without map'
// otherwise the menu for mainlist items can hide the menu for map items
if ($rootScope.lists[annotation.list_id] == "MAPLIST") {
$scope.menuItems.push({
......@@ -385,7 +381,7 @@
// =============
// text ------- "Background Few previous studies have examined
// non-wealth-based inequalities etc etc etc"
// ngram ----- {uuid: 1846, occurrences: 1, list_id: 3689,
// ngram ----- {uuid: 1846, occs: 1, list_id: 3689,
// text: "previous studies", listName: "MAINLIST"}
// template --- "<span ng-controller='TextSelectionController'
// ng-click='onClick($event)'
......
......@@ -64,9 +64,9 @@
* --------
* "554": {
* "lists": { "558": "StopList", "564": "MiamList", "565": "MapList" }
* "556": [{ "uuid": 2368, "occurrences": 1.0, "text": "idea", "list_id": 564 },
* { "uuid": 5031, "occurrences": 1.0, "text": "indications", "list_id": 564},
* { "uuid": 5015, "occurrences": 3.0, "text": "star", "list_id": 565 },
* "556": [{ "uuid": 2368, "occs": 1.0, "text": "idea", "list_id": 564 },
* { "uuid": 5031, "occs": 1.0, "text": "indications", "list_id": 564},
* { "uuid": 5015, "occs": 3.0, "text": "star", "list_id": 565 },
* ... ],
* }
*/
......
<span ng-click='onDeleteClick()' class="delete-keyword">×</span>
<span data-toggle="tooltip" class="keyword-text {[{keyword.listName}]}">{[{keyword.text}]}</span>
<span class="occurrences" data-keyword-id="{[{keyword.uuid}]}">{[{keyword.occurrences}]}</span>
<span class="occurrences" data-keyword-id="{[{keyword.uuid}]}">{[{keyword.occs}]}</span>
......@@ -159,7 +159,7 @@
// £TEST locally check if already in annotations NodeNgrams ------
// $rootScope.annotations = array of ngram objects like:
// {"list_id":805,"occurrences":2,"uuid":9386,"text":"petit échantillon"}
// {"list_id":805,"occs":2,"uuid":9386,"text":"petit échantillon"}
console.log('looking for "' + value + '" in list:' + listId)
var already_in_list = false ;
......
......@@ -25,12 +25,24 @@
<div class="container-fluid">
<div class="row-fluid main-panel" ng-controller="NGramHighlightController">
<div class="col-md-4 col-xs-4 tabbable words-panel">
<ul class="nav nav-pills nav-justified">
<li ng-repeat="(listId, listName) in activeLists" ng-class="{active: $first == true}">
<a href="#tab-{[{listId}]}" data-toggle="tab">{[{listName}]}</a>
</li>
</ul>
<div class="tab-content">
<div class="list-selector">
<h5>Select highlighted list(s)
<select class="selectpicker" multiple ng-change="activeListsChange()" ng-model="lists" ng-controller="ActiveListsController">
<option ng-repeat="item in allListsSelect" id="list---{[{item.id}]}" ng-disabled="{[{ item.label == 'MAPLIST' }]}" >{[{item.label}]}</option>
<!-- to disallow unchecking MapList add this into <option> element: ng-disabled="{[{ item.label == 'MAPLIST' }]}" -->
</select>
</h5>
<div class="row spacer"></div>
<ul class="nav nav-pills nav-justified">
<li ng-repeat="(listId, listName) in activeLists" ng-class="{active: $first == true}">
<a href="#tab-{[{listId}]}" data-toggle="tab">{[{listName}]}</a>
</li>
</ul>
</div>
<div class="tab-content">
<div ng-controller="NgramListPaginationController" ng-repeat="(listId, listName) in activeLists" ng-class="{active: $first == true}" class="tab-pane" id="tab-{[{listId}]}">
<div ng-if="ngramsInPanel[listId].length == 0" class="alert alert-info" role="alert">
Input any keyword you want to link to this article and the list named '{[{listName}]}'
......@@ -48,23 +60,14 @@
<li ng-class="{'disabled': currentListPage >= totalListPages(listId) - 1}"><a ng-click="nextListPage()" class="glyphicon glyphicon-forward"></a></li>
</ul>
</nav>
<!--
<div class="form-group" ng-controller="NgramInputController">
<input autosave="search" maxlength="240" placeholder="Add any text" type="text" class="form-control" id="{[{listId}]}-input" ng-keypress="onListSubmit($event, listId)">
<button type="submit" class="form-control btn btn-default btn-primary" ng-click="onListSubmit($event, listId)">Add to {[{listName}]}</button>
</div>
-->
</div>
</div>
<div class="list-selector">
<h5>Select lists</h5>
<select class="selectpicker" multiple ng-change="activeListsChange()" ng-model="lists" ng-controller="ActiveListsController">
<option ng-repeat="item in allListsSelect" id="list---{[{item.id}]}">{[{item.label}]}</option>
<!-- to disallow unchecking MapList add this into <option> element: ng-disabled="{[{ item.label == 'MapList' }]}" -->
</select>
</div>
</div>
<div class="col-md-8 col-xs-8 text-panel" ng-controller="DocController" id="document">
<div class="row-fluid clearfix">
......
......@@ -12,15 +12,11 @@ from rest_framework.renderers import JSONRenderer
from rest_framework.exceptions import APIException
from rest_framework.authentication import SessionAuthentication, BasicAuthentication
# 2016-03-24: refactoring, new paths
from gargantext.models.ngrams import Node, NodeNgram, Ngram
from gargantext.models.ngrams import Node, NodeNgram, Ngram, NodeNgramNgram
from gargantext.util.db import session, aliased
from gargantext.util.db_cache import cache
from gargantext.util.http import requires_auth
# from ngram.lists import listIds, listNgramIds
# from gargantext_web.db import get_or_create_node
from sqlalchemy.sql.expression import case
@requires_auth
def main(request, project_id, corpus_id, document_id):
......@@ -39,30 +35,93 @@ class NgramList(APIView):
renderer_classes = (JSONRenderer,)
def get(self, request, corpus_id, doc_id):
"""Get All for a doc id"""
"""
Get all ngrams for a doc id, sorted by list
NB1 : we are within a doc only
NB2 : MAINLIST items are actually MAINLIST without MAP items
NB3 : mostly the mainforms are in lists, but doc can have subform
=> if we simply join on ngram_id, we'll filter out the subforms
=> join on value filled by case switch:
(the ngram itself or a mainform if exists)
"""
corpus_id = int(corpus_id)
doc_id = int(doc_id)
# our results: ngrams for the corpus_id (ignoring doc_id for the moment)
doc_ngram_list = []
doc_ngram_list_add = doc_ngram_list.append
lists = {}
corpus_nod = cache.Node[corpus_id]
doc_nod = cache.Node[doc_id]
scores_nod = corpus_nod.children(typename="OCCURRENCES").first()
groups_nod = corpus_nod.children(typename="GROUPLIST").first()
# synonyms sub table for outerjoins
Syno = (session.query(NodeNgramNgram.ngram1_id,
NodeNgramNgram.ngram2_id)
.filter(NodeNgramNgram.node_id == groups_nod.id)
.subquery()
)
for list_type in ['MAINLIST', 'MAPLIST', 'STOPLIST']:
# maplist_ids to filter map ngrams from mainlist
maplist_ids = {}
# NB must do mainlist after map for filtering map items out of main
for list_type in ['MAPLIST', 'STOPLIST', 'MAINLIST']:
list_nod = corpus_nod.children(typename=list_type).first()
list_id = list_nod.id
lists["%s" % list_id] = list_type
ListsTable = aliased(NodeNgram)
# doc_nod.ngrams iff we just need the occurrences in the doc (otherwise do manually)
q = doc_nod.ngrams.join(ListsTable).filter(ListsTable.node_id == list_id)
# add to results
doc_ngram_list += [(obj.id, obj.terms, w, list_id) for (w,obj) in q.all()]
mainform_id = case([
(Syno.c.ngram1_id != None, Syno.c.ngram1_id),
(Syno.c.ngram1_id == None, Ngram.id)
])
q = (session
# ngrams from the doc_id
.query(NodeNgram.weight, Ngram, mainform_id)
# debug
#.query(NodeNgram.weight, Ngram.terms, Ngram.id, Syno.c.ngram1_id, mainform_id)
.select_from(NodeNgram)
.join(Ngram)
.filter(NodeNgram.node_id == doc_id)
# add mainforms next to their subforms
.outerjoin(Syno,
Syno.c.ngram2_id == Ngram.id)
# filter mainforms on the list we want
.join(ListsTable,
# possible that mainform is in list
# and not the subform
ListsTable.ngram_id == mainform_id
)
.filter(ListsTable.node_id == list_id)
)
# add to results (and optional filtering)
for (w,obj, mainform_id) in q.all():
ngram_id = obj.id
# boolean if needed
# is_subform = (ngram_id == mainform_id)
# special filtering case
# when MAINLIST requested we actually want MAIN without MAP
if list_type == "MAPLIST":
maplist_ids[ngram_id] = True
if list_type == "MAINLIST":
if ngram_id in maplist_ids:
# skip object
continue
# normal case
doc_ngram_list_add((ngram_id, obj.terms, w, list_id))
# debug
# print("annotations.views.NgramList.doc_ngram_list: ", doc_ngram_list)
......@@ -71,7 +130,7 @@ class NgramList(APIView):
[
{'uuid': ngram_id,
'text': ngram_text,
'occurrences': ngram_occurrences,
'occs': ngram_occurrences,
'list_id': list_id,}
for (ngram_id,ngram_text,ngram_occurrences,list_id) in doc_ngram_list
],
......
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