Kronosinhaven

Friday, July 8, 2011

typedependency

import edu.stanford.nlp.objectbank.TokenizerFactory;
import edu.stanford.nlp.parser.lexparser.LexicalizedParser;
import edu.stanford.nlp.process.*;
import edu.stanford.nlp.trees.*;
import java.io.*;
import java.util.*;
/**
*
* @author kronos
*/
public class typedependancyFinder {

public static List prsd_list;
public static LexicalizedParser lp = new LexicalizedParser("./res/englishPCFG.ser.gz");
public static InputStream in=null;
public static DataInputStream dis=null;
public static BufferedReader br=null;
public static TokenizerFactory tf = PTBTokenizer.factory(false, new WordTokenFactory());
public static TreePrint tp=null;
public static Tree t=null;
public static TreebankLanguagePack tlp = new PennTreebankLanguagePack();
public static GrammaticalStructureFactory gsf = tlp.grammaticalStructureFactory();
public static GrammaticalStructure gs=null;


public List getTypeDepndncy(String line)
{
List td=null;
try {
in=new ByteArrayInputStream(line.getBytes("UTF-8"));
dis = new DataInputStream(in);
br = new BufferedReader(new InputStreamReader(dis));
tp = new TreePrint("typedDependenciesCollapsed");
String sentence;
while ((sentence = br.readLine()) != null)
{
List tokens = tf.getTokenizer(new StringReader(sentence)).tokenize();
lp.parse(tokens);
t = lp.getBestParse();
gs = gsf.newGrammaticalStructure(t);
td=(List) gs.typedDependenciesCollapsed();
}
} catch (Exception e) {

System.out.println("" + e.toString());
e.printStackTrace();
}
return td;
}

public static void main(String[] args) {
System.out.println( new typedependancyFinder().getTypeDepndncy("It's unclear whether Wednesday's twist will affect the timing of Google's initial public offering"));
}

}

No comments:

Post a Comment