FeaturesExample2.java

#
/**
 * 
 */
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.Constituent;
import edu.illinois.cs.cogcomp.edison.sentences.Queries;
import edu.illinois.cs.cogcomp.edison.sentences.Relation;
import edu.illinois.cs.cogcomp.edison.sentences.SpanLabelView;
import edu.illinois.cs.cogcomp.edison.sentences.TextAnnotation;
import edu.illinois.cs.cogcomp.edison.sentences.TreeView;
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 FeaturesExample2 {
	/**
	 * This example adds the Named Entity and Dependency views and prints all
	 * incoming and outgoing dependency edges for named entities.
	 * 
	 * @param args
	 * @throws ServiceUnavailableException
	 * @throws AnnotationFailedException
	 * @throws TException
	 */
	public static void main(String[] args) throws ServiceUnavailableException,
			AnnotationFailedException, TException {
		CuratorClient client = new CuratorClient("grandma.cs.uiuc.edu", 9010);

		String testExample = "Joseph Conrad Parkhurst , who founded the motorcycle magazine Cycle World in 1962 , has died.";

		System.out.println(testExample);

		boolean forceUpdate = false;
		TextAnnotation ta = client.getTextAnnotation("", "", testExample,
				forceUpdate);

		client.addNamedEntityView(ta, forceUpdate);
#
client.addEasyFirstDependencyView(ta, forceUpdate);
		client.addCharniakParse(ta, forceUpdate);
#
client.addSRLView(ta, forceUpdate);
#
client.addCorefView(ta, forceUpdate);
#

System.out.println(ta.getView(ViewNames.COREF));

		System.out.println(ta.getAvailableViews());

		SpanLabelView ne = (SpanLabelView) ta.getView(ViewNames.NER);
#
TreeView dependency = (TreeView) ta.getView(ViewNames.PARSE_CHARNIAK);
		TreeView dependency = (TreeView) ta.getView(ViewNames.DEPENDENCY);

		System.out.println(dependency);
		System.out.println(ne);

		for (Constituent neConstituent : ne.getConstituents()) {
			List<Constituent> depConstituents = (List<Constituent>) dependency
					.where(Queries.containedInConstituent(neConstituent));

			for (Constituent depConstituent : depConstituents) {
				System.out.println("Outgoing relations");

				for (Relation depRel : depConstituent.getOutgoingRelations()) {
					System.out.println("\t" + neConstituent + "--"
							+ depRel.getRelationName() + "--> "
							+ depRel.getTarget());
				}

				System.out.println("Incoming relations");

				for (Relation depRel : depConstituent.getIncomingRelations()) {
					System.out
							.println("\t" + depRel.getSource() + "--"
									+ depRel.getRelationName() + "--> "
									+ neConstituent);
				}
			}
		}
	}
}