edu.stanford.nlp.trees.TreeGraphNodeFactory 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.trees;
import edu.stanford.nlp.ling.Label;
import edu.stanford.nlp.ling.LabelFactory;
import edu.stanford.nlp.ling.CoreLabel;
import java.util.List;
/**
* A {@code TreeGraphNodeFactory} acts as a factory for creating
* tree nodes of type {@link TreeGraphNode}. Unless
* another {@link LabelFactory} is supplied, it will use a CoreLabelFactory
* by default.
*
* @author Bill MacCartney
*/
public class TreeGraphNodeFactory implements TreeFactory {
private final LabelFactory mlf;
/**
* Make a {@code TreeFactory} that produces
* {@code TreeGraphNode}s. The labels are of class
* {@code CoreLabel}.
*/
public TreeGraphNodeFactory() {
this(CoreLabel.factory());
}
/**
* Make a {@code TreeFactory} that produces
* {@code TreeGraphNode}s. The labels depend on the
* {@code LabelFactory}.
*
* @param mlf The LabelFactory to use for node labels
*/
public TreeGraphNodeFactory(LabelFactory mlf) {
this.mlf = mlf;
}
/** {@inheritDoc} */
@Override
public Tree newLeaf(final String word) {
return newLeaf(mlf.newLabel(word));
}
/** {@inheritDoc} */
@Override
public Tree newLeaf(Label label) {
return new TreeGraphNode(label);
}
/** {@inheritDoc} */
@Override
public Tree newTreeNode(final String parent, final List children) {
return newTreeNode(mlf.newLabel(parent), children);
}
/** {@inheritDoc} */
@Override
public Tree newTreeNode(Label parentLabel, List children) {
return new TreeGraphNode(parentLabel, children);
}
}