We are working on an annotation project where annotators should annotate based on words not characters. However, sometimes such mistakes occur. How can restrict annotation so that individual

I could not find a way to do this in Brat.

1

There are 1 best solutions below

0
On

It would be the easiest to instruct your annotators to double-click on a word instead of dragging the mouse, as a double click always selects the whole word.

However, if you want there is also a technical solution. This uses the Rangy Javascript library, which has functionality to expand a selection towards word boundaries. You can modify the source code of Brat to load this library and to perform the selection expansion every time the user presses Enter to annotate after selecting a (partial) word.

First, locate index.xhtml in your local Brat installation, which should be in the root folder. Add the following lines to the header where other Javascript libraries are loaded:

<script src="https://cdnjs.cloudflare.com/ajax/libs/rangy/1.3.1/rangy-core.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/rangy/1.3.1/rangy-textrange.js"></script>

For context, the header should look similar to the following after adding Rangy:

<title>brat</title>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8"/>
<meta name="google" value="notranslate"/>
<link href="static/jquery-theme/jquery-ui.css" rel="stylesheet" type="text/css"/>
<link href="static/jquery-theme/jquery-ui-redmond.css" rel="stylesheet" type="text/css"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/rangy/1.3.1/rangy-core.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/rangy/1.3.1/rangy-textrange.js"></script>
<script type="text/javascript" src="client/lib/head.load.min.js"></script>

Then, locate annotator_ui.js. This file can be found in brat/client/src. Find line 1789, which should read:

var tryToAnnotate = function(evt) {

Add the following line to the top of the function definition:

rangy.getSelection().expand("word");

For context, the start of the function should look as follows after the modification:

var tryToAnnotate = function(evt) {
rangy.getSelection().expand("word");
var sel = window.getSelection();
var theFocusNode = sel.focusNode;
if (!theFocusNode) return;

Reload the Brat interface. Then after selecting a partial word the full word will be presented in the annotation window, and saving the annotation will apply it to the full word as well.