All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aliasi.test.unit.features.StringLengthFeatureExtractorTest Maven / Gradle / Ivy

Go to download

This is the original Lingpipe: http://alias-i.com/lingpipe/web/download.html There were not made any changes to the source code.

There is a newer version: 4.1.2-JL1.0
Show newest version
package com.aliasi.test.unit.features;

import com.aliasi.features.StringLengthFeatureExtractor;

import com.aliasi.util.AbstractExternalizable;
import com.aliasi.util.FeatureExtractor;
import com.aliasi.util.ObjectToDoubleMap;

import org.junit.Test;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;

import java.io.IOException;
import java.io.NotSerializableException;

import java.util.Map;

public class StringLengthFeatureExtractorTest {

    
    @Test(expected = IllegalArgumentException.class)
    public void testEx1() {
        new StringLengthFeatureExtractor();
    }

    @Test(expected = IllegalArgumentException.class)
    public void testEx2() {
        new StringLengthFeatureExtractor(2,-1);
    }

    @Test
    public void testAll() throws IOException {
        StringLengthFeatureExtractor fe
            = new StringLengthFeatureExtractor(5, 1, 2);
        
        Map features
            = fe.features("");
        assertTrue(features.isEmpty());

        features = fe.features("a");
        assertEquals(1,features.size());
        assertEquals(1.0,features.get("LEN>=1").doubleValue(),0.0001);


        features = fe.features("abc");
        assertEquals(2,features.size());
        assertEquals(1.0,features.get("LEN>=1").doubleValue(),0.0001);
        assertEquals(1.0,features.get("LEN>=2").doubleValue(),0.0001);

        features = fe.features("abcdef");
        assertEquals(3,features.size());
        assertEquals(1.0,features.get("LEN>=1").doubleValue(),0.0001);
        assertEquals(1.0,features.get("LEN>=2").doubleValue(),0.0001);
        assertEquals(1.0,features.get("LEN>=5").doubleValue(),0.0001);


        @SuppressWarnings("unchecked")
        FeatureExtractor fe2
            = (FeatureExtractor)
            AbstractExternalizable.serializeDeserialize(fe);

        features = fe2.features("a");
        assertEquals(1,features.size());
        assertEquals(1.0,features.get("LEN>=1").doubleValue(),0.0001);


        features = fe2.features("abc");
        assertEquals(2,features.size());
        assertEquals(1.0,features.get("LEN>=1").doubleValue(),0.0001);
        assertEquals(1.0,features.get("LEN>=2").doubleValue(),0.0001);

        features = fe2.features("abcdef");
        assertEquals(3,features.size());
        assertEquals(1.0,features.get("LEN>=1").doubleValue(),0.0001);
        assertEquals(1.0,features.get("LEN>=2").doubleValue(),0.0001);
        assertEquals(1.0,features.get("LEN>=5").doubleValue(),0.0001);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy