Skip to content

Commit

Permalink
Updated the score function
Browse files Browse the repository at this point in the history
  • Loading branch information
chewxy committed Dec 12, 2017
1 parent cd4539d commit 2e36c32
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
10 changes: 3 additions & 7 deletions tfidf.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,13 @@ func (tf *TFIDF) Score(doc Document) []float64 {
ids := doc.IDs()

retVal := make([]float64, len(ids))
tf.Lock()
TF := make(map[int]float64)
for _, id := range ids {
tf.TF[id]++
TF[id]++
}
for i, id := range ids {
retVal[i] = tf.TF[id]
}
for _, id := range ids {
tf.TF[id]--
retVal[i] = TF[id]
}
tf.Unlock()

l := float64(len(ids))
for i, freq := range retVal {
Expand Down
2 changes: 1 addition & 1 deletion tfidf_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,5 @@ func Example() {
// "never": 2.4
// "mind": 2.4
// "how": 2.4
// Scores: [1.2 1.3 1.2 0.9]
// Scores: [0.6 0.3 0.6 0.1]
}

0 comments on commit 2e36c32

Please sign in to comment.