Implement query to tf-idf score.
This commit is contained in:
@@ -2,6 +2,8 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gslin/go-ir-playground/internal/artifact"
|
"github.com/gslin/go-ir-playground/internal/artifact"
|
||||||
@@ -34,4 +36,16 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("TF & DF Built")
|
fmt.Println("TF & DF Built")
|
||||||
|
|
||||||
|
q := os.Args[1:]
|
||||||
|
|
||||||
|
for _, article := range articles {
|
||||||
|
var score float64 = 0.0
|
||||||
|
for _, w := range q {
|
||||||
|
if tf[w] != nil {
|
||||||
|
score += float64(tf[w][article.Id]) * math.Log2(float64(len(articles) / df[w]))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Printf("Article %v: %v\n", article.Id, score)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user