Commit 7f7ac788 authored by Romain Loth's avatar Romain Loth

annotations: working delete from lists (added "ngramlists/change?list=..." as...

annotations: working delete from lists (added "ngramlists/change?list=..." as an external service + added chained calls to manage consequences)
parent 5f0581a2
......@@ -32,7 +32,10 @@
},
function(data) {
$rootScope.annotations = data[$rootScope.corpusId.toString()][$rootScope.docId.toString()];
// eg id => 'MAPLIST'
$rootScope.lists = data[$rootScope.corpusId.toString()].lists;
// inverted 'MAPLIST' => id
$rootScope.listIds = _.invert($rootScope.lists)
$scope.dataLoading = false ;
},
function(data) {
......
(function () {
'use strict';
var annotationsAppHighlight = angular.module('annotationsAppHighlight', ['annotationsAppHttp']);
var annotationsAppHighlight = angular.module('annotationsAppHighlight', ['annotationsAppHttp', 'annotationsAppUtils']);
/*
* Controls the mouse selection on the text
......@@ -15,7 +15,6 @@
// grand parent should be the rootscope
//console.log($scope.$parent.$parent.$id)
// (prepared once, after highlight)
// (then used when onClick event)
// retrieve corresponding ngram using element attr uuid in <span uuid="42">
......@@ -45,8 +44,8 @@
* Controls the menu over the current mouse selection
*/
annotationsAppHighlight.controller('TextSelectionMenuController',
['$scope', '$rootScope', '$element', '$timeout', 'NgramHttpService', 'NgramListHttpService',
function ($scope, $rootScope, $element, $timeout, NgramHttpService, NgramListHttpService) {
['$scope', '$rootScope', '$element', '$timeout', 'MainApiChangeNgramHttpService', 'NgramListHttpService',
function ($scope, $rootScope, $element, $timeout, MainApiChangeNgramHttpService, NgramListHttpService) {
/*
* Universal text selection
*/
......@@ -82,14 +81,14 @@
/*
* Dynamically construct the selection menu scope
* (actions are then interpreted in onMenuClick)
*/
function toggleMenu(context, annotation) {
$timeout(function() {
$scope.$apply(function() {
// £TODO check
var miamlist_id = _.invert($rootScope.lists).MAINLIST;
var stoplist_id = _.invert($rootScope.lists).STOPLIST;
var maplist_id = _.invert($rootScope.lists).MAPLIST;
var mainlist_id = $rootScope.listIds.MAINLIST;
var stoplist_id = $rootScope.listIds.STOPLIST;
var maplist_id = $rootScope.listIds.MAPLIST;
// if called from highlighted span
// - annotation has full {ngram}
......@@ -105,28 +104,19 @@
// debug
// console.log("toggleMenu with \$scope.selection_text: '" + JSON.stringify($scope.selection_text) +"'") ;
if (angular.isObject(annotation) && !$element.hasClass('menu-is-opened')) {
// existing ngram
console.log("toggleMenu.annotation: '" + JSON.stringify(annotation) +"'")
// Delete from the current list
$scope.menuItems = [
{
'action': 'delete',
'listId': annotation.list_id,
'verb': 'Delete from',
'listName': $rootScope.lists[annotation.list_id]
}
];
// Context menu proposes 3 things for each item of list A
// - deletion from A
// Context menu proposes 2 things for each item of list A
// - adding/moving to other lists B or C
// Because of logical dependencies b/w lists, these
// menu actions will also trigger todo_other_actions
// cf. forge.iscpif.fr/projects/garg/wiki/Ngram_Lists
// ---------------------------------------------------------------
// Because of logical dependencies b/w lists, user choices are "intentions"
// the real CRUDs actions are deduced from intentions as a list...
// * (see forge.iscpif.fr/projects/garg/wiki/Ngram_Lists)
// * (see also InferCRUDFlags in lib/NGrams_dyna_chart_and_table)
// ---------------------------------------------------------------
// TODO disambiguate annotation.list_id for highlighted MapList items
// -------------------------------------------------------------
......@@ -136,39 +126,81 @@
// otherwise the "if" here will propose MiamList's options
if ($rootScope.lists[annotation.list_id] == "MAPLIST") {
// Add to the other lists
$scope.menuItems.push({
'action': 'post',
'listId': stoplist_id,
'verb': 'Move to',
'listName': $rootScope.lists[stoplist_id]
// "tgtListName" is just used to render the GUI explanation
'tgtListName': 'STOPLIST',
// crudActions is an array of rest/DB actions
// (consequences of the intention)
'crudActions':[
["delete", maplist_id],
["delete", mainlist_id],
["put", stoplist_id]
]
});
} else if ($rootScope.lists[annotation.list_id] == "STOPLIST") {
// Add to the alternative list
$scope.menuItems.push({
'action': 'post',
'listId': miamlist_id,
'verb': 'Move to',
'listName': $rootScope.lists[miamlist_id]
'tgtListName': 'MAINLIST',
'crudActions':[
["delete", maplist_id]
]
});
}
else if ($rootScope.lists[annotation.list_id] == "MAINLIST") {
$scope.menuItems.push({
'tgtListName': "STOPLIST",
'crudActions':[
["delete", mainlist_id],
["put", stoplist_id]
]
});
$scope.menuItems.push({
'tgtListName': "MAPLIST",
'crudActions':[
["put", maplist_id]
]
});
}
else if ($rootScope.lists[annotation.list_id] == "STOPLIST") {
$scope.menuItems.push({
'tgtListName': "MAINLIST",
'crudActions':[
["delete", stoplist_id],
["put", mainlist_id]
]
});
$scope.menuItems.push({
'tgtListName': "MAPLIST",
'crudActions':[
["delete", stoplist_id],
["put", mainlist_id],
["put", maplist_id]
]
});
}
// show the menu
$element.fadeIn(100);
$element.addClass('menu-is-opened');
} else if (annotation.trim() !== "" && !$element.hasClass('menu-is-opened')) {
// new ngram
$scope.menuItems = [
{
'action': 'post',
'listId': miamlist_id,
'verb': 'Add to',
'listName': $rootScope.lists[miamlist_id]
}
];
// show the menu
$element.fadeIn(100);
$element.addClass('menu-is-opened');
} else {
}
// -------8<------ "add" actions for non-existing ngram ------
// else if (annotation.trim() !== "" && !$element.hasClass('menu-is-opened')) {
// // new ngram
// $scope.menuItems = [
// {
// 'action': 'post',
// 'listId': miamlist_id,
// 'verb': 'Add to',
// 'listName': $rootScope.lists[miamlist_id]
// }
// ];
// // show the menu
// $element.fadeIn(100);
// $element.addClass('menu-is-opened');
// }
// -------8<--------------------------------------------------
else {
$scope.menuItems = [];
// close the menu
$element.fadeOut(100);
......@@ -178,80 +210,6 @@
});
}
// £TODO CHECK
// if ($rootScope.lists[annotation.list_id] == "MiamList") {
// // Add to the other lists
// $scope.menuItems.push({
// 'action': 'post',
// 'listId': maplist_id,
// // "Add" because copy into MapList
// 'verb': 'Add to',
// 'listName': $rootScope.lists[maplist_id]
// },
// {
// 'action': 'post',
// 'listId': stoplist_id,
// // "Move"
// // £dbg: TODO for instance pass conditional dependancy as info
// // 'todo_other_actions': 'remove from miam',
// 'verb': 'Move to',
// 'listName': $rootScope.lists[stoplist_id]
// });
// } else if ($rootScope.lists[annotation.list_id] == "StopList") {
// // Move from stop to the "positive" lists
// $scope.menuItems.push({
// 'action': 'post',
// 'listId': miamlist_id,
// // 'todo_other_actions': 'remove from stop',
// 'verb': 'Move to',
// 'listName': $rootScope.lists[miamlist_id]
// },
// {
// 'action': 'post',
// 'listId': maplist_id,
// // 'todo_other_actions': 'remove from stop, add to miam',
// 'verb': 'Move to',
// 'listName': $rootScope.lists[maplist_id]
// });
// } else if ($rootScope.lists[annotation.list_id] == "MapList") {
// // No need to add to miam, just possible to move to stop
// $scope.menuItems.push({
// 'action': 'post',
// 'listId': stoplist_id,
// // 'todo_other_actions': 'remove from miam and from map'
// 'verb': 'Move to',
// 'listName': $rootScope.lists[stoplist_id]
// });
// }
//
//
//
var pos = $(".text-panel").position();
function positionElement(context, x, y) {
......@@ -296,72 +254,115 @@
$rootScope.$on("positionAnnotationMenu", positionElement);
$rootScope.$on("toggleAnnotationMenu", toggleMenu);
/*
* Menu click action
* Menu click actions
* (1 intention => list of actions => MainApiChangeNgramHttpService CRUDs)
* post/delete
*/
$scope.onMenuClick = function($event, action, listId) {
// TODO interpret context menu chosen actions
// as implicit API+DB actions
// ex: add to map (+ add to miam + delete from stop)
$scope.onMenuClick = function($event, crudActions) {
console.warn('in onMenuClick')
console.warn('item.crudActions')
console.warn(crudActions)
if (angular.isObject($scope.selection_text)) {
console.log("requested action: " + action + "on scope.sel: '" + $scope.selection_text + "'")
// action on an existing Ngram
NgramHttpService[action]({
'listId': listId,
'ngramId': $scope.selection_text.uuid
}, function(data) {
// Refresh the annotationss
NgramListHttpService.get(
{
'corpusId': $rootScope.corpusId,
'docId': $rootScope.docId
},
function(data) {
$rootScope.annotations = data[$rootScope.corpusId.toString()][$rootScope.docId.toString()];
$rootScope.refreshDisplay();
},
function(data) {
console.error("unable to get the list of ngrams");
}
);
}, function(data) {
console.error("unable to edit the Ngram " + $scope.selection_text.text);
var ngramId = $scope.selection_text.uuid
var ngramText = $scope.selection_text.text
var lastCallback = function() {
// Refresh the annotationss
NgramListHttpService.get(
{'corpusId': $rootScope.corpusId,
'docId': $rootScope.docId},
function(data) {
$rootScope.annotations = data[$rootScope.corpusId.toString()][$rootScope.docId.toString()];
$rootScope.refreshDisplay();
},
function(data) {
console.error("unable to get the list of ngrams");
}
);
}
);
} else if ($scope.selection_text.trim() !== "") {
// new annotation from selection
NgramHttpService.post(
{
'listId': listId,
'ngramId': 'create'
},
{
'text': $scope.selection_text.trim()
}, function(data) {
// Refresh the annotationss
NgramListHttpService.get(
{
'corpusId': $rootScope.corpusId,
'docId': $rootScope.docId
},
function(data) {
$rootScope.annotations = data[$rootScope.corpusId.toString()][$rootScope.docId.toString()];
$rootScope.refreshDisplay();
},
function(data) {
console.error("unable to get the list of ngrams");
}
// chained recursion to do several actions then callback (eg refresh)
function makeChainedCalls (i, listOfActions, finalCallback) {
// each action couple has 2 elts
var action = listOfActions[i][0]
var listId = listOfActions[i][1]
console.log("===>"+action+"<===")
MainApiChangeNgramHttpService[action](
{'listId': listId,
'ngramIdList': ngramId},
// on success
function(data) {
// case NEXT
// ----
// when chained actions
if (listOfActions.length > i+1) {
console.log("calling next action ("+(i+1)+")")
// ==============================================
makeChainedCalls(i+1, listOfActions, finalCallback)
// ==============================================
}
// case LAST
// ------
// when last action
else {
finalCallback()
}
},
// on error
function(data) {
console.error("unable to edit the Ngram \""+ngramText+"\""
+"(ngramId "+ngramId+")"+"at crud no "+i
+" ("+action+" on list "+listId+")");
}
);
}, function(data) {
console.error("unable to edit the Ngram " + $scope.selection_text);
}
);
// run the loop by calling the initial recursion step
makeChainedCalls(0, crudActions, lastCallback)
}
// hide the highlighted text the the menu
// TODO: first action creates then like previous case
// else if ($scope.selection_text.trim() !== "") {
// // new annotation from selection
// NgramHttpService.post(
// {
// 'listId': listId,
// 'ngramId': 'create'
// },
// {
// 'text': $scope.selection_text.trim()
// }, function(data) {
// // Refresh the annotationss
// NgramListHttpService.get(
// {
// 'corpusId': $rootScope.corpusId,
// 'docId': $rootScope.docId
// },
// function(data) {
// $rootScope.annotations = data[$rootScope.corpusId.toString()][$rootScope.docId.toString()];
// $rootScope.refreshDisplay();
// },
// function(data) {
// console.error("unable to get the list of ngrams");
// }
// );
// }, function(data) {
// console.error("unable to edit the Ngram " + $scope.selection_text);
// }
// );
// }
// hide the highlighted text and the menu element
$(".text-panel").removeClass("selection");
$element.fadeOut(100);
};
......
......@@ -13,7 +13,7 @@
*
* route: annotations/documents/@d_id
* ------
*
* TODO use external: api/nodes/@d_id?fields[]=hyperdata
* exemple:
* --------
* {
......@@ -86,13 +86,19 @@
);
});
/*
* NgramHttpService: Create, modify or delete 1 Ngram
* =================
*
* TODO REACTIVATE IN urls.py
* TODO add a create case separately and then remove service
*
* NB : replaced by external api: (MainApiChangeNgramHttpService)
* api/ngramlists/change?list=LISTID&ngrams=ID1,ID2..
*
* if new ngram:
* old logic:
* ----------
* if new ngram
* -> ngram_id will be "create"
* -> route: annotations/lists/@node_id/ngrams/create
* -> will land on views.NgramCreate
......@@ -100,24 +106,61 @@
* else:
* -> ngram_id is a real ngram id
* -> route: annotations/lists/@node_id/ngrams/@ngram_id
* -> will land on views.NgramCreate
* -> will land on views.NgramEdit
*
*/
// http.factory('NgramHttpService', function ($resource) {
// return $resource(
// window.ANNOTATION_API_URL + 'lists/:listId/ngrams/:ngramId',
// {
// listId: '@listId',
// ngramId: '@id'
// },
// {
// post: {
// method: 'POST',
// params: {'listId': '@listId', 'ngramId': '@ngramId'}
// },
// delete: {
// method: 'DELETE',
// params: {'listId': '@listId', 'ngramId': '@ngramId'}
// }
// }
// );
// });
/*
* MainApiChangeNgramHttpService: Add/remove ngrams from lists
* =============================
* route: api/ngramlists/change?list=LISTID&ngrams=ID1,ID2...
*
* (same route used in ngrams table)
*
* /!\ for this route we reach out of this annotation module
* and send directly to the gargantext api route for list change
* (cross origin request with http protocol scheme)
* ------
*
*/
http.factory('NgramHttpService', function ($resource) {
http.factory('MainApiChangeNgramHttpService', function($resource) {
return $resource(
window.ANNOTATION_API_URL + 'lists/:listId/ngrams/:ngramId',
{
// adding explicit "http://" b/c this a cross origin request
'http://' + window.GARG_ROOT_URL
+ "/api/ngramlists/change?list=:listId&ngrams=:ngramIdList",
{
listId: '@listId',
ngramId: '@id'
ngramIdList: '@ngramIdList' // list in str form (sep=","): "12,25,30"
// (usually in this app just 1 id): "12"
},
{
post: {
method: 'POST',
params: {'listId': '@listId', 'ngramId': '@ngramId'}
{
put: {
method: 'PUT',
params: {listId: '@listId', ngramIdList: '@ngramIdList'}
},
delete: {
method: 'DELETE',
params: {'listId': '@listId', 'ngramId': '@ngramId'}
params: {listId: '@listId', ngramIdList: '@ngramIdList'}
}
}
);
......
......@@ -7,39 +7,101 @@
* Controls one Ngram displayed in the flat lists (called "extra-text")
*/
annotationsAppNgramList.controller('NgramController',
['$scope', '$rootScope', 'NgramHttpService', 'NgramListHttpService',
function ($scope, $rootScope, NgramHttpService, NgramListHttpService) {
['$scope', '$rootScope', 'MainApiChangeNgramHttpService', 'NgramListHttpService',
function ($scope, $rootScope, MainApiChangeNgramHttpService, NgramListHttpService) {
/*
* Click on the 'delete' cross button
* (NB: we have different delete consequences depending on list)
*/
$scope.onDeleteClick = function () {
NgramHttpService.delete({
'listId': $scope.keyword.list_id,
'ngramId': $scope.keyword.uuid
}, function(data) {
// Refresh the annotationss
NgramListHttpService.get(
{
'corpusId': $rootScope.corpusId,
'docId': $rootScope.docId
},
function(data) {
// $rootScope.annotations
// ----------------------
// is the union of all lists, one being later "active"
// (then used for left-side flatlist AND inline annots)
$rootScope.annotations = data[$rootScope.corpusId.toString()][$rootScope.docId.toString()];
// TODO £NEW : lookup obj[list_id][term_text] = {terminfo}
// $rootScope.lookup =
$rootScope.refreshDisplay();
},
function(data) {
console.error("unable to refresh the list of ngrams");
}
);
}, function(data) {
console.error("unable to remove the Ngram " + $scope.keyword.text);
});
var listName = $scope.keyword.listName
var thisListId = $scope.keyword.list_id
var thisNgramId = $scope.keyword.uuid
var crudActions = [] ;
if (listName == 'MAPLIST') {
crudActions = [
["delete", thisListId]
]
}
else if (listName == 'MAINLIST') {
crudActions = [
["delete", thisListId],
["put", $rootScope.listIds.STOPLIST],
]
}
else if (listName == 'STOPLIST') {
crudActions = [
["delete", thisListId],
["put", $rootScope.listIds.MAINLIST],
]
}
// using recursion to make chained calls,
// todo factorize with highlight.js
var lastCallback = function() {
// Refresh the annotationss
NgramListHttpService.get(
{'corpusId': $rootScope.corpusId,
'docId': $rootScope.docId},
function(data) {
// $rootScope.annotations
// ----------------------
// is the union of all lists, one being later "active"
// (then used for left-side flatlist AND inline annots)
$rootScope.annotations = data[$rootScope.corpusId.toString()][$rootScope.docId.toString()];
// TODO £NEW : lookup obj[list_id][term_text] = {terminfo}
// $rootScope.lookup =
$rootScope.refreshDisplay();
},
function(data) {
console.error("unable to refresh the list of ngrams");
}
);
}
// chained recursion to do several actions then callback (eg refresh)
function makeChainedCalls (i, listOfActions, finalCallback) {
// each action couple has 2 elts
var action = listOfActions[i][0]
var listId = listOfActions[i][1]
MainApiChangeNgramHttpService[action](
{'listId': thisListId,
'ngramIdList': thisNgramId},
// on success
function(data) {
// case NEXT
// ----
// when chained actions
if (listOfActions.length > i+1) {
console.log("calling next action ("+(i+1)+")")
// ==============================================
makeChainedCalls(i+1, listOfActions, finalCallback)
// ==============================================
}
// case LAST
// ------
// when last action
else {
finalCallback()
}
},
// on error
function(data) {
console.error("unable to edit the Ngram \""+ngramText+"\""
+"(ngramId "+ngramId+")"+"at crud no "+i
+" ("+action+" on list "+listId+")");
}
);
}
// run the loop by calling the initial recursion step
makeChainedCalls(0, crudActions, lastCallback)
};
}]);
......@@ -82,8 +144,8 @@
* new NGram from the user input
*/
annotationsAppNgramList.controller('NgramInputController',
['$scope', '$rootScope', '$element', 'NgramHttpService', 'NgramListHttpService',
function ($scope, $rootScope, $element, NgramHttpService, NgramListHttpService) {
['$scope', '$rootScope', '$element', 'NgramListHttpService',
function ($scope, $rootScope, $element, NgramListHttpService) {
/*
* Add a new NGram from the user input in the extra-text list
*/
......@@ -114,46 +176,47 @@
// ---------------------------------------------------------------
// will check if there's a preexisting ngramId for this value
// TODO: reconnect separately from list addition
// TODO: if maplist => also add to miam
NgramHttpService.post(
{
'listId': listId,
'ngramId': 'create'
},
{
'text': value
},
function(data) {
console.warn("refresh attempt");
// on success
if (data) {
angular.element(inputEltId).val("");
// Refresh the annotationss
NgramListHttpService.get(
{
'corpusId': $rootScope.corpusId,
'docId': $rootScope.docId
},
function(data) {
$rootScope.annotations = data[$rootScope.corpusId.toString()][$rootScope.docId.toString()];
// TODO £NEW : lookup obj[list_id][term_text] = {terminfo}
// $rootScope.lookup =
$rootScope.refreshDisplay();
},
function(data) {
console.error("unable to get the list of ngrams");
}
);
}
}, function(data) {
// on error
angular.element(inputEltId).parent().addClass("has-error");
console.error("error adding Ngram "+ value);
}
);
// NgramHttpService.post(
// {
// 'listId': listId,
// 'ngramId': 'create'
// },
// {
// 'text': value
// },
// function(data) {
// console.warn("refresh attempt");
// // on success
// if (data) {
// angular.element(inputEltId).val("");
// // Refresh the annotationss
// NgramListHttpService.get(
// {
// 'corpusId': $rootScope.corpusId,
// 'docId': $rootScope.docId
// },
// function(data) {
// $rootScope.annotations = data[$rootScope.corpusId.toString()][$rootScope.docId.toString()];
//
// // TODO £NEW : lookup obj[list_id][term_text] = {terminfo}
// // $rootScope.lookup =
//
//
// $rootScope.refreshDisplay();
// },
// function(data) {
// console.error("unable to get the list of ngrams");
// }
// );
// }
// }, function(data) {
// // on error
// angular.element(inputEltId).parent().addClass("has-error");
// console.error("error adding Ngram "+ value);
// }
// );
};
}]);
......
......@@ -118,7 +118,7 @@
<!-- this menu is over the text on mouse selection -->
<div ng-controller="TextSelectionMenuController" id="selection" class="selection-menu">
<ul class="noselection">
<li ng-repeat="item in menuItems" class="{[{item.listName}]}" ng-click="onMenuClick($event, item.action, item.listId)">{[{item.verb}]} {[{item.listName}]}</li>
<li ng-repeat="item in menuItems" class="{[{item.tgtListName}]}" ng-click="onMenuClick($event, item.crudActions)">Move to {[{item.tgtListName}]}</li>
</ul>
</div>
</div>
......
......@@ -13,13 +13,10 @@ urlpatterns = [
url(r'^documents/(?P<doc_id>[0-9]+)$', views.Document.as_view()), # document view
# GET [NgramListHttpService]
# was : lists ∩ document (ngram_ids intersection if connected to list node_id and doc node_id)
# fixed 2016-01: just lists (because document doesn't get updated by POST create cf. ngram.lists.DocNgram filter commented)
# ngrams from {lists ∩ document}
url(r'^corpora/(?P<corpus_id>[0-9]+)/documents/(?P<doc_id>[0-9]+)$', views.NgramList.as_view()), # the list associated with an ngram
# 2016-03-24: refactoring, deactivated NgramEdit and NgramCreate
#
# url(r'^lists/(?P<list_id>[0-9]+)/ngrams/(?P<ngram_ids>[0-9,\+]+)+$', views.NgramEdit.as_view()),
# POST (fixed 2015-12-16)
# 2016-05-27: removed NgramEdit: replaced the local httpservice by api/ngramlists
# url(r'^lists/(?P<list_id>[0-9]+)/ngrams/create$', views.NgramCreate.as_view()), #
]
......@@ -93,79 +93,8 @@ class NgramList(APIView):
# 2016-03-24: refactoring, deactivated NgramEdit and NgramCreate
# 2016-05-27: removed NgramEdit: replaced the local httpservice by api/ngramlists
# ------------------------------------
# class NgramEdit(APIView):
# """
# Actions on one existing Ngram in one list
# """
# renderer_classes = (JSONRenderer,)
# authentication_classes = (SessionAuthentication, BasicAuthentication)
#
# def post(self, request, list_id, ngram_ids):
# """
# Edit an existing NGram in a given list
# """
# # implicit global session
# list_id = int(list_id)
# list_node = session.query(Node).filter(Node.id==list_id).first()
# # TODO add 1 for MapList social score ?
# if list_node.type_id == cache.NodeType['MiamList']:
# weight=1.0
# elif list_node.type_id == cache.NodeType['StopList']:
# weight=-1.0
#
# # TODO remove the node_ngram from another conflicting list
# for ngram_id in ngram_ids.split('+'):
# ngram_id = int(ngram_id)
# node_ngram = NodeNgram(node_id=list_id, ngram_id=ngram_id, weight=weight)
# session.add(node_ngram)
#
# session.commit()
#
# # return the response
# return Response({
# 'uuid': ngram_id,
# 'list_id': list_id,
# } for ngram_id in ngram_ids)
#
# def put(self, request, list_id, ngram_ids):
# return Response(None, 204)
#
# def delete(self, request, list_id, ngram_ids):
# """
# Delete a ngram from a list
# """
# # implicit global session
# print("to del",ngram_ids)
# for ngram_id in ngram_ids.split('+'):
# print('ngram_id', ngram_id)
# ngram_id = int(ngram_id)
# (session.query(NodeNgram)
# .filter(NodeNgram.node_id==list_id)
# .filter(NodeNgram.ngram_id==ngram_id).delete()
# )
#
# session.commit()
#
# # [ = = = = del from map-list = = = = ]
# list_id = session.query(Node).filter(Node.id==list_id).first()
# corpus = session.query(Node).filter(Node.id==list_id.parent_id , Node.type_id==cache.NodeType['Corpus'].id).first()
# node_mapList = get_or_create_node(nodetype='MapList', corpus=corpus )
# results = session.query(NodeNgram).filter(NodeNgram.node_id==node_mapList.id ).all()
# ngram_2del = [int(i) for i in ngram_ids.split('+')]
# ngram_2del_ = session.query(NodeNgram).filter(NodeNgram.node_id==node_mapList.id , NodeNgram.ngram_id.in_(ngram_2del) ).all()
# for map_node in ngram_2del_:
# session.delete(map_node)
# session.commit()
#
# node_stopList = get_or_create_node(nodetype='StopList', corpus=corpus )
# for ngram_id in ngram_2del:
# stop_node = NodeNgram( weight=1.0, ngram_id=ngram_id , node_id=node_stopList.id)
# session.add(stop_node)
# session.commit()
# # [ = = = = / del from map-list = = = = ]
#
# return Response(None, 204)
#
# class NgramCreate(APIView):
# """
......
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