0

So I've made an app that makes sentences, much like a keyboard of words and pictures, what I'd like to achieve is a kind of predictive text where if a user chooses X they are shown Y and Z, user doesnt want either of these and chooses A.

The next time the user picks X they are shown A, Y and Z, so it learns like your keyboard would, my words are stored in a database and right now i have a crude solution where if the user chooses X they are shown Y and Z, and I also track how many times each card is clicked and show them too but it has no context of full sentences or previously made sentences, i hope this is making sense as I've no idea where to start I've been looking at maybe a hashmap full of essentially TAGS as key value pairs and adding to it but I need to research this, I've also looked at candidate view but that would mean declaring my app as an Input Method I believe and I need the normal keyboard for other things, but I'm not sure how that works or if it's remotely viable so I'm hoping someone can educate me here or point to a better solution.

Below I'll post excerpts of what I'm doing thus far

   //Check what card was pressed and update predictedCardActivityDB example
   //to carry on like this would mean a lot of typing 
   //and not a lot of smart results

   if (cardsChoice.predictive == true) {
                String item = cardWriter.getCardSpeech();
                switch(item){
                    case " I":
                        String[] I_String = {"LIKE","LOVE","WANT"};
                        predictedCardActivityDB.prepareCardData
                        (I_String,getActivity(),prefString);
                        break;
                    case " I'm":
                        String[] Im_String = 
                        {"HAPPY","SAD","ANGRY","HUNGRY","FEELING"};
                        predictedCardActivityDB.prepareCardData
                        (Im_String,getActivity(),prefString);
                        break;

And this is the prepareCardData method excerpt nothing to see here just updates the lists based on the string array

 public static void prepareCardData
 (String[] predictionArray, Context context ,String prefString){


   //boring database stuff

    DaoMaster.DevOpenHelper helper = 
    new DaoMaster.DevOpenHelper(context, "ADD_NEW_CARD", null);
    SQLiteDatabase db = helper.getWritableDatabase();
    DaoMaster daoMaster = new DaoMaster(db);
    DaoSession daoSession = daoMaster.newSession();
    addNewCardDao leaseDao = daoSession.getAddNewCardDao();
    QueryBuilder qb = leaseDao.queryBuilder()
    .orderDesc(addNewCardDao.Properties.Clicked);
    QueryBuilder qb2 = leaseDao.queryBuilder()
    .orderDesc(addNewCardDao.Properties.Clicked);
    predictsList.clear();
    String[] strings1 = {"ORIGINAL","SIMPLE","PHOTOS", "USER"};

    switch (prefString){
    case "PHOTOS":

        if (predictionArray != null){

            //qb gets any card clicked >2 
            //qb gets all favourites tagged by a boolean

            qb.where(addNewCardDao.Properties.CardIconType.in(strings1),
                    qb.or(addNewCardDao.Properties.Clicked.ge(2),
                            addNewCardDao.Properties.Fav.ge(true)));
            predictsList = qb.list();

            //qb2 gets any card that matches a word from the passed in             
            //string array predictionArray 

            qb2 = leaseDao.queryBuilder();
            qb2.where(addNewCardDao.Properties.CardIconType.in(strings1),
            qb2.or(addNewCardDao.Properties.CardName.in(predictionArray),            
            addNewCardDao.Properties.CardTitle.in(predictionArray)));
            temptList = qb2.list();
            db.close();
            temptList.addAll(predictsList);


            predicts_card_adapter.notifyItemInserted(predictedCardActivityDB.temptList.size());
            predicts_card_adapter.notifyDataSetChanged();
            predicts_card_adapter = new predictsCardAdapter(temptList,itemTouchListener);
            predictsrecyclerView.setAdapter(predicts_card_adapter);

        }else{
            qb.where(addNewCardDao.Properties.CardIconType.in(strings1),
                    qb.or(addNewCardDao.Properties.Clicked.ge(2),
                            addNewCardDao.Properties.Fav.ge(true)));
            predictsList = qb.list();
            //this should work
            predicts_card_adapter.notifyDataSetChanged();
            predicts_card_adapter = new predictsCardAdapter(predictsList,itemTouchListener);
            predictsrecyclerView.setAdapter(predicts_card_adapter);
            db.close();
            System.out.println("else, predictsList size " + predictsList.size());
        }

    break;
}
    //should be able t delete this and use the two commented out piecess of code above
    //the result being the predicted cards coming first in the list
  /*
    predicts_card_adapter.notifyItemInserted(predictedCardActivityDB.temptList.size());
    predicts_card_adapter.notifyDataSetChanged();
    predicts_card_adapter = new predictsCardAdapter(temptList,itemTouchListener);
    predictsrecyclerView.setAdapter(predicts_card_adapter);
*/
}
Martin Seal
  • 616
  • 2
  • 14
  • 32

0 Answers0