if (!relation.headNode().word().equals(focusWord))
continue;
RelationTuple relationKey = new RelationTuple(
focusIndex, relation.relation().intern());
SparseDoubleVector relationVector = localTuples.get(
relationKey);
if (relationVector == null) {
relationVector = new CompactSparseVector();
localTuples.put(relationKey, relationVector);
}
relationVector.add(featureIndex, 1);
}
}
}
document.close();
// Once the document has been processed, update the co-occurrence matrix
// accordingly.
for (Map.Entry<Pair<String>,Double> e : localLemmaCounts.entrySet()){
// Push the local co-occurrence counts to the larger mapping.
Pair<String> p = e.getKey();
// Get the prefernce vectors for the current focus word. If they do
// not exist, create it in a thread safe manner.
SelectionalPreference preference = preferenceVectors.get(p.x);
if (preference == null) {
synchronized (this) {
preference = preferenceVectors.get(p.x);
if (preference == null) {
preference = new SelectionalPreference(combinor);
preferenceVectors.put(p.x, preference);
}
}
}
// Add the local count.
synchronized (preference) {
preference.lemmaVector.add(
termBasis.getDimension(p.y), e.getValue());
}
}
// Push the relation tuple counts to the larger counts.
for (Map.Entry<RelationTuple, SparseDoubleVector> r :
localTuples.entrySet()) {
// Get the global counts for this relation tuple. If it does not
// exist, create a new one in a thread safe manner.
SparseDoubleVector relationCounts = relationVectors.get(r.getKey());
if (relationCounts == null) {
synchronized (this) {
relationCounts = relationVectors.get(r.getKey());
if (relationCounts == null) {
relationCounts = new CompactSparseVector();