Ejemplo n.º 1
0
 // Tools
 public boolean mergeWith(Category category) {
   try {
     this.keyWords.addAll(category.getKeyWords());
     this.frequency += category.getFrequency();
     this.refresh();
   } catch (Exception ex) {
     LOGGER.error(ex.getMessage(), ex);
     return false;
   }
   return true;
 }
Ejemplo n.º 2
0
 /**
  * Merges two categories.
  *
  * @param a first category to be merged.
  * @param b second category to be merged.
  * @return result of merge - category as or null (if merge failed).
  */
 public static Category merge(Category a, Category b) {
   Category category = null;
   try {
     category = new Category(a.getKeyWords().get(0));
     category.setKeyWords(a.getKeyWords());
     category.getKeyWords().addAll(b.getKeyWords());
     category.frequency += b.getFrequency();
     category.refresh();
   } catch (Exception ex) {
     LOGGER.error(ex.getMessage(), ex);
   }
   return category;
 }
Ejemplo n.º 3
0
 /**
  * Merges all categories in list. Use it for large amount of data, due to refresh of the result
  * category will be in the end.
  *
  * @param categories list of all categories to be merged.
  * @return new category.
  */
 public static Category mergeAll(List<Category> categories) {
   Category category = null;
   try {
     for (Category c : categories) {
       if (category != null) {
         category.getKeyWords().addAll(c.getKeyWords());
         category.frequency += c.getFrequency();
       } else {
         category = new Category(c.getKeyWords().get(0));
         category.setKeyWords(c.getKeyWords());
       }
     }
     category.refresh();
   } catch (Exception ex) {
     LOGGER.error(ex.getMessage(), ex);
   }
   return category;
 }