/**
   * Increment the count for the given word by the amount increment
   *
   * @param word the word to increment the count for
   * @param increment the amount to increment by
   */
  @Override
  public synchronized void incrementWordCount(String word, int increment) {
    if (word == null || word.isEmpty())
      throw new IllegalArgumentException("Word can't be empty or null");
    wordFrequencies.incrementCount(word, increment);

    if (hasToken(word)) {
      VocabWord token = tokenFor(word);
      token.increaseElementFrequency(increment);
    }
    totalWordOccurrences.set(totalWordOccurrences.get() + increment);
  }
Ejemplo n.º 2
0
  private void addTokenToVocabCache(String stringToken, Double tokenCount) {
    // Making string token into actual token if not already an actual token (vocabWord)
    VocabWord actualToken;
    if (vocabCache.hasToken(stringToken)) {
      actualToken = vocabCache.tokenFor(stringToken);
      actualToken.increaseElementFrequency(tokenCount.intValue());
    } else {
      actualToken = new VocabWord(tokenCount, stringToken);
    }

    // Set the index of the actual token (vocabWord)
    // Put vocabWord into vocabs in InMemoryVocabCache
    boolean vocabContainsWord = vocabCache.containsWord(stringToken);
    if (!vocabContainsWord) {
      vocabCache.addToken(actualToken);

      int idx = vocabCache.numWords();
      actualToken.setIndex(idx);
      vocabCache.putVocabWord(stringToken);
    }
  }