edu.stanford.nlp.tagger.maxent.ExtractorDistsimConjunction 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.tagger.maxent;
/**
* Extractor for adding a conjunction of distsim information.
*
* @author rafferty
*/
public class ExtractorDistsimConjunction extends Extractor {
private static final long serialVersionUID = 1L;
private final Distsim lexicon;
private final int left;
private final int right;
private final String name;
@Override
String extract(History h, PairsHolder pH) {
StringBuilder sb = new StringBuilder();
for (int j = left; j <= right; j++) {
String word = pH.getWord(h, j);
String distSim = lexicon.getMapping(word);
sb.append(distSim);
if (j < right) {
sb.append('|');
}
}
return sb.toString();
}
/** Create an Extractor for conjunctions of Distsim classes
*
* @param distSimPath File path. If it contains a semi-colon, the material after it is interpreted
* as options to the Distsim class (q.v.)
* @param left Which position to start from (normally a non-positive number)
* @param right Which position to end with (normally a non-negative number)
*/
ExtractorDistsimConjunction(String distSimPath, int left, int right) {
super();
lexicon = Distsim.initLexicon(distSimPath);
this.left = left;
this.right = right;
name = "ExtractorDistsimConjunction(" + left + ',' + right + ')';
}
@Override
public String toString() {
return name;
}
@Override public boolean isLocal() { return false; }
@Override public boolean isDynamic() { return false; }
} // end static class ExtractorDistsimConjunction