FileDocCategorySizeDatePackage
BordeauxRanker.javaAPI DocAndroid 5.1 API4816Thu Mar 12 22:22:48 GMT 2015android.bordeaux.services

BordeauxRanker

public class BordeauxRanker extends Object
Ranker for the Learning framework. For training: call updateClassifier with a pair of samples. For ranking: call scoreSample to the score of the rank Data is represented as sparse key, value pair. And key is a String, value is a float. Note: since the actual ranker is running in a remote the service. Sometimes the connection may be lost or not established.

Fields Summary
static final String
TAG
static final String
RANKER_NOTAVAILABLE
private android.content.Context
mContext
private String
mName
private android.bordeaux.services.ILearning_StochasticLinearRanker
mRanker
Constructors Summary
public BordeauxRanker(android.content.Context context)

        mContext = context;
        mName = "defaultRanker";
        mRanker = BordeauxManagerService.getRanker(context, mName);
    
public BordeauxRanker(android.content.Context context, String name)

        mContext = context;
        mName = name;
        mRanker = BordeauxManagerService.getRanker(context, mName);
    
Methods Summary
private java.util.ArrayListgetArrayList(java.util.HashMap sample)

          
        ArrayList<StringFloat> stringfloat_sample = new ArrayList<StringFloat>();
        for (Map.Entry<String, Float> x : sample.entrySet()) {
           StringFloat v = new StringFloat();
           v.key = x.getKey();
           v.value = x.getValue();
           stringfloat_sample.add(v);
        }
        return stringfloat_sample;
    
public booleanreset()

        if (!retrieveRanker()){
            Log.e(TAG,"Exception: Ranker is not availible");
            return false;
        }
        try {
            mRanker.ResetRanker();
            return true;
        } catch (RemoteException e) {
        }
        return false;
    
public booleanretrieveRanker()

        if (mRanker == null)
            mRanker = BordeauxManagerService.getRanker(mContext, mName);
        // if classifier is not available, return false
        if (mRanker == null) {
            Log.e(TAG,"Ranker not available.");
            return false;
        }
        return true;
    
public floatscoreSample(java.util.HashMap sample)

        if (!retrieveRanker())
            throw new RuntimeException(RANKER_NOTAVAILABLE);
        try {
            return mRanker.ScoreSample(getArrayList(sample));
        } catch (RemoteException e) {
            Log.e(TAG,"Exception: scoring the sample.");
            throw new RuntimeException(RANKER_NOTAVAILABLE);
        }
    
public booleansetParameter(java.lang.String key, java.lang.String value)

        if (!retrieveRanker())
            throw new RuntimeException(RANKER_NOTAVAILABLE);
        try {
            return mRanker.SetModelParameter(key, value);
        } catch (RemoteException e) {
            Log.e(TAG,"Exception: Setting Parameter");
            throw new RuntimeException(RANKER_NOTAVAILABLE);
        }
    
public booleansetPriorWeight(java.util.HashMap sample)

        if (!retrieveRanker())
            throw new RuntimeException(RANKER_NOTAVAILABLE);
        try {
            return mRanker.SetModelPriorWeight(getArrayList(sample));
        } catch (RemoteException e) {
            Log.e(TAG,"Exception: set prior Weights");
            throw new RuntimeException(RANKER_NOTAVAILABLE);
        }
    
public booleanupdate(java.util.HashMap sample1, java.util.HashMap sample2)

        if (!retrieveRanker())
            return false;
        try {
            mRanker.UpdateClassifier(getArrayList(sample1), getArrayList(sample2));
        } catch (RemoteException e) {
            Log.e(TAG,"Exception: updateClassifier.");
            return false;
        }
        return true;