Search in sources :

Example 16 with DiscretePrimitiveStringFeature

use of edu.illinois.cs.cogcomp.lbjava.classify.DiscretePrimitiveStringFeature in project cogcomp-nlp by CogComp.

the class Chunker method cachedFeatureValue.

private Feature cachedFeatureValue(Object __example) {
    Token word = (Token) __example;
    String __cachedValue = word.type;
    if (__cachedValue != null) {
        return new DiscretePrimitiveStringFeature(containingPackage, name, "", __cachedValue, valueIndexOf(__cachedValue), (short) allowableValues().length);
    }
    Feature __result;
    __result = super.featureValue(__example);
    word.type = __result.getStringValue();
    return __result;
}
Also used : DiscretePrimitiveStringFeature(edu.illinois.cs.cogcomp.lbjava.classify.DiscretePrimitiveStringFeature) Token(edu.illinois.cs.cogcomp.lbjava.nlp.seg.Token) Feature(edu.illinois.cs.cogcomp.lbjava.classify.Feature) DiscretePrimitiveStringFeature(edu.illinois.cs.cogcomp.lbjava.classify.DiscretePrimitiveStringFeature)

Example 17 with DiscretePrimitiveStringFeature

use of edu.illinois.cs.cogcomp.lbjava.classify.DiscretePrimitiveStringFeature in project cogcomp-nlp by CogComp.

the class Capitalization method classify.

public FeatureVector classify(Object __example) {
    if (!(__example instanceof Word)) {
        String type = __example == null ? "null" : __example.getClass().getName();
        logger.error("Classifier 'Capitalization(Word)' defined on line 45 of CommonFeatures.lbj received '" + type + "' as input.");
        new Exception().printStackTrace();
        System.exit(1);
    }
    Word word = (Word) __example;
    FeatureVector __result;
    __result = new FeatureVector();
    String __id;
    String __value;
    int i;
    Word w = word, last = word;
    for (i = 0; i <= 2 && last != null; ++i) {
        last = (Word) last.next;
    }
    for (i = 0; i > -2 && w.previous != null; --i) {
        w = (Word) w.previous;
    }
    for (; w != last; w = (Word) w.next) {
        __id = "" + (i++);
        __value = "" + (w.capitalized);
        __result.addFeature(new DiscretePrimitiveStringFeature(this.containingPackage, this.name, __id, __value, valueIndexOf(__value), (short) 2));
    }
    return __result;
}
Also used : FeatureVector(edu.illinois.cs.cogcomp.lbjava.classify.FeatureVector) DiscretePrimitiveStringFeature(edu.illinois.cs.cogcomp.lbjava.classify.DiscretePrimitiveStringFeature)

Example 18 with DiscretePrimitiveStringFeature

use of edu.illinois.cs.cogcomp.lbjava.classify.DiscretePrimitiveStringFeature in project cogcomp-nlp by CogComp.

the class WordTypeInformation method classify.

public FeatureVector classify(Object __example) {
    if (!(__example instanceof Word)) {
        String type = __example == null ? "null" : __example.getClass().getName();
        logger.error("Classifier 'WordTypeInformation(Word)' defined on line 71 of CommonFeatures.lbj received '" + type + "' as input.");
        new Exception().printStackTrace();
        System.exit(1);
    }
    Word word = (Word) __example;
    FeatureVector __result;
    __result = new FeatureVector();
    String __id;
    String __value;
    int i;
    Word w = word, last = word;
    for (i = 0; i <= 2 && last != null; ++i) {
        last = (Word) last.next;
    }
    for (i = 0; i > -2 && w.previous != null; --i) {
        w = (Word) w.previous;
    }
    for (; w != last; w = (Word) w.next, ++i) {
        boolean allCapitalized = true, allDigits = true, allNonLetters = true;
        for (int j = 0; j < w.form.length(); ++j) {
            allCapitalized &= Character.isUpperCase(w.form.charAt(j));
            allDigits &= Character.isDigit(w.form.charAt(j));
            allNonLetters &= !Character.isLetter(w.form.charAt(j));
        }
        __id = "" + ("c" + i);
        __value = "" + (allCapitalized);
        __result.addFeature(new DiscretePrimitiveStringFeature(this.containingPackage, this.name, __id, __value, valueIndexOf(__value), (short) 2));
        __id = "" + ("d" + i);
        __value = "" + (allDigits);
        __result.addFeature(new DiscretePrimitiveStringFeature(this.containingPackage, this.name, __id, __value, valueIndexOf(__value), (short) 2));
        __id = "" + ("p" + i);
        __value = "" + (allNonLetters);
        __result.addFeature(new DiscretePrimitiveStringFeature(this.containingPackage, this.name, __id, __value, valueIndexOf(__value), (short) 2));
    }
    return __result;
}
Also used : FeatureVector(edu.illinois.cs.cogcomp.lbjava.classify.FeatureVector) DiscretePrimitiveStringFeature(edu.illinois.cs.cogcomp.lbjava.classify.DiscretePrimitiveStringFeature)

Aggregations

DiscretePrimitiveStringFeature (edu.illinois.cs.cogcomp.lbjava.classify.DiscretePrimitiveStringFeature)18 Feature (edu.illinois.cs.cogcomp.lbjava.classify.Feature)9 FeatureVector (edu.illinois.cs.cogcomp.lbjava.classify.FeatureVector)9 Token (edu.illinois.cs.cogcomp.lbjava.nlp.seg.Token)8