use of edu.illinois.cs.cogcomp.edison.features.DiscreteFeature in project cogcomp-nlp by CogComp.
the class LabelOneBefore method getFeatures.
@Override
public Set<Feature> getFeatures(Constituent c) throws EdisonException {
String classifier;
String prefix = "LabelOneBefore";
TextAnnotation ta = c.getTextAnnotation();
int start = c.getStartSpan() - 1;
int end = c.getEndSpan() - 1;
Set<Feature> features = new LinkedHashSet<>();
for (int i = start; i < end; i++) {
if (!isPOSFromCounting) {
classifier = prefix + "_" + "POS";
if (i >= 0) {
TokenLabelView POSView = (TokenLabelView) ta.getView(ViewNames.POS);
String form = ta.getToken(i);
String tag = POSView.getLabel(i);
features.add(new DiscreteFeature(classifier + ":" + tag + "_" + form));
} else
features.add(new DiscreteFeature(classifier + ":" + ""));
} else if (isBaseLineCounting) {
classifier = prefix + "_" + "BaselinePOS";
if (i >= 0) {
String form = ta.getToken(i);
String tag = counter.tag(i, ta);
features.add(new DiscreteFeature(classifier + ":" + tag + "_" + form));
} else
features.add(new DiscreteFeature(classifier + ":" + ""));
} else {
classifier = prefix + "_" + "MikheevPOS";
if (i >= 0) {
String form = ta.getToken(i);
String tag = counter.tag(i, ta);
features.add(new DiscreteFeature(classifier + ":" + tag + "_" + form));
} else
features.add(new DiscreteFeature(classifier + ":" + ""));
}
}
return features;
}
use of edu.illinois.cs.cogcomp.edison.features.DiscreteFeature in project cogcomp-nlp by CogComp.
the class WordConjunctionOneTwoThreeGramWindowTwo method getFeatures.
@Override
public /**
* This feature extractor assumes that the TOKEN View has been generated in the Constituents TextAnnotation.
* It generate a feature for a window [-2, +2] of Forms (original text) for each constituent.
*/
Set<Feature> getFeatures(Constituent c) throws EdisonException {
TextAnnotation ta = c.getTextAnnotation();
TOKENS = ta.getView(ViewNames.TOKENS);
// We can assume that the constituent in this case is a Word(Token)
int startspan = c.getStartSpan();
int endspan = c.getEndSpan();
// k is 3 since we need up to 3-grams
int k = 3;
int window = 2;
// All our constituents are words(tokens)
String[] forms = getWindowK(TOKENS, startspan, endspan, window);
String id, value;
String classifier = "WordConjunctionOneTwoThreeGramWindowTwo";
Set<Feature> result = new LinkedHashSet<>();
for (int j = 0; j < k; j++) {
for (int i = 0; i < forms.length; i++) {
// forms.length = 5, So i goes from 0 to 4, for each String in the forms array.
StringBuilder f = new StringBuilder();
// and three word combinations within [-2,2] window or words.
for (int context = 0; context <= j && i + context < forms.length; context++) {
// add a '_' between words to conjoin them together
if (context != 0) {
f.append("_");
}
f.append(forms[i + context]);
}
// 2 is the center object in the array so i should go from -2 to +2 (with 0 being
// the center)
// j is the size of the n-gram so it goes 1 to 3
id = classifier + ":" + ((i - window) + "_" + (j + 1));
value = "(" + (f.toString()) + ")";
result.add(new DiscreteFeature(id + value));
}
}
return result;
}
use of edu.illinois.cs.cogcomp.edison.features.DiscreteFeature in project cogcomp-nlp by CogComp.
the class POSandPositionWindowThree method getFeatures.
@Override
public /**
* This feature extractor assumes that the TOKEN View and POS View have been
* generated in the Constituents TextAnnotation. It will use its own POS tag and well as the POS tag
* and the SHALLOW_PARSE (Chunk) labels of the previous two tokens and return it as a discrete feature.
*/
Set<Feature> getFeatures(Constituent c) throws EdisonException {
String classifier = "POSandPositionWindowThree";
TextAnnotation ta = c.getTextAnnotation();
TOKENS = ta.getView(ViewNames.TOKENS);
POS = ta.getView(ViewNames.POS);
// We can assume that the constituent in this case is a Word(Token) described by the LBJ
// chunk definition
int startspan = c.getStartSpan();
int endspan = c.getEndSpan();
int before = 3;
int after = 3;
// All our constituents are words(tokens)
String[] tags = new String[before + after + 1];
// three words before
int k = -3;
List<Constituent> wordsthreebefore = getwordskfrom(TOKENS, startspan, endspan, k);
int i = 0;
for (Constituent token : wordsthreebefore) {
// Should only be one POS tag for each token
List<String> POS_tag = POS.getLabelsCoveringSpan(token.getStartSpan(), token.getEndSpan());
if (POS_tag.size() != 1) {
logger.warn("Error token has more than one POS tag.");
}
tags[i] = POS_tag.get(0);
i++;
}
tags[i] = POS.getLabelsCoveringSpan(c.getStartSpan(), c.getEndSpan()).get(0);
i++;
// three words after
k = 3;
List<Constituent> wordsthreeafter = getwordskfrom(TOKENS, startspan, endspan, k);
for (Constituent token : wordsthreeafter) {
// Should only be one POS tag for each token
List<String> POS_tag = POS.getLabelsCoveringSpan(token.getStartSpan(), token.getEndSpan());
if (POS_tag.size() != 1) {
logger.info("Error token has more than one POS tag.");
}
tags[i] = POS_tag.get(0);
i++;
}
Set<Feature> __result = new LinkedHashSet<Feature>();
String __id;
String __value;
int contextmax = 3;
for (int j = 0; j < contextmax; j++) {
for (i = 0; i < tags.length; i++) {
StringBuffer f = new StringBuffer();
for (int context = 0; context <= j && i + context < tags.length; context++) {
if (context != 0) {
f.append("_");
}
f.append(tags[i + context]);
}
__id = "" + (i + "_" + j);
__value = "" + (f.toString());
__result.add(new DiscreteFeature(classifier + ":" + __id + "(" + __value + ")"));
}
}
return __result;
}
use of edu.illinois.cs.cogcomp.edison.features.DiscreteFeature in project cogcomp-nlp by CogComp.
the class LabeledDepFeatureGenerator method POSwinConj.
private Set<Feature> POSwinConj(int head, int dep, DepInst sent, String deprel) {
String header = "POSwin: ";
String headleft = "Left: " + (head > 0 ? sent.strPos[head - 1] : "null") + " ";
String headcenter = "Center: " + sent.strPos[head] + " ";
String headright = "Right: " + (head + 1 < sent.strPos.length ? sent.strPos[head + 1] : "null") + " ";
String depleft = "Left: " + (dep > 0 ? sent.strPos[dep - 1] : "null") + " ";
String depcenter = "Center: " + sent.strPos[dep] + " ";
String depright = "Right: " + (dep + 1 < sent.strPos.length ? sent.strPos[dep + 1] : "null") + " ";
String arcdir = "Arc-dir: " + (head < dep) + " ";
String arclength = "Arc-length: " + (head - dep) + " ";
Set<Feature> feats = new HashSet<>();
feats.add(new DiscreteFeature(header + headcenter + depcenter + arcdir + deprel));
feats.add(new DiscreteFeature(header + headcenter + depcenter + arclength + deprel));
feats.add(new DiscreteFeature(header + headleft + headcenter + headright + depleft + depcenter + depright + arcdir + deprel));
return feats;
}
use of edu.illinois.cs.cogcomp.edison.features.DiscreteFeature in project cogcomp-nlp by CogComp.
the class LabeledDepFeatureGenerator method PrefixConj.
private Set<Feature> PrefixConj(int head, int dep, DepInst sent, String deprel) {
String header = "Prefix: ";
String prefixhead = sent.strLemmas[head].substring(0, Math.min(sent.strLemmas[head].length(), 5)) + " ";
String prefixdep = sent.strLemmas[dep].substring(0, Math.min(sent.strLemmas[dep].length(), 5)) + " ";
String poshead = sent.strPos[head] + " ";
String posdep = sent.strPos[dep] + " ";
String arcdir = "Arc-dir: " + (head < dep) + " ";
Set<Feature> feats = new HashSet<>();
feats.add(new DiscreteFeature(header + prefixhead + posdep + arcdir + deprel));
feats.add(new DiscreteFeature(header + poshead + prefixdep + arcdir + deprel));
feats.add(new DiscreteFeature(header + prefixhead + prefixdep + arcdir + deprel));
return feats;
}
Aggregations