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

com.aliasi.features.ModifiedFeatureExtractor 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
/*
 * LingPipe v. 4.1.0
 * Copyright (C) 2003-2011 Alias-i
 *
 * This program is licensed under the Alias-i Royalty Free License
 * Version 1 WITHOUT ANY WARRANTY, without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the Alias-i
 * Royalty Free License Version 1 for more details.
 *
 * You should have received a copy of the Alias-i Royalty Free License
 * Version 1 along with this program; if not, visit
 * http://alias-i.com/lingpipe/licenses/lingpipe-license-1.txt or contact
 * Alias-i, Inc. at 181 North 11th Street, Suite 401, Brooklyn, NY 11211,
 * +1 (718) 290-9170.
 */

package com.aliasi.features;

import com.aliasi.util.FeatureExtractor;

import java.util.Map;
import java.util.HashMap;

/**
 * A {@code ModifiedFeatureExtractor} allows feature values to be
 * modified in a feature-specific fashion.
 *
 * @author Bob Carpenter
 * @version 3.8
 * @since Lingpipe3.8
 * @param  The type of objects whose features are extracted.
 */
public abstract class ModifiedFeatureExtractor
    extends FeatureExtractorFilter
    implements FeatureExtractor {

    /**
     * Construct a modified feature extractor with the specified
     * base extractor.
     *
     * @param extractor Base feature extractor.
     */
    public ModifiedFeatureExtractor(FeatureExtractor extractor) {
        super(extractor);
    }

    /**
     * Return the modified form of the feature vector produced by
     * the base feature extractor.  Each feature/value pair will
     * be passed through the method {@link #filter(String,Number)} to
     * produce a new value, which if non-null, is added to the
     * result.
     *
     * @return The modified feature vector.
     */
    @Override
    public Map features(E in) {
        Map featureMap = baseExtractor().features(in);
        Map result = new HashMap();
        for (Map.Entry entry : featureMap.entrySet()) {
            String feature = entry.getKey();
            Number originalValue = entry.getValue();
            Number value = filter(feature,originalValue);
            if (value == null) continue;
            result.put(feature,value);
        }
        return result;
    }

    /**
     * Return the value for the specified original feature and value,
     * or {@code null} to remove the feature altogether.
     *
     * 

This implementation passes through the value. * * @param feature Feature corresponding to the value. * @param value Value to filter. * @return The modified value or {@code null}. */ public Number filter(String feature, Number value) { return value; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy