コード例 #1
0
  public void setCurrentSearch(Search newSearch, String result) {

    Action.Type actionType = null;
    yesNoSearch.setActive(true);
    yesNoSearch.setPotentialField(result);
    yesNoSearch.setResponse("Did you mean " + result + "?");
    // Set parent search for re-routing after user response
    if (Search.getCurrentSearch() != null && Search.getCurrentSearch() != yesNoSearch) {
      yesNoSearch.setParentSearch(Search.getCurrentSearch());
      Log.d(TAG, "parent search of yesNo search set to " + Search.getCurrentSearch().getName());
    }
    if (newSearch == binSearch) {
      actionType = Action.Type.LOG_BIN_ITEM;
    } else if (newSearch == typeSearch) {
      actionType = Action.Type.LOG_LITTER_TYPE;
    } else if (newSearch == brandSearch) {
      actionType = Action.Type.LOG_LITTER_BRAND;
    } else if (newSearch == yesNoSearch) {
      yesNoSearch.setYesAction(mActionHandler.getCurrentAction().getActionType());
      yesNoSearch.setNoAction(getActionFromSearch(yesNoSearch.getParentSearch()));
    }
    if (actionType != null) {
      mActionHandler.getCurrentAction().setActionType(actionType);
    }
    Search.setCurrentSearch(newSearch);
  }
コード例 #2
0
 public String processVoiceResults(ArrayList<String> matchedStrings) {
   Log.d(TAG, "Initial results = " + matchedStrings);
   // Default result is the most likely match of those returned
   String result = matchedStrings.get(0);
   boolean resultFound = false;
   for (int i = 0; i < Search.getCurrentSearch().getSearchObjects().size() && !resultFound; i++) {
     LocalEntity currentSearchItem = Search.getCurrentSearch().getSearchObjects().get(i);
     for (int j = 0; j < matchedStrings.size() && !resultFound; j++) {
       for (int k = 0; k < currentSearchItem.getSearchTerms().size() && !resultFound; k++) {
         //                    Log.d(TAG, "matched string = " + matchedStrings.get(j));
         //                    Log.d(TAG, "search string = " +
         // currentSearchItem.getSearchTerms().get(k));
         // If magic algorithm finds a match
         if (StringUtils.getLevenshteinDistance(
                     matchedStrings.get(j), currentSearchItem.getSearchTerms().get(k))
                 < (currentSearchItem.getSearchTerms().get(k).length() / 3)
             || currentSearchItem.getSearchTerms().get(k).equals(matchedStrings.get(j))) {
           resultFound = true;
           if (Search.getCurrentSearch().getName().equals("yesno")) {
             Log.d(TAG, "got here");
             result = currentSearchItem.getSearchTerms().get(k);
           } else {
             result = Search.getCurrentSearch().getSearchObjects().get(i).getName();
           }
           Log.d(TAG, "result = " + result);
           // If result found then update next search based on match
           processExpectedResult(result);
           return null;
         }
       }
     }
   }
   return processUnexpectedResult(result);
 }
コード例 #3
0
  // Deal with unexpected results
  private String processUnexpectedResult(String result) {

    String toastText = "";

    // Cancel item and start again if needed
    if (result.equals("cancel")
        || result.equals("council")
        || result.equals("Council")
        || result.equals("cancer")
        || result.equals("pencil")) {
      mOutingManager.speak("item cancelled");
      setCurrentSearch(brandSearch, result);
      mBin = null;
      mLitter = null;
      return null;
    }

    for (LocalEntity menuItem : menuSearch.getSearchObjects()) {
      if (menuItem.getSearchTerms().contains(result)) {
        setCurrentSearchByString(menuItem.getName());
        return null;
      }
    }

    if (!Search.getCurrentSearch().getName().equals("menu")) {
      toastText = "I haven't heard of " + result + ". Should I log it as other?";
      // log current item as 'other' and record the result
      yesNoSearch.setActive(true);
      yesNoSearch.setResponse(toastText);
      yesNoSearch.setPotentialOtherField(result);

      if (Search.getCurrentSearch().equals(brandSearch)) {
        mActionHandler.getCurrentAction().setActionType(Action.Type.LOG_OTHER_BRAND);
      }
      if (Search.getCurrentSearch().equals(typeSearch)) {
        mActionHandler.getCurrentAction().setActionType(Action.Type.LOG_OTHER_LITTER_TYPE);
      }
      if (Search.getCurrentSearch().equals(binSearch)) {
        mActionHandler.getCurrentAction().setActionType(Action.Type.LOG_OTHER_BIN_TYPE);
      }

      Log.d(TAG, "result at other: " + result);
      Log.d(TAG, "yesnosearch potentialotherfield set to " + yesNoSearch.getPotentialOtherField());
      Log.d(TAG, "currentSearch at unexpected result = " + Search.getCurrentSearch().getName());

      setCurrentSearch(yesNoSearch, "");
      return toastText;
    } else {
      setCurrentSearch(brandSearch, result);
      return null;
    }
  }
コード例 #4
0
  private void processExpectedResult(String result) {

    // If result is affirmative then assume it is in response to a confirmation question and
    // perform pending action associated with current search
    if (yesNoSearch.getYesTerms().getSearchTerms().contains(result)) {
      yesNoSearch.setActive(false);
      Log.d(TAG, "user answered yes");
      performAction(yesNoSearch.getYesAction(), result);
      return;
    }
    // If result is negative, assume it is in response to a confirmation as above
    if (yesNoSearch.getNoTerms().getSearchTerms().contains(result)) {
      yesNoSearch.setActive(false);
      Log.d(TAG, "user answered no");
      Log.d(TAG, "current no action = " + yesNoSearch.getNoAction());
      performAction(yesNoSearch.getNoAction(), result);
      return;
    }
    // Otherwise set next search, update UI and start listening for next input
    mActionHandler.setActionPerformed(false);
    setCurrentSearchByString(result);
    Log.d(TAG, "new current search before UI update = " + Search.getCurrentSearch().getName());
  }