mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 00:31:35 +00:00
28 lines
851 B
Go
28 lines
851 B
Go
package enrich
|
|
|
|
import "testing"
|
|
|
|
func TestKeywordExtractor_Basic(t *testing.T) {
|
|
e := NewKeywordExtractor()
|
|
text := Text{Body: "The quick brown fox jumps over the lazy dog. The quick brown fox!"}
|
|
keywords, err := e.Extract(text)
|
|
if err != nil {
|
|
t.Fatalf("Extract returned error: %v", err)
|
|
}
|
|
if len(keywords) == 0 {
|
|
t.Fatalf("expected some keywords, got 0")
|
|
}
|
|
// Ensure stop words filtered and most frequent word appears first
|
|
if keywords[0].Text != "quick" && keywords[0].Text != "brown" && keywords[0].Text != "fox" {
|
|
t.Errorf("expected a content word as top keyword, got %q", keywords[0].Text)
|
|
}
|
|
for _, kw := range keywords {
|
|
if kw.Text == "the" || kw.Text == "over" {
|
|
t.Errorf("stop word %q should be filtered out", kw.Text)
|
|
}
|
|
if kw.Relevance <= 0 {
|
|
t.Errorf("keyword %q has non-positive relevance", kw.Text)
|
|
}
|
|
}
|
|
}
|