feat(wing): BM25 scorer as the independent cross-check (#205 S1)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package wing_test
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mathiasbq/hyperguild/ingestion/internal/wing"
|
||||
)
|
||||
|
||||
func writePage(t *testing.T, dir, rel, body string) {
|
||||
t.Helper()
|
||||
full := filepath.Join(dir, rel)
|
||||
require.NoError(t, os.MkdirAll(filepath.Dir(full), 0o755))
|
||||
require.NoError(t, os.WriteFile(full, []byte(body), 0o644))
|
||||
}
|
||||
|
||||
func scorerBrain(t *testing.T) string {
|
||||
dir := t.TempDir()
|
||||
writePage(t, dir, "wiki/infra/facts/k3s.md", "---\ntitle: K3s cluster\n---\nkubernetes cluster nodes scheduling pods deployment\n")
|
||||
writePage(t, dir, "wiki/finance/facts/invoice.md", "---\ntitle: Invoices\n---\ninvoice payment bookkeeping ledger reconciliation\n")
|
||||
return dir
|
||||
}
|
||||
|
||||
func TestBM25Scorer_RanksTheWingWhosePagesMatch(t *testing.T) {
|
||||
s := wing.NewBM25Scorer(scorerBrain(t), []string{"infra", "finance"}, "")
|
||||
got := s.Score("notes about kubernetes cluster scheduling and pods")
|
||||
assert.Greater(t, got["infra"], got["finance"])
|
||||
assert.Greater(t, got["infra"], 0.0)
|
||||
}
|
||||
|
||||
func TestBM25Scorer_ExcludesThePageBeingClassified(t *testing.T) {
|
||||
// A page must not vouch for its own wing when it is the backtest sample.
|
||||
s := wing.NewBM25Scorer(scorerBrain(t), []string{"infra", "finance"}, "wiki/infra/facts/k3s.md")
|
||||
got := s.Score("kubernetes cluster nodes scheduling pods deployment")
|
||||
assert.Zero(t, got["infra"], "the excluded page is the only infra match")
|
||||
}
|
||||
|
||||
func TestBM25Scorer_NoUsableTermsScoresNothing(t *testing.T) {
|
||||
s := wing.NewBM25Scorer(scorerBrain(t), []string{"infra", "finance"}, "")
|
||||
assert.Empty(t, s.Score("a an to of"))
|
||||
}
|
||||
Reference in New Issue
Block a user