Search in sources :

Example 1 with POS_PRON

use of de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS_PRON in project dkpro-tc by dkpro.

the class PronounRatioFeatureExtractor method extract.

@Override
public Set<Feature> extract(JCas jcas, TextClassificationTarget aTarget) throws TextClassificationException {
    int heCount = 0;
    int sheCount = 0;
    int iCount = 0;
    int weCount = 0;
    int theyCount = 0;
    int usCount = 0;
    int youCount = 0;
    int n = 0;
    for (POS_PRON pronoun : JCasUtil.selectCovered(jcas, POS_PRON.class, aTarget)) {
        n++;
        String text = pronoun.getCoveredText().toLowerCase();
        if (text.equals("he")) {
            heCount++;
        } else if (text.equals("she")) {
            sheCount++;
        } else if (text.equals("i")) {
            iCount++;
        } else if (text.equals("we")) {
            weCount++;
        } else if (text.equals("they")) {
            theyCount++;
        } else if (text.equals("us")) {
            usCount++;
        } else if (text.equals("you")) {
            youCount++;
        }
    }
    Set<Feature> features = new HashSet<Feature>();
    if (n > 0) {
        features.add(new Feature(FN_HE_RATIO, (double) heCount / n, FeatureType.NUMERIC));
        features.add(new Feature(FN_SHE_RATIO, (double) sheCount / n, FeatureType.NUMERIC));
        features.add(new Feature(FN_I_RATIO, (double) iCount / n, FeatureType.NUMERIC));
        features.add(new Feature(FN_WE_RATIO, (double) weCount / n, FeatureType.NUMERIC));
        features.add(new Feature(FN_THEY_RATIO, (double) theyCount / n, FeatureType.NUMERIC));
        features.add(new Feature(FN_US_RATIO, (double) usCount / n, FeatureType.NUMERIC));
        features.add(new Feature(FN_YOU_RATIO, (double) youCount / n, FeatureType.NUMERIC));
    }
    return features;
}
Also used : POS_PRON(de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS_PRON) Feature(org.dkpro.tc.api.features.Feature) HashSet(java.util.HashSet)

Aggregations

POS_PRON (de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS_PRON)1 HashSet (java.util.HashSet)1 Feature (org.dkpro.tc.api.features.Feature)1