示例#1
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;
 }
示例#2
0
 public static List<Category> split(Category category, int wordsCount) {
   List<Category> categories = null;
   Category cat;
   try {
     categories = new ArrayList<>();
     for (KeyWord word : category.getKeyWords()) {
       cat = new Category(word);
       cat.refresh(wordsCount);
       categories.add(cat);
     }
   } catch (Exception ex) {
     LOGGER.error(ex.getMessage(), ex);
   }
   return categories;
 }
示例#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;
 }