Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
junyangzhang authored and dreamyang-liu committed Jun 26, 2021
1 parent 0a0528f commit c2f8b2c
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
44 changes: 44 additions & 0 deletions client/src/annotator_ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -3348,6 +3348,7 @@ var AnnotatorUI = (function ($, window, undefined) {
0,
fullPath.length - document.length
);
console.log(collection);
$.post(
"ajax.cgi",
{
Expand Down Expand Up @@ -3375,6 +3376,44 @@ var AnnotatorUI = (function ($, window, undefined) {
);
});

var deleteEntity = function () {
let entity = $('input[id^="span_"]').filter(':checked').val();

let fullPath = window.location.href.split("#")[1];
let document = fullPath.split("/").reverse()[0];
let collection = fullPath.substr(
0,
fullPath.length - document.length
);

$.post(
"ajax.cgi",
{
protocol: 1,
action: "deleteEntity",
entity_name: entity,
collection: collection,
},
function () {
dispatcher.post("ajax", [
{
action:
"getCollectionInformation",
collection: collection,
},
"collectionLoaded",
{
collection: collection,
keep: true,
},
]);
// window.location = window.location.pathname + "#" + collection + folderName;
// $("#span_form").dialog("close");
}
);
}


var spanChangeLock = function (evt) {
var $this = $(evt.target);
var locked = $this.is(":checked");
Expand Down Expand Up @@ -3432,6 +3471,11 @@ var AnnotatorUI = (function ($, window, undefined) {
text: "Create Entity",
click: createEntity,
},
{
id: "span_form_delete_entity",
text: "Delete Entity",
click: deleteEntity,
},
],
create: function (evt) {
var $ok = $("#span_form-ok").wrap(
Expand Down
5 changes: 3 additions & 2 deletions server/src/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from newDocument import create_new_document, import_new_document, delete_new_document, create_folder
from createSpanAll import create_span_all_text, create_span_all_re
from utils import GLOBAL_LOGGER, fetch_all_annotations, prehandle_data, cache_model_results
from newEntity import create_new_entity
from newEntity import create_new_entity, delete_entity
# no-op function that can be invoked by client to log a user action


Expand Down Expand Up @@ -73,6 +73,7 @@ def logging_no_op(collection, document, log):
'splitSpan': split_span,

'createEntity': create_new_entity,
'deleteEntity': delete_entity,

'createArc': create_arc,
'reverseArc': reverse_arc,
Expand Down Expand Up @@ -133,7 +134,7 @@ def logging_no_op(collection, document, log):

# Actions that correspond to labeling function functionality
EXPAND_ACTION = {'labelingFunctionProcess', 'instantExecutor', 'addLabelingFunction', 'deleteLabelingFunction', 'getAvailableLabelingFunction', 'createSpanAllText',
'createSpanAllRe', 'fetchAllAnnotations', 'preprocessModelData', 'createNewDocument', 'importNewDocument','deleteNewDocument', 'createNewUser', 'cacheModelResults', 'createFolder', 'createEntity'}
'createSpanAllRe', 'fetchAllAnnotations', 'preprocessModelData', 'createNewDocument', 'importNewDocument','deleteNewDocument', 'createNewUser', 'cacheModelResults', 'createFolder', 'createEntity', 'deleteEntity'}

# Actions that correspond to annotation functionality
ANNOTATION_ACTION = {'createArc', 'deleteArc', 'createSpan', 'deleteSpan', 'splitSpan', 'suggestSpanTypes', 'undo'}
Expand Down
21 changes: 21 additions & 0 deletions server/src/newEntity.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,27 @@ def create_new_entity(**kwargs):
config.set_allow_duplicate(False)
config.archive()

res['status'] = 200

return res



def delete_entity(**kwargs):
res = dict()
entity = kwargs['entity_name']
collection = kwargs['collection']
real_dir = real_directory(collection)
config_dir = real_dir + "annotation.conf"
configstr = __read_or_default(config_dir, __default_configuration)
configstr = configstr.split("\n")

configstr.remove(entity)

with open(config_dir, 'w') as configFile:
configFile.write("\n".join(configstr))


res['status'] = 200

return res

0 comments on commit c2f8b2c

Please sign in to comment.