Search in sources :

Example 16 with FeatureVector

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

the class AffixesTest method testClassify.

@Test
public void testClassify() {
    FeatureVector result = affixesClassifier.classify(testWord);
    assertTrue(result != null);
    String[] resultArray = result.discreteValueArray();
    assertEquals("tion", resultArray[5]);
}
Also used : FeatureVector(edu.illinois.cs.cogcomp.lbjava.classify.FeatureVector) Test(org.junit.Test)

Example 17 with FeatureVector

use of edu.illinois.cs.cogcomp.lbjava.classify.FeatureVector 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

FeatureVector (edu.illinois.cs.cogcomp.lbjava.classify.FeatureVector)17 DiscretePrimitiveStringFeature (edu.illinois.cs.cogcomp.lbjava.classify.DiscretePrimitiveStringFeature)9 Token (edu.illinois.cs.cogcomp.lbjava.nlp.seg.Token)5 Constituent (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)3 EdisonException (edu.illinois.cs.cogcomp.edison.utilities.EdisonException)3 LinkedVector (edu.illinois.cs.cogcomp.lbjava.parse.LinkedVector)1 Parser (edu.illinois.cs.cogcomp.lbjava.parse.Parser)1 OutFile (edu.illinois.cs.cogcomp.ner.IO.OutFile)1 EOFException (java.io.EOFException)1 File (java.io.File)1 Vector (java.util.Vector)1 Test (org.junit.Test)1