从传入消息android broadcaster中提取特定关键字

时间:2018-05-01 20:11:57

标签: java android nlp keyword-search

我想从String中提取关键字。

表示我想从传入消息中提取所有关键字,然后检查数据库中的每个字符串是否存在。并忽略常用词(即我,我或,你,我,那,等等),只接受关键词,大学,人类,爱情,LGS等。

我怎么能在android中做到这一点?

主要问题是,检查特定关键字是否存在。

如果您有其他解决方案,请指导我。

谢谢 -

1 个答案:

答案 0 :(得分:0)

只需拆分字符串并走过列表。

String[] searchwords = myMessageString.split(" ");
int processedWords = 0;
ArrayList<String> foundWords = ArrayList<String>();
for ( int i=0; i < searchwords.length; i++) {
   myAsyncTaskSearchDatabase(searchwords[i]){
        public override onPostExecute(foundWordOrNull){
             processedWords++;
             if(foundWordOrNull != null){
                 foundWords.add(foundWordOrNull);
             }

             if(processedWords = searchwords.length){
                 //handle all found words
             }
        }
   }.execute();
}

---根据您的要求进行更新

 String[] searchwords = myMessageString.split(" ");
    bool wasFound = false;
    for ( int i=0; i < searchwords.length; i++) {
       new myAsyncTaskSearchDatabase(searchwords[i]){
            public override onPostExecute(foundWordOrNull){
                 processedWords++;
                 if(foundWordOrNull != null){
                     wasFound = true;
                 }

                 if(processedWords = searchwords.length){
                      if(wasFound){
                           //do something
                      }else{
                           //no matches
                      }
                 }
            }
       }.execute();
    }