edu.stanford.nlp.parser.lexparser.AbstractUnknownWordModelTrainer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of stanford-corenlp Show documentation
Show all versions of stanford-corenlp Show documentation
Stanford CoreNLP provides a set of natural language analysis tools which can take raw English language text input and give the base forms of words, their parts of speech, whether they are names of companies, people, etc., normalize dates, times, and numeric quantities, mark up the structure of sentences in terms of phrases and word dependencies, and indicate which noun phrases refer to the same entities. It provides the foundational building blocks for higher level text understanding applications.
package edu.stanford.nlp.parser.lexparser;
import java.util.Collection;
import java.util.List;
import edu.stanford.nlp.ling.TaggedWord;
import edu.stanford.nlp.trees.Tree;
import edu.stanford.nlp.util.Index;
public abstract class AbstractUnknownWordModelTrainer
implements UnknownWordModelTrainer
{
double treesRead;
double totalTrees;
Index wordIndex, tagIndex;
Options op;
Lexicon lex;
@Override
public void initializeTraining(Options op, Lexicon lex,
Index wordIndex,
Index tagIndex, double totalTrees) {
this.totalTrees = totalTrees;
this.treesRead = 0;
this.wordIndex = wordIndex;
this.tagIndex = tagIndex;
this.op = op;
this.lex = lex;
}
@Override
public final void train(Collection trees) {
train(trees, 1.0);
}
@Override
public final void train(Collection trees, double weight) {
for (Tree tree : trees) {
train(tree, weight);
}
}
@Override
public final void train(Tree tree, double weight) {
incrementTreesRead(weight);
int loc = 0;
List yield = tree.taggedYield();
for (TaggedWord tw : yield) {
train(tw, loc, weight);
++loc;
}
}
@Override
public void incrementTreesRead(double weight) {
treesRead += weight;
}
}