? 1
: 1 + focusFreq.intValue());
// Get the temprorary semantics for the focus word, create a new
// vector for them if needed.
SparseDoubleVector focusSemantics = wordDocSemantics.get(
focusWord);
if (focusSemantics == null) {
focusSemantics = new SparseHashDoubleVector(
Integer.MAX_VALUE);
wordDocSemantics.put(focusWord, focusSemantics);
}
// Process the previous words.
int offset = 4 - prevWords.size();
for (String word : prevWords) {
offset++;
if (word.equals(IteratorFactory.EMPTY_TOKEN))
continue;
int index = getIndexFor(word);
focusSemantics.add(index, offset);
}
// Process the next words.
offset = 5;
for (String word : nextWords) {
offset--;
if (word.equals(IteratorFactory.EMPTY_TOKEN))
continue;
int index = getIndexFor(word);
focusSemantics.add(index, offset);
}
}
prevWords.offer(focusWord);
if (prevWords.size() > 4)
prevWords.remove();
}
// Add the temporary vectors for each word in this document to the
// actual semantic fectors.
for (Map.Entry<String, SparseDoubleVector> e :
wordDocSemantics.entrySet()) {
SparseDoubleVector focusSemantics = getSemanticVector(
e.getKey());
// Get the non zero indices before hand so that they are cached
// during the synchronized section.
focusSemantics.getNonZeroIndices();
synchronized (focusSemantics) {
VectorMath.add(focusSemantics, e.getValue());
}
}