<!–Style guidelines: 1. Quote excerpts from Eclipse; commands, sections names, etc. 2. Italicize arguments: package names, class names, etc.
remember that italics are placed on text delineated with 2 apostrophes: ''italicized words''–> This page walks you through the steps necessary to creating the client-side interface for a basic annotation task. The steps explained here correspond to Eclipse 3.7.
In the Ccash project:
This operation should create two packages and one file:
In the Ccash project:
This operation should create the file DemoTask.java in the package edu.byu.nlp.ccash.tasks.demo.client.
AbstractAnnotationTask takes two generic parameters, I for the class of instances that you will be annotating, and A for the class of annotations you will be producing. For this tutorial, set both to String as follows:
public class DemoTask extends AbstractAnnotationTask<String, String>
Hover your mouse over the class name and click “Add unimplemented methods,” and then seven methods stubs should be generated. If you didn't uncheck “Inherited abstract methods” when you created the task, then the methods were auto-generated; you'll need to change some of the Object types to the more specific types for the generic types I and A (For this tutorial String).
The purposes of these methods are:
Here is a complete implementation of DemoTask:
package edu.byu.nlp.ccash.tasks.demo.client; import com.google.gwt.user.client.ui.AcceptsOneWidget; import com.google.gwt.user.client.ui.FlowPanel; import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.TextBox; import edu.byu.nlp.ccash.annotation.client.AbstractAnnotationTask; import edu.byu.nlp.ccash.client.datatransferobjects.DBAnnotationInstanceDTO; import edu.byu.nlp.ccash.common.client.events.CompletedHandler; import edu.byu.nlp.ccash.common.client.events.ValueChangedHandler; public class DemoTask extends AbstractAnnotationTask<String, String> { private TextBox labelDisplay; public DemoTask() { super(); labelDisplay = null; } @Override public String getDefaultInstanceProviderName() { return "DemoInstanceProvider"; } @Override protected void annotateInstanceDelegate(AcceptsOneWidget container, String instanceValue, String automaticAnnotationValue, CompletedHandler<String> finishedCallback, ValueChangedHandler<String> annotationChangeHandler, AnnotationValidatorCallback annotationTaskValidator, DBAnnotationInstanceDTO annotationInstance) { // Display instance Label instanceDisplay = new Label(); instanceDisplay.setText(instanceValue); // Display annotation labelDisplay = new TextBox(); labelDisplay.setText(automaticAnnotationValue); // Combine them in a parent panel FlowPanel panel = new FlowPanel(); panel.add(instanceDisplay); panel.add(labelDisplay); // Add the parent panel to the container container.setWidget(panel); } @Override protected String onCommitButtonClick() throws IncompleteAnnotationException { if (labelDisplay == null) { throw new NullPointerException("annotateInstanceDelegate should be called before onCommitButtonClick"); } String annotation = labelDisplay.getText(); if (annotation.isEmpty()) { throw new IncompleteAnnotationException(); } return annotation; } @Override protected void postprocessCompletedAnnotation(String annotation) { // ignore } @Override protected void receiveUpdateAutomaticAnnotation(String automaticAnnotation) { // ignore } @Override protected Class<String> getInstanceClass() { return String.class; } @Override protected Class<String> getAnnotationClass() { return String.class; } }
In the Ccash project:
This operation should create one file and add a line to the module definition:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.4.0//EN" "http://google-web-toolkit.googlecode.com/svn/tags/2.4.0/distro-source/core/src/gwt-module.dtd"> <module rename-to="demo"> <inherits name="edu.byu.nlp.ccash.Ccash" /> <source path="client" /> <entry-point class="edu.byu.nlp.ccash.tasks.demo.client.DemoEntryPoint"> </entry-point> </module>
Three method stubs should have been automatically generated. The purposes of the methods are:
Here is a complete implementation of DemoEntryPoint:
package edu.byu.nlp.ccash.tasks.demo.client; import edu.byu.nlp.ccash.annotation.client.AnnotationTaskEntryPoint; import edu.byu.nlp.ccash.annotation.client.AnnotationTaskInterface; public class DemoEntryPoint extends AnnotationTaskEntryPoint { @Override protected String getTaskName() { // replace with task name return "Demo Annotation Task"; } @Override protected String getTaskDescription() { // replace with task description return "This is the description of the " + getTaskName() + " task"; } @Override protected AnnotationTaskInterface<?, ?> getAnnotationTask() { // create the task and return it AnnotationTaskInterface<String, String> task = new DemoTask(); return task; } }
Now edit the main module edu.byu.nlp.ccash.Ccash.gwt.xml to add an “inherits” reference to your newly created module.
<inherits name='edu.byu.nlp.ccash.tasks.demo.Demo' />
Because you have added a module to the main module, your run configuration will need to change so that the arguments includes your new module. The easiest way to do this is to delete your old “Ccash” run configuration (if it existed) and then create a new one automatically by clicking on the Ccash project then clicking “Run as”→“Web Application.”
Now you can proceed to Creating an Annotation Manager. After that, you should be able to make a CCASH project from the pieces that you've constructed (see Setting Up a Simple Sentiment Classification Task for an example of how to assemble exiting tasks and annotation managers).
This example chose to extend AbstractAnnotationTask. However, you can choose to directly implement AnnotationTaskInterface, or to extend other tasks that offer different pre-baked feature sets: