54 lines
2.1 KiB
Go
54 lines
2.1 KiB
Go
package knowledge
|
|
|
|
import "testing"
|
|
|
|
func TestIsTangentialToIntentWashingMachineVsHypoallergenicDetergent(t *testing.T) {
|
|
profile := BuildIntentProfile(PatrolTagInput{
|
|
ProductName: "抗敏無香洗衣精",
|
|
ProductFeatures: "完全無香、抗敏,適合敏感肌與化療族群",
|
|
MatchTags: []string{"無香", "抗敏", "洗衣精"},
|
|
Pillars: []string{"化療後衣物清潔", "無香洗衣"},
|
|
Questions: []string{"化療後想找不會刺激的洗衣精"},
|
|
})
|
|
text := "請問洗脫烘洗衣機有推薦嗎?"
|
|
if !IsTangentialToIntent(text, profile) {
|
|
t.Fatal("expected washing machine post to be tangential to hypoallergenic detergent intent")
|
|
}
|
|
}
|
|
|
|
func TestIsTangentialToIntentAcceptsCorePain(t *testing.T) {
|
|
profile := BuildIntentProfile(PatrolTagInput{
|
|
ProductName: "抗敏無香洗衣精",
|
|
ProductFeatures: "完全無香、抗敏",
|
|
MatchTags: []string{"無香", "洗衣精"},
|
|
})
|
|
text := "化療後對香味很敏感,有無香洗衣精推薦嗎?"
|
|
if IsTangentialToIntent(text, profile) {
|
|
t.Fatal("expected core pain post to align with intent")
|
|
}
|
|
}
|
|
|
|
func TestRescoreGraphIntentFitPenalizesTangentialNode(t *testing.T) {
|
|
graph := Graph{
|
|
Seed: "無香 洗衣精",
|
|
Nodes: []Node{
|
|
{ID: "core", Label: "化療後對香味敏感", NodeKind: "pain", Layer: 0, ProductFitScore: 92, Relation: "需要無香洗衣精"},
|
|
{ID: "weak", Label: "洗衣機選購", NodeKind: "knowledge", Layer: 2, ProductFitScore: 72, Relation: "家電預算與容量"},
|
|
},
|
|
Edges: []Edge{{From: "core", To: "weak", Relation: "延伸"}},
|
|
}
|
|
in := PatrolTagInput{
|
|
ProductName: "抗敏無香洗衣精",
|
|
ProductFeatures: "完全無香、抗敏",
|
|
MatchTags: []string{"無香", "洗衣精"},
|
|
Questions: []string{"化療後想找無香洗衣精"},
|
|
}
|
|
RescoreGraphIntentFit(&graph, in)
|
|
if graph.Nodes[0].ProductFitScore < 60 {
|
|
t.Fatalf("expected core node to stay high, got %d", graph.Nodes[0].ProductFitScore)
|
|
}
|
|
if graph.Nodes[1].ProductFitScore > 35 {
|
|
t.Fatalf("expected tangential node to be penalized, got %d", graph.Nodes[1].ProductFitScore)
|
|
}
|
|
}
|