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);
  }
 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);
 }
 @Test
 public void testSquareRoot() throws Exception {
   assertEquals(4, Search.squareRoot(16));
   assertEquals(13, Search.squareRoot(169));
   assertEquals(25, Search.squareRoot(625));
   assertEquals(-1, Search.squareRoot(626));
 }
Exemple #4
0
  /** 查询 */
  private void search() {
    // 调用查询窗口
    Function function = new Function();
    Search search = new Search(this, staffInfo);
    function.setFunctionDialog(search);
    function.create();
    if (search.isUpdate()) {
      int searched = search.getSearched();

      switch (searched) {
        case 0:
          DMManage();
          break;
        case 1:
          break;
        case 3:
          break;
        case 4:
          break;
        case 5:
          break;
      }
      content = search.getResultContent();
      header = search.getResultHeader();
      displayPanel.setBorder(
          BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "查询结果"));
      setTable(content, header);
    }
  }
Exemple #5
0
  /**
   * @param args
   * @throws IOException
   * @throws Exception
   */
  public static void main(String[] args) throws Exception {
    Search search = new Search();
    String query = "";
    System.out.println();
    System.err.println("Options: ");
    System.err.println("1) Always begin with 'search'");
    System.err.println("2) Hit option to fetch Top K-N. e.g.: search [--hits=10] [query]");
    System.err.println(
        "3) Relevance feedback,  e.g.: search [--relevant=(relevance document)] [query]");
    System.err.println(
        "4) Irrelevance feedback ,  e.g.: search [--irrelevant=(relevance document)] [query]");
    System.err.println("5) OR Query option, e.g.: search [--OR] [query]");
    System.err.println("6) AND Query option, e.g.: search [--AND] [query]");
    System.out.println("Type your query 'search [your query]' below or type 'quit' to exit :");
    System.out.println();

    InputStreamReader is = new InputStreamReader(System.in);
    BufferedReader br = new BufferedReader(is);
    while (!(query.equals("quit"))) {
      query = br.readLine();
      if (!(query.equals("quit"))) {
        search.checkArgument(query);
      }
    }
  }
  @RequestMapping(value = "/buildOrder.html", method = RequestMethod.GET)
  public ModelAndView get(HttpServletRequest request) {

    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("Redirecting to current order details page");
    }

    HttpSession session = request.getSession(true);
    String orderrestaurantid = (String) session.getAttribute("orderrestaurantid");
    String restaurantid = (String) session.getAttribute("restaurantid");
    Search search = (Search) session.getAttribute("search");

    if (orderrestaurantid != null) {
      restaurantid = orderrestaurantid;
    }

    if (restaurantid == null) {
      if (search == null) {
        return new ModelAndView("redirect:/home.html", null);
      } else {
        return new ModelAndView("redirect:/search.html" + search.getQueryString());
      }
    } else {
      Restaurant restaurant = restaurantRepository.findByRestaurantId(restaurantid);
      return new ModelAndView("redirect:/" + restaurant.getUrl());
    }
  }
Exemple #7
0
  @Override
  public QueryIterator execEvaluated(
      final Binding binding,
      PropFuncArg argSubject,
      Node predicate,
      PropFuncArg argObject,
      ExecutionContext execCxt) {
    // check subject is a variable.
    if (!argSubject.getArg().isVariable()) throw new QueryExecException("Subject not a variable");

    final Var var = Var.alloc(argSubject.getArg());

    if (!argObject.getArg().isLiteral()) throw new QueryExecException("Subject not a literal");

    String searchTerm = argObject.getArg().getLiteralLexicalForm();
    Search search = searchEngine();
    Iterator<String> x = search.search(searchTerm);
    Iter<String> iter = Iter.iter(x);
    QueryIterator qIter =
        new QueryIterPlainWrapper(
            iter.map(
                (item) -> {
                  return BindingFactory.binding(binding, var, NodeFactory.createURI(item));
                }));
    return qIter;
  }
 @Test
 public void testExhaustedCharacterSet() {
   Assert.assertFalse(search.exhaustedCharset("wants"));
   Assert.assertFalse(search.exhaustedCharset(Model.getBlob()));
   Assert.assertTrue(search.exhaustedCharset("zippo"));
   Assert.assertTrue(search.exhaustedCharset(Model.getBlob() + "a"));
 }
  /** Index the text and set the keywords field with the tokenized texts. */
  @Override
  public Cursor<T> text(String text) throws Exception {
    Search search = new Search();
    search.addAll(text);
    appendAll("__keywords", search.set());

    return this;
  }
  /** Index the text and set the keywords field with the tokenized texts. */
  @Override
  public Cursor<T> word(String word) throws Exception {
    Search search = new Search();
    search.add(word);
    for (String s : search.set()) append("__keywords", s);

    return this;
  }
 @Test
 public void testSearch() throws NoSuchAlgorithmException {
   search.setMatcher(new MatcherForMd5(matchingMd5));
   wordlist.addWord("poultry");
   wordlist.addWord("outwits");
   wordlist.addWord("ants");
   String phrase = search.findit();
   Assert.assertEquals(testPhrase, phrase);
 }
Exemple #12
0
 @Test
 public void testNaiveSearch3() {
   Search s = new Search();
   assertEquals(3, s.naiveSearch3("pattern", "ter"));
   assertEquals(0, s.naiveSearch3("pattern", "p"));
   assertEquals(6, s.naiveSearch3("pattern", "n"));
   assertEquals(-1, s.naiveSearch3("pattern", "u"));
   assertEquals(2, s.naiveSearch3("pattern", "t"));
 }
Exemple #13
0
 @Test
 public void testKmpSearch() {
   Search s = new Search();
   assertEquals(3, s.kmpSearch("pattern", "ter"));
   assertEquals(0, s.kmpSearch("pattern", "p"));
   assertEquals(6, s.kmpSearch("pattern", "n"));
   assertEquals(-1, s.kmpSearch("pattern", "u"));
   assertEquals(2, s.kmpSearch("pattern", "t"));
 }
Exemple #14
0
 /**
  * 根据查询条件,返回对象列表
  *
  * @param search 查询对象
  * @return
  */
 @SuppressWarnings("unchecked")
 public <X> List<X> search(final Class<T> entityClass, Search search) {
   if (search == null) throw new NullPointerException("Search is null.");
   if (search.getSearchClass() == null) throw new NullPointerException("Search class is null.");
   if (entityClass != null && !search.getSearchClass().equals(entityClass))
     throw new IllegalArgumentException(
         "Search class does not match expected type: " + entityClass.getName());
   return this.searchProcessor.search(
       this.getEntityManager().getPersistEntityManager(), entityClass, search);
 }
Exemple #15
0
 public static void main(String[] args) {
   Random rnd = new Random();
   Search s = new Search(10);
   for (int i = 0; i < 10; i++) {
     s.addTerm(i, rnd.nextInt(15));
   }
   s.sort();
   System.out.println(s);
   System.out.println(s.rbsearch(5));
 }
Exemple #16
0
 /** Renders the paging information into the title bar. */
 private void renderTitle() {
   int resultEnd = querySize;
   String totalStr;
   if (search.getTotal() != Search.UNKNOWN_SIZE) {
     resultEnd = Math.min(resultEnd, search.getTotal());
     totalStr = messages.of(search.getTotal());
   } else {
     totalStr = messages.ofUnknown();
   }
   searchUi.setTitleText(queryText + " (0-" + resultEnd + " " + totalStr + ")");
 }
Exemple #17
0
  /** 按属性查找唯一对象, 匹配方式为相等. */
  @SuppressWarnings("unchecked")
  public T findUniqueByProperty(
      final Class<T> entityClass, final String propertyName, final Object value) {

    Search search = new Search(entityClass);
    search.setResultMode(Search.RESULT_SINGLE);
    SearchUtil.addFilterEqual(search, propertyName, value);

    return (T)
        searchProcessor.searchUnique(this.getEntityManager().getPersistEntityManager(), search);
  }
 @Test
 public void testMakeTestPhrase() {
   int[] indexArray = search.makeIndexArray();
   wordlist.addWord("this");
   wordlist.addWord("isa");
   wordlist.addWord("test");
   indexArray[0] = 0;
   indexArray[1] = 1;
   indexArray[2] = 2;
   String phrase = search.makePhrase(indexArray);
   Assert.assertEquals("this isa test", phrase);
 }
Exemple #19
0
		public void actionPerformed(ActionEvent e) {
			if (e.getSource() == edit) {
				for (JRadioButton selAlbum : albumButtons) {
					if (selAlbum.isSelected()) {
						String albumInfo = selAlbum.getText();
						String[] album = albumInfo.split(" - ");
						Album selectedAlbum = Search.searchAlbum(album[1], Search.searchArtist(album[2]));
						EditAlbumComponents editComp = new EditAlbumComponents (null, selectedAlbum);
						editComp.setVisible(true);
					}
				}
			}
		}
Exemple #20
0
  private void jButton2ActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton2ActionPerformed

    if (source == null) {
      Search search = new Search();
      search.setVisible(true);
      this.dispose();
    } else {
      SuggestRecipe suggestRecipe = new SuggestRecipe();
      suggestRecipe.setVisible(true);
      this.dispose();
    }
  } // GEN-LAST:event_jButton2ActionPerformed
  /** @return */
  public CswParams copy() {
    CswParams copy = new CswParams(dm);
    copyTo(copy);

    copy.capabUrl = capabUrl;
    copy.icon = icon;
    copy.rejectDuplicateResource = rejectDuplicateResource;

    for (Search s : alSearches) copy.alSearches.add(s.copy());

    copy.eltSearches = eltSearches;

    return copy;
  }
 private String getSearchQuery(final Search search) {
   StringBuilder queryBuilder = new StringBuilder();
   queryBuilder.append("q=");
   try {
     queryBuilder.append(URLEncoder.encode(search.getText(), "utf-8"));
   } catch (UnsupportedEncodingException e) {
     e.printStackTrace();
   }
   if (search.getSearchOrder() != null) {
     queryBuilder.append("&order=");
     queryBuilder.append(search.getSearchOrder());
   }
   return queryBuilder.toString();
 }
 @Test
 public void testMatching() throws NoSuchAlgorithmException {
   search.setMatcher(new MatcherForMd5(matchingMd5));
   int[] indexArray = search.makeIndexArray();
   wordlist.addWord("poultry");
   wordlist.addWord("outwits");
   wordlist.addWord("ants");
   indexArray[0] = 0;
   indexArray[1] = 1;
   indexArray[2] = 2;
   String probe = testPhrase.replace(" ", "");
   Assert.assertEquals(testPhrase, search.makePhrase(indexArray));
   Assert.assertTrue(search.matching(probe, indexArray));
 }
 @Test
 public void testBinarySearchWithEmpty() throws Exception {
   assertEquals(
       4,
       Search.binarySearchWithEmpty(
           new String[] {"at", "", "", "", "ball", "", "", "car", "", "", "dad", "", ""}, "ball"));
 }
Exemple #25
0
  /** Performs initial presentation, and attaches listeners to live objects. */
  private void init() {
    initToolbarMenu();
    initSearchBox();
    render();
    search.addListener(this);
    profiles.addListener(this);
    searchUi.init(this);
    searchUi.getSearch().init(this);

    // Fire a polling search.
    scheduler.scheduleRepeating(searchUpdater, 0, POLLING_INTERVAL_MS);

    StateManagerInstance.get()
        .onStateChanged(
            false,
            new StateChangedHandler() {
              @Override
              public void onStateChanged(StateChangedEvent event) {
                StateAbstractDTO state = event.getState();
                if (state instanceof StateContentDTO) {
                  StateContentDTO ctn = (StateContentDTO) state;
                  if (ctn.isWave() && ctn.isParticipant()) {
                    // This will work only if the wave is in the current search
                    // GwtWaverefEncoder.decodeWaveRefFromPath(DEFAULT_SEARCH)
                    // final String waveUri =
                    // GwtWaverefEncoder.encodeToUriPathSegment(WaveRef.of(digest.getWaveId()));
                    selectWaveUri(ctn.getWaveRef().replaceFirst("\\/~\\/conv\\+root", ""));
                  }
                }
              }
            });
  }
Exemple #26
0
 /**
  * 根据id获取对象列表
  *
  * @param ids
  * @return
  */
 @SuppressWarnings("unchecked")
 public List<T> get(final Class<T> entityClass, final Collection<PK> ids) {
   Search search = new Search(entityClass);
   search.setResultMode(Search.RESULT_LIST);
   JPAAnnotationMetadataUtil metadataUtil = new JPAAnnotationMetadataUtil();
   T entity;
   try {
     entity = entityClass.newInstance();
   } catch (Exception e) {
     logger.error("根据主键集合查找对象 {}发生异常! ", entityClass.getClass());
     throw new RuntimeException("根据主键集合查找对象发生异常", e);
   }
   String propertyName = metadataUtil.getIdPropertyName(entity);
   SearchUtil.addFilterIn(search, propertyName, ids);
   return searchProcessor.search(this.getEntityManager().getPersistEntityManager(), search);
 }
 @Test
 public void testMinTriplet() {
   assertTrue(
       Arrays.equals(
           new int[] {2, 2, 2},
           Search.minTriplet(
               new int[] {1, 3, 78}, new int[] {15, 19, 79}, new int[] {27, 29, 80})));
 }
  // Update search based on keyword found
  public void setCurrentSearchByString(String searchString) {

    Search newSearch;

    if (searchString.equals(binSearch.getName())) {
      newSearch = binSearch;
    } else if (searchString.equals(typeSearch.getName())) {
      newSearch = typeSearch;
    } else if (searchString.equals(brandSearch.getName())) {
      newSearch = brandSearch;
    } else if (!mActionHandler.isActionPerformed()) {
      newSearch = yesNoSearch;
    } else {
      newSearch = brandSearch;
    }
    setCurrentSearch(newSearch, searchString);
  }
 /**
  * Compute the Maximal flow for the given flow network.
  *
  * <p>The results of the computation are stored within the network object. Specifically, the final
  * labeling of vertices computes the set S of nodes which is disjoint from the unlabeled vertices
  * which form the set T. Together, S and T represent the disjoint split of the graph into two sets
  * whose connecting edges for the min-cut, in other words, the forward edges from S to T all have
  * flow values which equal their capacity. Thus no additional augmentations are possible.
  *
  * @throws Exception if the graph structure is not a flow network.
  * @return true if an augmenting path was found; false otherwise.
  */
 public boolean compute() {
   boolean augmented = false;
   while (searchMethod.findAugmentingPath(network.vertices)) {
     processPath(network.vertices);
     augmented = true;
   }
   return augmented;
 }
Exemple #30
0
 /**
  * 根据查询条件,返回符合条件的单个对象,用户单表查询
  *
  * @param search 查询对象
  * @return
  */
 @SuppressWarnings("unchecked")
 public <X> X searchUnique(Search search) {
   if (search == null) throw new NullPointerException("Search is null.");
   if (search.getSearchClass() == null) throw new NullPointerException("Search class is null.");
   return (X)
       this.searchProcessor.searchUnique(
           this.getEntityManager().getPersistEntityManager(), search);
 }