-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrite.go
52 lines (37 loc) · 1.2 KB
/
write.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package gokapi
import (
"encoding/json"
"log"
)
func (retriever Retriever) writeTF(key string, value map[string]map[string]float32) {
jsonStr, err := json.Marshal(value)
if err != nil {
log.Println("Warning: unable to parse document TF ", key, " as json.")
}
err = retriever.diskTF.Write(key, jsonStr)
if err != nil {
log.Println("Warning: Unable to save document TF ", key, "on disk.")
}
}
func (retriever Retriever) writeIDF(key string, value map[string]float32) {
jsonStr, _ := json.Marshal(value)
retriever.diskIDF.Write(key, jsonStr)
}
func (retriever Retriever) writeMeta(n float32, mean float32) {
jsonStr, err := json.Marshal(n)
if err != nil {
log.Println("Warning: unable to convert the total number of documents as JSON.")
}
err = retriever.diskMeta.Write("n", jsonStr)
if err != nil {
log.Println("Warning: Unable to write the total number of documents on disk.")
}
jsonStr, err = json.Marshal(mean)
if err != nil {
log.Println("Warning: unable to convert the average length number of documents as JSON.")
}
err = retriever.diskMeta.Write("mean", jsonStr)
if err != nil {
log.Println("Warning: Unable to write the average length number of documents on disk.")
}
}