/** * Load a look up cache from an input stream delimited by \n * * @param from the input stream to read from * @return the in memory lookup cache */ public static InMemoryLookupCache load(InputStream from) { Reader inputStream = new InputStreamReader(from); LineIterator iter = IOUtils.lineIterator(inputStream); String line; InMemoryLookupCache ret = new InMemoryLookupCache(); int count = 0; while ((iter.hasNext())) { line = iter.nextLine(); if (line.isEmpty()) continue; ret.incrementWordCount(line); VocabWord word = new VocabWord(1.0, line); word.setIndex(count); ret.addToken(word); ret.addWordToIndex(count, line); ret.putVocabWord(line); count++; } return ret; }
/** * Increment the count for the given word * * @param word the word to increment the count for */ @Override public synchronized void incrementWordCount(String word) { incrementWordCount(word, 1); }
/** * Increment the count for the given word * * @param word the word to increment the count for */ @Override public void incrementWordCount(String word) { incrementWordCount(word, 1); }