0

所以我制作了一个可以造句的应用程序,很像文字和图片的键盘,我想要实现的是一种预测文本,如果用户选择 X,他们会显示 Y 和 Z,用户也不想要其中并选择 A。

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

下面我将发布到目前为止我正在做的事情的摘录

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

0 回答 0