com.aliasi.features
Class CacheFeatureExtractor<E>

java.lang.Object
  extended by com.aliasi.features.FeatureExtractorFilter<E>
      extended by com.aliasi.features.CacheFeatureExtractor<E>
Type Parameters:
E - Type of object whose features are extracted
All Implemented Interfaces:
FeatureExtractor<E>, Serializable

public class CacheFeatureExtractor<E>
extends FeatureExtractorFilter<E>
implements Serializable

A CacheFeatureExtractor uses a cache to store a mapping from objects to their feature vector maps.

Elements will be stored in the cache and looked up in the cache using the standard map methods put() and get(). It is up to the map to remove elements.

Thread Safety

A cached feature extractor will be thread safe if its contained cache is thread safe. A map may be made thread safe by wrapping it with synchronization. There are more live thread-safe maps in Java from the util.concurrent package. The FastCache and HardFastCache are also both thread safe. The only methods of the map accessed by this class are the put and get methods.

Serialization

A cached feature extractor will be serializable if its contained map and contained feature extractor are serializable. The current values in the cache will be included in the serialized value. To prevent serializing values, clear the cache before serializing it (the cache is accessible through the cache() method. The fast cache and most of Java's map implementations are serializable.

Since:
Lingpipe3.8
Version:
3.8
Author:
Bob Carpenter
See Also:
Serialized Form

Constructor Summary
CacheFeatureExtractor(FeatureExtractor<? super E> extractor, Map<E,Map<String,? extends Number>> cache)
          Construct a cached feature extractor that caches the results of the specified extractor using the specified cache.
 
Method Summary
 Map<E,Map<String,? extends Number>> cache()
          Returns the cache for this cached feature extractor.
 Map<String,? extends Number> features(E in)
          Return the features extracted by the contained feature extractor.
 
Methods inherited from class com.aliasi.features.FeatureExtractorFilter
baseExtractor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CacheFeatureExtractor

public CacheFeatureExtractor(FeatureExtractor<? super E> extractor,
                             Map<E,Map<String,? extends Number>> cache)
Construct a cached feature extractor that caches the results of the specified extractor using the specified cache.

Parameters:
extractor - Extractor to use to extract feature vectors.
cache - Cache in which to store extracted vectors.
Method Detail

cache

public Map<E,Map<String,? extends Number>> cache()
Returns the cache for this cached feature extractor. This is the actual cache used by this extractor, so changes to it affect this extractor.

Returns:
The cache for this feature extractor.

features

public Map<String,? extends Number> features(E in)
Description copied from class: FeatureExtractorFilter
Return the features extracted by the contained feature extractor.

Specified by:
features in interface FeatureExtractor<E>
Overrides:
features in class FeatureExtractorFilter<E>
Parameters:
in - Input to be converted to a feature vector.
Returns:
The map representing the feature vector for the input object.