Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support to move to the next unannotated document #1193

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ In order by changed lines of code ([Ballmer][ballmer] says [SLOC][sloc]
* David McClosky <david.mcclosky gmail com>
* Antony Scerri <a.scerri elsevier com>
* Jon Crump <jjcrump uw edu>
* Jose Gonzalez-Brenes <jgonzalez chegg com>

Extracted using the following bash one-liner:

Expand Down
25 changes: 25 additions & 0 deletions client/src/visualizer_ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -1530,6 +1530,26 @@ var VisualizerUI = (function($, window, undefined) {
}
};

var refreshAndMove = function(response) {
dispatcher.post('setDocument', [selectorData.items[response.new_pos][2],
selectorData.items[response.new_pos][1]]);
return false;

}

var nextUnannotated = function(dir) {
var pos = currentSelectorPosition();
// Request the server to reload collection:
console.log(selectorData.items)
dispatcher.post('ajax',
[{ action: 'get_next_unnanotated', collection: selectorData.collection, start: pos },
'refreshAndMove',
{collection: selectorData.collection, keep: true}]);


return false;
};

var moveInFileBrowser = function(dir) {
var pos = currentSelectorPosition();
var newPos = pos + dir;
Expand Down Expand Up @@ -2264,6 +2284,10 @@ var VisualizerUI = (function($, window, undefined) {
$('#type_collapse_limit')[0].value = Configuration.typeCollapseLimit;
}

$('#fast_forward').button().click(function() {
return nextUnannotated();
});

$('#prev').button().click(function() {
return moveInFileBrowser(-1);
});
Expand Down Expand Up @@ -2307,6 +2331,7 @@ var VisualizerUI = (function($, window, undefined) {
on('initForm', initForm).
on('collectionLoaded', rememberNormDb).
on('collectionLoaded', collectionLoaded).
on('refreshAndMove', refreshAndMove).
on('spanAndAttributeTypesLoaded', spanAndAttributeTypesLoaded).
on('isReloadOkay', isReloadOkay).
on('current', gotCurrent).
Expand Down
4 changes: 3 additions & 1 deletion index.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@
<div id="mainHeader" class="ui-widget-header">
<div id="mainlogo" class="logo unselectable">brat</div>
<span id="navbuttons">
<img id="prev" alt="Previous document (Cursor Left)" title="Previous document (Cursor Left)" src="static/img/arrow-180.png"/><img id="next" alt="Next document (Cursor Right)" title="Next document (Cursor Right)" src="static/img/arrow.png"/>
<img id="prev" alt="Previous document (Cursor Left)" title="Previous document (Cursor Left)" src="static/img/arrow-180.png"/>
<img id="next" alt="Next document (Cursor Right)" title="Next document (Cursor Right)" src="static/img/arrow.png"/>
<img id="fast_forward" alt="Next document without annotation" title="Next unannotated document" src="static/img/fast_forward.png"/>
</span>
<div id="document_name">
<input readonly="readonly" class="ui-widget-header"/>
Expand Down
3 changes: 2 additions & 1 deletion server/src/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from config import DATA_DIR
from convert.convert import convert
from docimport import save_import
from document import (get_directory_information, get_document,
from document import (get_directory_information,get_next_unnanotated, get_document,
get_document_timestamp, get_configuration)
from download import download_file, download_collection
from inspect import getargspec
Expand All @@ -47,6 +47,7 @@ def logging_no_op(collection, document, log):
# Function call-backs
DISPATCHER = {
'getCollectionInformation': get_directory_information,
'get_next_unnanotated': get_next_unnanotated,
'getDocument': get_document,
'getDocumentTimestamp': get_document_timestamp,
'importDocument': save_import,
Expand Down
26 changes: 26 additions & 0 deletions server/src/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,32 @@ def _inject_annotation_type_conf(dir_path, json_dic=None):

return json_dic

def get_next_unnanotated(collection, start):
directory = collection
start = int(start)
new_pos = start
real_dir = real_directory(directory)

assert_allowed_to_read(real_dir)

# Get the document names
base_names = [fn[0:-4] for fn in _listdir(real_dir)
if fn.endswith('txt')]

try:
stats_types, doc_stats = get_statistics(real_dir, base_names)
except OSError:
# something like missing access permissions?
raise CollectionNotAccessibleError

if start < len(doc_stats):
for i in range(start, len(doc_stats)): # Have to account for "." , ".."
if sum(doc_stats[i]) == 0:
new_pos = i + 1
break
return {"new_pos": new_pos}


# TODO: This is not the prettiest of functions
def get_directory_information(collection):
directory = collection
Expand Down
Binary file added static/img/fast_forward.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.