我怎样才能让我的应用像键盘一样学习?

时间:2016-12-02 22:52:03

标签: java android keyboard prediction candidate

所以我做了一个制作句子的应用程序,就像一个单词和图片的键盘,我想要实现的是一种预测文本,如果用户选择X,它们会显示为Y和Z,用户不想要其中任何一个并选择A。

下次用户选择X时会显示A,Y和Z,所以它会像你的键盘一样学习,我的文字存储在数据库中,现在我有一个粗略的解决方案,如果用户选择X,他们是显示Y和Z,我还跟踪每张卡被点击的次数并显示它们但它没有完整句子或先前制作的句子的上下文,我希望这是有意义的,因为我不知道从哪里开始我'我一直在寻找一个基本上都是TAGS的散列图作为关键值对并添加到它但我需要研究这个,我也看了候选视图但这意味着将我的应用声明为输入法我相信并且我需要其他东西的普通键盘,但我不确定它是如何工作的,或者它是否具有远程可行性,所以我希望有人可以在这里教育我或者指出更好的解决方案。

下面我将发布我到目前为止所做的摘录

   //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;

这就是prepareCardData方法的摘录,这里看不到只是根据字符串数组更新列表

 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);
*/
}

0 个答案:

没有答案