FileDocCategorySizeDatePackage
FeatureAssembly.javaAPI DocAndroid 5.1 API3837Thu Mar 12 22:22:48 GMT 2015android.bordeaux.services

FeatureAssembly

public class FeatureAssembly extends Object

Fields Summary
private static final String
TAG
private List
mPossibleFeatures
private HashSet
mUseFeatures
private HashSet
mUsePairedFeatures
private AggregatorManager
mAggregatorManager
Constructors Summary
public FeatureAssembly()


      
        mAggregatorManager = AggregatorManager.getInstance();
        mPossibleFeatures = Arrays.asList(mAggregatorManager.getListOfFeatures());
        mUseFeatures = new HashSet<String>();
        mUsePairedFeatures = new HashSet<Pair<String, String> >();
    
Methods Summary
public java.lang.StringaugmentFeatureInputString(java.lang.String s)

        String fs = s;
        Iterator itr = mUseFeatures.iterator();
        while(itr.hasNext()) {
            String f = (String) itr.next();
            fs = fs + "+" + mAggregatorManager.getDataMap(f).get(f);
        }
        return fs;
    
public java.util.MapgetFeatureMap()

        HashMap<String, String> featureMap = new HashMap<String, String>();

        Iterator itr = mUseFeatures.iterator();
        while(itr.hasNext()) {
            String f = (String) itr.next();
            Map<String, String> features = mAggregatorManager.getDataMap(f);

            // TODO: sanity check for now.
            if (features.size() > 1) {
              throw new RuntimeException("Incorrect feature format extracted from aggregator.");
            }
            featureMap.putAll(features);
        }

        if (!mUsePairedFeatures.isEmpty()) {
            itr = mUsePairedFeatures.iterator();
            while(itr.hasNext()) {
                Pair<String, String> pair = (Pair<String, String>) itr.next();
                if (featureMap.containsKey(pair.first) &&
                    featureMap.containsKey(pair.second)) {
                    String key = pair.first + Predictor.FEATURE_SEPARATOR + pair.second;
                    String value = featureMap.get(pair.first) + Predictor.FEATURE_SEPARATOR +
                            featureMap.get(pair.second);
                    featureMap.put(key, value);
                }
            }
        }
        return (Map)featureMap;
    
public java.util.SetgetUsedFeatures()

        return (Set) mUseFeatures;
    
public booleanregisterFeature(java.lang.String s)

        if (mPossibleFeatures.contains(s)) {
            mUseFeatures.add(s);
            return true;
        } else {
            return false;
        }
    
public booleanregisterFeaturePair(java.lang.String[] features)

        if (features.length != 2 ||
            !mPossibleFeatures.contains(features[0]) ||
            !mPossibleFeatures.contains(features[1])) {
            return false;
        } else {
            mUseFeatures.add(features[0]);
            mUseFeatures.add(features[1]);
            mUsePairedFeatures.add(Pair.create(features[0], features[1]));
            return true;
        }