8015fdbb79
Replace nearest-neighbour personal routing with a frozen class-balanced linear head measured on historical, stratified, cross-validation, holdout, and fresh challenge gates (V-702). Close the four repair handoff holes, preserve nested clarification flows, and route Russian possession statements through structural grammar rather than lexical exceptions (V-573). Owner explicitly requested direct commits to master.
67 lines
2.2 KiB
Go
67 lines
2.2 KiB
Go
package router
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
)
|
|
|
|
func TestPossessionStatementGrammarClaimsOpenRemainder(t *testing.T) {
|
|
g := PossessionStatementGrammar()
|
|
for _, utterance := range []string{
|
|
"у меня новый ноутбук",
|
|
"У меня сломался велосипед.",
|
|
"у меня после отпуска другая работа",
|
|
"у меня что-то сломалось",
|
|
"у меня кто-нибудь дома",
|
|
"у меня когда-то был велосипед",
|
|
"у меня кое-что изменилось",
|
|
} {
|
|
d, matched, ok := g.Evaluate(utterance)
|
|
if !matched || !ok {
|
|
t.Errorf("%q was not claimed", utterance)
|
|
continue
|
|
}
|
|
if d.Intent != IntentNote || d.Slots.Text != utterance || d.Stage != 0 {
|
|
t.Errorf("%q => %+v, want an anchored note preserving the utterance", utterance, d)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestPossessionStatementGrammarDefersNarrowerRequests(t *testing.T) {
|
|
g := PossessionStatementGrammar()
|
|
for _, utterance := range []string{
|
|
"что у меня сегодня?",
|
|
"у меня когда встреча?",
|
|
"у меня когда встреча",
|
|
"у меня новый ноутбук?",
|
|
"у меня новый ноутбук, запиши это",
|
|
"у меня новый ноутбук, напомни настроить его",
|
|
"расскажи, что у меня в календаре",
|
|
"у тебя новый ноутбук",
|
|
} {
|
|
if _, _, ok := g.Evaluate(utterance); ok {
|
|
t.Errorf("%q was claimed as a plain possession statement", utterance)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestPossessionStatementBeatsStatisticalQueryGuess(t *testing.T) {
|
|
emb := NewHashEmbedder(64)
|
|
classifier := NewClassifier(emb)
|
|
if err := classifier.AddExample(context.Background(), IntentQuery, "у меня новый ноутбук"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
r := New(Config{
|
|
Grammars: []Grammar{PossessionStatementGrammar()},
|
|
Classifier: classifier,
|
|
Threshold: 0,
|
|
})
|
|
d, err := r.Route(context.Background(), "у меня новый ноутбук", refNow())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if d.Intent != IntentNote || d.Stage != 0 {
|
|
t.Fatalf("route = %+v, want the structural statement grammar before the statistical query guess", d)
|
|
}
|
|
}
|