FeaturesExample.java

#
/**
 * 
 */
package edu.illinois.cs.cogcomp.edison.examples;

import edu.illinois.cs.cogcomp.edison.annotators.ClauseViewGenerator;
import edu.illinois.cs.cogcomp.edison.annotators.PorterStemmer;
import edu.illinois.cs.cogcomp.edison.data.curator.CuratorClient;
import edu.illinois.cs.cogcomp.edison.features.helpers.PathFeatureHelper;
import edu.illinois.cs.cogcomp.edison.features.helpers.WordHelpers;
import edu.illinois.cs.cogcomp.edison.sentences.Constituent;
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.edison.utilities.WordNetManager;

/**
 * @author vsrikum2
 * 
 *         Mar 23, 2010
 */
public class FeaturesExample {
    public static void main(String[] args) throws Exception {
	String text = "Good afternoon, gentlemen. I am a HAL-9000 computer.";

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

	String curatorHost = "grandma.cs.uiuc.edu";
	int curatorPort = 9010;
	CuratorClient client = new CuratorClient(curatorHost, curatorPort);

	boolean forceUpdate = false;
	TextAnnotation ta = client.getTextAnnotation(corpus, textId, text,
		forceUpdate);
	client.addChunkView(ta, forceUpdate);

	client.addPOSView(ta, forceUpdate);

	client.addStanfordDependencyView(ta, forceUpdate);

	client.addCharniakParse(ta, forceUpdate);

	ta.addView(PorterStemmer.instance);

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

	WordNetManager wnManager = WordNetManager
		.getInstance("config/jwnl_properties.xml");
#

Get token level features

	int tokenId = 3;
	System.out.println(WordHelpers.getWord(ta, tokenId));
	System.out.println(WordHelpers.getPOS(ta, tokenId));
	System.out.println(WordHelpers.getLemma(ta, tokenId));
	System.out.println(WordHelpers.getSynset(ta, tokenId, wnManager));
#

tree features

	TreeView dependencyView = (TreeView) ta
		.getView(ViewNames.DEPENDENCY_STANFORD);

	System.out.println(dependencyView);
#

Suppose we want to get the path along the dependency tree from "HAL-9000" to "I". Also, suppose we somehow have constituents in the dependency tree corresponding to these.

	Constituent c1 = dependencyView.getConstituentsCoveringToken(8).get(0);
	Constituent c2 = dependencyView.getConstituentsCoveringToken(5).get(0);
#

The path string:

	System.out.println(PathFeatureHelper
		.getDependencyPathString(c1, c2, 40));
#

Clauses

	ta.addView(ClauseViewGenerator.CHARNIAK);
	SpanLabelView clauseView = (SpanLabelView) ta
		.getView(ViewNames.CLAUSES);

	System.out.println(clauseView);

    }

}