Search in sources :

Example 16 with DiscreteFeature

use of edu.illinois.cs.cogcomp.edison.features.DiscreteFeature in project cogcomp-nlp by CogComp.

the class ChunkWindowThreeBefore method getFeatures.

@Override
public /**
 * This feature extractor assumes that the TOKEN View and the SHALLOW_PARSE View have been
 * generated in the Constituents TextAnnotation. It will generate discrete features from
 * the chunk labels of the previous two tokens.
 */
Set<Feature> getFeatures(Constituent c) throws EdisonException {
    String classifier = "ChunkWindowThreeBefore";
    TextAnnotation ta = c.getTextAnnotation();
    TOKENS = ta.getView(ViewNames.TOKENS);
    SHALLOW_PARSE = ta.getView(ViewNames.SHALLOW_PARSE);
    // 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();
    // All our constituents are words(tokens)
    // two words before
    int k = -2;
    List<Constituent> wordstwobefore = getwordskfrom(TOKENS, startspan, endspan, k);
    String[] labels = new String[2];
    Set<Feature> result = new LinkedHashSet<Feature>();
    int i = 0;
    if (wordstwobefore.size() == 0) {
        return result;
    }
    for (Constituent token : wordstwobefore) {
        // Should only be one POS tag for each token
        List<String> Chunk_label = SHALLOW_PARSE.getLabelsCoveringSpan(token.getStartSpan(), token.getEndSpan());
        if (Chunk_label.size() != 1) {
            logger.warn("Error token has more than one POS tag or Chunk Label.");
        }
        labels[i] = Chunk_label.get(0);
        String __value = "(" + labels[i] + ")";
        String __id = classifier + ":" + (i++);
        result.add(new DiscreteFeature(__id + __value));
    }
    return result;
}
Also used : DiscreteFeature(edu.illinois.cs.cogcomp.edison.features.DiscreteFeature) TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) Feature(edu.illinois.cs.cogcomp.edison.features.Feature) DiscreteFeature(edu.illinois.cs.cogcomp.edison.features.DiscreteFeature) RealFeature(edu.illinois.cs.cogcomp.edison.features.RealFeature) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)

Example 17 with DiscreteFeature

use of edu.illinois.cs.cogcomp.edison.features.DiscreteFeature in project cogcomp-nlp by CogComp.

the class LabelOneAfter method getFeatures.

@Override
public Set<Feature> getFeatures(Constituent c) throws EdisonException {
    String classifier;
    String prefix = "LabelOneAfter";
    TextAnnotation ta = c.getTextAnnotation();
    int lenOfTokens = ta.getTokens().length;
    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 < lenOfTokens) {
                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 < lenOfTokens) {
                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 < lenOfTokens) {
                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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) TokenLabelView(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TokenLabelView) DiscreteFeature(edu.illinois.cs.cogcomp.edison.features.DiscreteFeature) TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) DiscreteFeature(edu.illinois.cs.cogcomp.edison.features.DiscreteFeature) Feature(edu.illinois.cs.cogcomp.edison.features.Feature)

Example 18 with DiscreteFeature

use of edu.illinois.cs.cogcomp.edison.features.DiscreteFeature in project cogcomp-nlp by CogComp.

the class PosWordConjunctionSizeTwoWindowSizeTwo method getFeatures.

@Override
public /**
 * This feature extractor assumes that the TOKEN View, POS View have been
 * generated in the Constituents TextAnnotation. It will use its own POS tag and well
 * as the form of the word as a forms of the words around the constitent a
 */
Set<Feature> getFeatures(Constituent c) throws EdisonException {
    TextAnnotation ta = c.getTextAnnotation();
    View TOKENS = null, POS = null;
    try {
        TOKENS = ta.getView(ViewNames.TOKENS);
        POS = ta.getView(ViewNames.POS);
    } catch (Exception e) {
        e.printStackTrace();
    }
    // 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();
    // All our constituents are words(tokens)
    // words two before & after
    int k = 2;
    int window = 2;
    String[] forms = getWindowK(TOKENS, startspan, endspan, k);
    String[] tags = getWindowKTags(POS, startspan, endspan, k);
    String classifier = "PosWordConjunctionSizeTwoWindowSizeTwo";
    String id, value;
    Set<Feature> result = new LinkedHashSet<>();
    for (int j = 0; j < k; j++) {
        for (int i = 0; i < tags.length; i++) {
            StringBuilder f = new StringBuilder();
            for (int context = 0; context <= j && i + context < tags.length; context++) {
                if (context != 0) {
                    f.append("_");
                }
                f.append(tags[i + context]);
                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 2
            id = classifier + ":" + ((i - window) + "_" + (j + 1));
            value = "(" + (f.toString()) + ")";
            result.add(new DiscreteFeature(id + value));
        }
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DiscreteFeature(edu.illinois.cs.cogcomp.edison.features.DiscreteFeature) TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) View(edu.illinois.cs.cogcomp.core.datastructures.textannotation.View) DiscreteFeature(edu.illinois.cs.cogcomp.edison.features.DiscreteFeature) Feature(edu.illinois.cs.cogcomp.edison.features.Feature) EdisonException(edu.illinois.cs.cogcomp.edison.utilities.EdisonException)

Example 19 with DiscreteFeature

use of edu.illinois.cs.cogcomp.edison.features.DiscreteFeature in project cogcomp-nlp by CogComp.

the class LabeledDepFeatureGenerator method SuffixConj.

private Set<Feature> SuffixConj(int head, int dep, DepInst sent, String deprel) {
    String header = "Suffix: ";
    String suffixhead = sent.strLemmas[head].substring(Math.max(sent.strLemmas[head].length() - 3, 0)) + " ";
    String suffixdep = sent.strLemmas[dep].substring(Math.max(sent.strLemmas[dep].length() - 3, 0)) + " ";
    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 + suffixhead + posdep + arcdir + deprel));
    feats.add(new DiscreteFeature(header + poshead + suffixdep + arcdir + deprel));
    feats.add(new DiscreteFeature(header + suffixhead + suffixdep + arcdir + deprel));
    return feats;
}
Also used : DiscreteFeature(edu.illinois.cs.cogcomp.edison.features.DiscreteFeature) Feature(edu.illinois.cs.cogcomp.edison.features.Feature) DiscreteFeature(edu.illinois.cs.cogcomp.edison.features.DiscreteFeature) HashSet(java.util.HashSet)

Aggregations

DiscreteFeature (edu.illinois.cs.cogcomp.edison.features.DiscreteFeature)19 Feature (edu.illinois.cs.cogcomp.edison.features.Feature)19 TextAnnotation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation)15 LinkedHashSet (java.util.LinkedHashSet)7 RealFeature (edu.illinois.cs.cogcomp.edison.features.RealFeature)6 TokenLabelView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TokenLabelView)5 HashSet (java.util.HashSet)4 Constituent (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)3 EdisonException (edu.illinois.cs.cogcomp.edison.utilities.EdisonException)3 View (edu.illinois.cs.cogcomp.core.datastructures.textannotation.View)2 IOException (java.io.IOException)2