FirstCuratorExample.java

#

You can download this file here. This example shows how to create a TextAnnotation object by connecting to the Curator. It adds the part-of-speech, Named Entity and Stanford dependency views and prints them.

package edu.illinois.cs.cogcomp.edison.examples;

import java.util.List;

import org.apache.thrift.TException;

import edu.illinois.cs.cogcomp.edison.data.curator.CuratorClient;
import edu.illinois.cs.cogcomp.edison.sentences.TextAnnotation;
import edu.illinois.cs.cogcomp.edison.sentences.ViewNames;
import edu.illinois.cs.cogcomp.thrift.base.AnnotationFailedException;
import edu.illinois.cs.cogcomp.thrift.base.ServiceUnavailableException;

public class FirstCuratorExample {
	public static void main(String[] args) throws ServiceUnavailableException,
			AnnotationFailedException, TException {
#

This is the text we want to annotate.

		String text = "Good afternoon, gentlemen. I am a HAL-9000 "
				+ "computer. I was born in Urbana, Il. in 1992";

		String corpus = "2001_ODYSSEY";
		String textId = "001";
#

We need to specify a host and a port where the curator server is running.

		String curatorHost = "your-curator-server.cs.uiuc.edu";
		int curatorPort = 9090;

		CuratorClient client = new CuratorClient(curatorHost, curatorPort);
#

Should the curator's cache be forcibly updated?

		boolean forceUpdate = false;
#

Get the text annotation object from the curator, which splits the sentences and tokenizes it.

		TextAnnotation ta = client.getTextAnnotation(corpus, textId, text,
				forceUpdate);
#

Print the tokenized text

		System.out.println(ta.getTokenizedText());
#

Let's add the part of speech view and print it

		client.addPOSView(ta, forceUpdate);
#

The view is stored as ViewNames.POS. The class ViewNames defines a set of standard names for different views.

		System.out.println(ta.getView(ViewNames.POS));
#

Add the named entity view and print it.

		client.addNamedEntityView(ta, forceUpdate);
		System.out.println(ta.getView(ViewNames.NER));
#

Add the stanford dependency view and print the dependency tree

		client.addStanfordDependencyView(ta, forceUpdate);
		System.out.println(ta.getView(ViewNames.DEPENDENCY_STANFORD));

	}
}