FileDocCategorySizeDatePackage
BordeauxPredictor.javaAPI DocAndroid 5.1 API3876Thu Mar 12 22:22:48 GMT 2015android.bordeaux.services

BordeauxPredictor

public class BordeauxPredictor extends Object
Predictor for the Learning framework.

Fields Summary
static final String
TAG
static final String
PREDICTOR_NOTAVAILABLE
private android.content.Context
mContext
private String
mName
private android.bordeaux.services.IPredictor
mPredictor
Constructors Summary
public BordeauxPredictor(android.content.Context context)


       
        mContext = context;
        mName = "defaultPredictor";
        mPredictor = BordeauxManagerService.getPredictor(context, mName);
    
public BordeauxPredictor(android.content.Context context, String name)

        mContext = context;
        mName = name;
        mPredictor = BordeauxManagerService.getPredictor(context, mName);
    
Methods Summary
public voidaddSample(java.lang.String sampleName)

        if (!retrievePredictor())
            throw new RuntimeException(PREDICTOR_NOTAVAILABLE);
        try {
            mPredictor.pushNewSample(sampleName);
        } catch (RemoteException e) {
            Log.e(TAG,"Exception: pushing a new example");
            throw new RuntimeException(PREDICTOR_NOTAVAILABLE);
        }
    
public java.util.ArrayListgetTopSamples()

        return getTopSamples(0);
    
public java.util.ArrayListgetTopSamples(int topK)

        try {
            ArrayList<StringFloat> topList =
                    (ArrayList<StringFloat>) mPredictor.getTopCandidates(topK);

            ArrayList<Pair<String, Float> > topSamples =
                    new ArrayList<Pair<String, Float> >(topList.size());
            for (int i = 0; i < topList.size(); ++i) {
                topSamples.add(new Pair<String, Float>(topList.get(i).key, topList.get(i).value));
            }
            return topSamples;
        } catch(RemoteException e) {
            Log.e(TAG,"Exception: getTopSamples");
            throw new RuntimeException(PREDICTOR_NOTAVAILABLE);
        }
    
public booleanreset()

        if (!retrievePredictor()){
            Log.e(TAG, "reset: " + PREDICTOR_NOTAVAILABLE);
            return false;
        }
        try {
            mPredictor.resetPredictor();
            return true;
        } catch (RemoteException e) {
        }
        return false;
    
public booleanretrievePredictor()

        if (mPredictor == null) {
            mPredictor = BordeauxManagerService.getPredictor(mContext, mName);
        }
        if (mPredictor == null) {
            Log.e(TAG, "retrievePredictor: " + PREDICTOR_NOTAVAILABLE);
            return false;
        }
        return true;
    
public booleansetParameter(java.lang.String key, java.lang.String value)

        if (!retrievePredictor())
            throw new RuntimeException(PREDICTOR_NOTAVAILABLE);
        try {
            return mPredictor.setPredictorParameter(key, value);
        } catch (RemoteException e) {
            Log.e(TAG,"Exception: setting predictor parameter");
            throw new RuntimeException(PREDICTOR_NOTAVAILABLE);
        }