Use id instead of article.Id.

This commit is contained in:
Gea-Suan Lin
2024-02-28 21:54:15 +08:00
parent 7290880a10
commit d72fe86325

View File

@@ -23,17 +23,18 @@ func main() {
df := make(map[string]int)
for _, article := range articles {
id := article.Id
str := strings.ToLower(article.Title + "\n" + article.Body)
bag := tokenizer.Tokenize(str)
tokens[article.Id] = bag
tokens[id] = bag
for _, w := range bag {
// Handle TF:
if _, ok := tf[w]; !ok {
tf[w] = make(map[string]int)
}
tf[w][article.Id] += strings.Count(str, w)
tf[w][id] += strings.Count(str, w)
// Handle DF:
df[w] += 1