Skip to content

Commit

Permalink
Merge pull request leonard-thong#16 from foreverjerry7/label_function…
Browse files Browse the repository at this point in the history
…_dev

add entity option
  • Loading branch information
dreamyang-liu committed Mar 23, 2021
2 parents f2f3800 + b401f6e commit f815497
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 1 deletion.
59 changes: 59 additions & 0 deletions client/src/annotator_ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -3321,6 +3321,60 @@ var AnnotatorUI = (function ($, window, undefined) {
$("#waiter").dialog("open");
};

var createEntity = function () {
dispatcher.post("showForm", [createEntityForm]);
}
var createEntityForm = $("#create_entity_form");
var createEntityFormSubmit = function (evt) {
dispatcher.post("hideForm");
return false;
}
createEntityForm.submit(createEntityFormSubmit);
initForm(createEntityForm, {
width: 550,
resizable: false,
no_cancel: true,
open: function (evt) {
keymap = {};
},
});
$("#create_entity_form-ok").click(function () {
// create new entity
let entity = $("#entity_name").val();
// let collection = window.location.href.split("#")[1];
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: "createEntity",
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 @@ -3373,6 +3427,11 @@ var AnnotatorUI = (function ($, window, undefined) {
text: "Split",
click: splitSpan,
},
{
id: "span_form_create_entity",
text: "Create Entity",
click: createEntity,
},
],
create: function (evt) {
var $ok = $("#span_form-ok").wrap(
Expand Down
15 changes: 15 additions & 0 deletions index.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,21 @@
</div>
</fieldset>
</form>
<form id="create_entity_form" class="dialog" title="Create Entity">
<fieldset class="small-buttons">
<legend>Create New Entity</legend>
<div>
<table class="fullwidth">
<tr>
<td>Entity Name</td>
<td>
<input id="entity_name" class="fullwidth" placeholder="Entity Name" />
</td>
</tr>
</table>
</div>
</fieldset>
</form>
<!-- Import dialog -->
<form id="import_document_form" class="dialog" title="Import Document">
<fieldset>
Expand Down
5 changes: 4 additions & 1 deletion server/src/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +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
# no-op function that can be invoked by client to log a user action


Expand Down Expand Up @@ -71,6 +72,8 @@ def logging_no_op(collection, document, log):
'deleteSpan': delete_span,
'splitSpan': split_span,

'createEntity': create_new_entity,

'createArc': create_arc,
'reverseArc': reverse_arc,
'deleteArc': delete_arc,
Expand Down Expand Up @@ -130,7 +133,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'}
'createSpanAllRe', 'fetchAllAnnotations', 'preprocessModelData', 'createNewDocument', 'importNewDocument','deleteNewDocument', 'createNewUser', 'cacheModelResults', 'createFolder', 'createEntity'}

# Actions that correspond to annotation functionality
ANNOTATION_ACTION = {'createArc', 'deleteArc', 'createSpan', 'deleteSpan', 'splitSpan', 'suggestSpanTypes', 'undo'}
Expand Down
31 changes: 31 additions & 0 deletions server/src/newEntity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import os
import shutil
import re
from document import real_directory
from os.path import join as path_join
from projectconfig import __parse_configs, __default_configuration, __read_or_default, SECTION_ALIAS, SEPARATOR_STR

def create_new_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")

# section = "general"
# section_lines = {section: []}
# section_labels = {}

for ln, l in enumerate(configstr):
if l == "[relations]":
configstr.insert(ln-2, entity)

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


res['status'] = 200

return res

0 comments on commit f815497

Please sign in to comment.