本文整理汇总了Java中edu.stanford.nlp.trees.PennTreeReader.readTree方法的典型用法代码示例。如果您正苦于以下问题:Java PennTreeReader.readTree方法的具体用法?Java PennTreeReader.readTree怎么用?Java PennTreeReader.readTree使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.stanford.nlp.trees.PennTreeReader
的用法示例。
在下文中一共展示了PennTreeReader.readTree方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: stringToTree
import edu.stanford.nlp.trees.PennTreeReader; //导入方法依赖的package包/类
/**
* Build the Tree object from its string form.
*/
public static Tree stringToTree(String str, TreeFactory tf) {
try {
PennTreeReader ptr = new PennTreeReader(new BufferedReader(new StringReader(str)), tf);
Tree parseTree = ptr.readTree();
return parseTree;
} catch( Exception ex ) { ex.printStackTrace(); }
return null;
}
示例2: analyzeParsesNoCoref
import edu.stanford.nlp.trees.PennTreeReader; //导入方法依赖的package包/类
/**
* @desc Process parses for verbs
* @param parses The list of parses in String form
*/
private void analyzeParsesNoCoref( Vector<String> parses ) {
TreeFactory tf = new LabeledScoredTreeFactory();
Vector<String> verbs = new Vector();
// Save the verbs in each parse
int sentence = 0;
for( String parse : parses ) {
try {
// Read the parse
PennTreeReader ptr = new PennTreeReader(new BufferedReader(new StringReader(parse)), tf);
Tree ansTree = ptr.readTree();
// Look for the verbs in the tree
if( ansTree != null ) {
Vector<Tree> parseVerbs = TreeOperator.verbTreesFromTree(ansTree);
for( Tree verb : parseVerbs )
// verbs.add(verb.firstChild().firstChild().value());
verbs.add(verb.firstChild().value());
}
} catch( Exception ex ) { ex.printStackTrace(); }
sentence++;
}
// do the pair counts
countPairs(verbs);
}
示例3: analyzeParses
import edu.stanford.nlp.trees.PennTreeReader; //导入方法依赖的package包/类
private void analyzeParses( GigaDoc doc, Collection<String> parses, Collection<EntityMention> entities ) {
if( entities != null ) {
TreeFactory tf = new LabeledScoredTreeFactory();
// Read in all the parse trees
Tree trees[] = new Tree[parses.size()];
int i = 0;
for( String parse : parses ) {
try {
PennTreeReader ptr = new PennTreeReader(new BufferedReader(new StringReader(parse)), tf);
trees[i] = ptr.readTree();
} catch( Exception ex ) { ex.printStackTrace(); }
i++;
}
// Convert all entity spans from character spans to word-based
for( EntityMention mention : entities ) {
mention.convertCharSpanToIndex(TreeOperator.toRaw(trees[mention.sentenceID()-1]));
doc.addEntity(mention);
// mentions[mention.sentenceID()-1].add(mention);
}
// Save the verbs in each parse
int sid = 0, eid = 0;
for( Tree tree : trees ) {
if( tree != null ) {
// Look for the verbs in the tree
Vector<Tree> parseVerbs = TreeOperator.verbTreesFromTree(tree);
for( Tree verb : parseVerbs ) {
// System.out.println(" verb: " + verb + " index: " + (TreeOperator.wordIndex(tree,verb)+1));
doc.addEvent(new WordEvent(eid, verb.firstChild().value(), TreeOperator.wordIndex(tree,verb)+1, sid+1));
eid++;
}
sid++;
}
}
}
}
示例4: load
import edu.stanford.nlp.trees.PennTreeReader; //导入方法依赖的package包/类
public void load(String penn) throws IOException
{
Reader in = new StringReader(penn);
PennTreeReader tr = new PennTreeReader(in, new LabeledScoredTreeFactory(),
new NPTmpRetainingTreeNormalizer());
bufferTree = tr.readTree();
}
示例5: calculateIDFofVerbs
import edu.stanford.nlp.trees.PennTreeReader; //导入方法依赖的package包/类
/**
* Counts all *verbs* in the parse trees and tracks IDF counts.
*/
private void calculateIDFofVerbs( Vector<String> parses ) {
TreeFactory tf = new LabeledScoredTreeFactory();
HashMap<String,Boolean> seen = new HashMap(100);
HashMap<String,Boolean> seenLemmas = new HashMap(100);
// Loop over each parse tree
for( String parse : parses ) {
try {
PennTreeReader ptr = new PennTreeReader(new BufferedReader(new StringReader(parse)), tf);
Tree ansTree = ptr.readTree();
if( ansTree != null ) {
// Look for the verbs in the tree
Vector<Tree> parseVerbs = TreeOperator.verbTreesFromTree(ansTree);
for( Tree verb : parseVerbs ) {
String wordString = verb.firstChild().value().toLowerCase();
// Look for a particle
String particle = findParticleInTree(verb.parent(ansTree));
if( particle != null ) wordString += "_" + particle.toLowerCase();
// Don't count numerals or weird starting punctuation tokens
if( wordString.matches("[a-zA-Z].*") && !wordString.matches(".*\\d.*") ) {
// Count the documents the word appears in, for IDF score
if( !seen.containsKey(wordString) ) {
seen.put(wordString, true);
// add the count of documents
idf.increaseDocCount(wordString);
}
// Count the documents the lemma appears in, for IDF score
String lemmaString = verbToLemma(wordString);
if( lemmaString == null ) lemmaString = wordString;
if( !seenLemmas.containsKey(lemmaString) ) {
seenLemmas.put(lemmaString, true);
// add the count of documents
idfLemmas.increaseDocCount(lemmaString);
}
// Increment word frequency
idf.increaseTermFrequency(wordString);
idfLemmas.increaseTermFrequency(lemmaString);
}
}
}
} catch( Exception ex ) { ex.printStackTrace(); }
}
}