Skip to content

Commit 2e36c32

Browse files
committed
Updated the score function
1 parent cd4539d commit 2e36c32

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

tfidf.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,13 @@ func (tf *TFIDF) Score(doc Document) []float64 {
6767
ids := doc.IDs()
6868

6969
retVal := make([]float64, len(ids))
70-
tf.Lock()
70+
TF := make(map[int]float64)
7171
for _, id := range ids {
72-
tf.TF[id]++
72+
TF[id]++
7373
}
7474
for i, id := range ids {
75-
retVal[i] = tf.TF[id]
76-
}
77-
for _, id := range ids {
78-
tf.TF[id]--
75+
retVal[i] = TF[id]
7976
}
80-
tf.Unlock()
8177

8278
l := float64(len(ids))
8379
for i, freq := range retVal {

tfidf_example_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,5 @@ func Example() {
8989
// "never": 2.4
9090
// "mind": 2.4
9191
// "how": 2.4
92-
// Scores: [1.2 1.3 1.2 0.9]
92+
// Scores: [0.6 0.3 0.6 0.1]
9393
}

0 commit comments

Comments
 (0)