Skip to content

Commit

Permalink
Merge pull request #76 from johann-petrak/fix-issue69
Browse files Browse the repository at this point in the history
Fix #69.
  • Loading branch information
davidjurgens committed Apr 8, 2017
2 parents df71a3c + 3021ac8 commit a608102
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/main/java/edu/ucla/sspace/common/DocumentVectorBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Set;


/**
Expand Down Expand Up @@ -125,11 +126,18 @@ public DoubleVector buildVector(BufferedReader document,

// Iterate through each term in the document and sum the term Vectors
// found in the provided SemanticSpace.
// If the underlying BasisMapping of the sspace is not read-only, then
// the getVector method would try to access a non-existing element.
// We therefore check here if the word is in the mapping and
// skip the word if it is not.
Set<String> knownWords = sspace.getWords();
for (Map.Entry<String, Integer> entry : termCounts.entrySet()) {
Vector termVector = sspace.getVector(entry.getKey());
if (termVector == null)
continue;
add(documentVector, termVector, entry.getValue());
if(knownWords.contains(entry.getKey())) {
Vector termVector = sspace.getVector(entry.getKey());
if (termVector == null)
continue;
add(documentVector, termVector, entry.getValue());
}
}

return documentVector;
Expand Down

0 comments on commit a608102

Please sign in to comment.