Merge pull request #60 from velour/more_babbler_stuff

More babbler stuff
This commit is contained in:
Chris Sexton 2017-06-08 09:59:53 -04:00 committed by GitHub
commit e453f740c9
2 changed files with 44 additions and 12 deletions

View File

@ -110,15 +110,22 @@ func (p *BabblerPlugin) Message(message msg.Message) bool {
saidSomething := false
saidWhat := ""
if numTokens > 2 && tokens[1] == "says" && strings.Contains(lowercase, "syas") {
split := strings.Split(lowercase, "syas")
if numTokens > 2 && tokens[1] == "says-bridge" && strings.Contains(lowercase, "|") {
split := strings.Split(lowercase, "|")
start := strings.Fields(split[0])
end := strings.Fields(split[1])
saidWhat, saidSomething = p.getBabbleWithBookends(start, end)
} else if numTokens >= 2 && tokens[1] == "says" {
saidWhat, saidSomething = p.getBabble(tokens)
} else if numTokens > 2 && tokens[1] == "syas" {
} else if numTokens > 2 && tokens[1] == "says-tail" {
saidWhat, saidSomething = p.getBabbleWithSuffix(tokens)
} else if numTokens >= 2 && tokens[1] == "says-middle-out" {
saidWhatStart, saidSomethingStart := p.getBabbleWithSuffix(tokens)
saidWhatEnd, saidSomethingEnd := p.getBabble(tokens)
saidSomething = saidSomethingStart && saidSomethingEnd
if saidSomething {
saidWhat = saidWhatStart + " " + strings.Join(strings.Fields(saidWhatEnd)[len(tokens)-2:], " ")
}
} else if len(tokens) == 4 && strings.Index(lowercase, "initialize babbler for ") == 0 {
saidWhat, saidSomething = p.initializeBabbler(tokens)
} else if strings.Index(lowercase, "batch learn for ") == 0 {
@ -137,7 +144,15 @@ func (p *BabblerPlugin) Message(message msg.Message) bool {
}
func (p *BabblerPlugin) Help(channel string, parts []string) {
p.Bot.SendMessage(channel, "initialize babbler for seabass\n\nseabass says")
commands := []string{
"initialize babbler for seabass",
"merge babbler drseabass into seabass",
"seabass says ...",
"seabass says-tail ...",
"seabass says-middle-out ...",
"seabass says-bridge ... | ...",
}
p.Bot.SendMessage(channel, strings.Join(commands, "\n\n"))
}
func (p *BabblerPlugin) Event(kind string, message msg.Message) bool {
@ -847,7 +862,7 @@ func (p *BabblerPlugin) babbleSeedBookends(babblerName string, start, end []stri
closed := map[int64]*searchNode{ startWordNode.NodeId : open[0] }
goalNodeId := int64(-1)
for i := 0; i < len(open) && i < 250; i++ {
for i := 0; i < len(open) && i < 1000; i++ {
cur := open[i]
arcs, err := p.getNextArcs(cur.babblerNodeId)
@ -865,7 +880,10 @@ func (p *BabblerPlugin) babbleSeedBookends(babblerName string, start, end []stri
if arc.ToNodeId == endWordNode.NodeId {
goalNodeId = cur.babblerNodeId
break
//add a little randomization in through maybe searching beyond this solution?
if rand.Intn(4) == 0 {
break
}
}
}
}

View File

@ -169,8 +169,8 @@ func TestBabblerSuffixSeed(t *testing.T) {
res = c.Message(seabass)
seabass.Body = "hi there"
res = c.Message(seabass)
res = c.Message(makeMessage("!seabass syas message one"))
res = c.Message(makeMessage("!seabass syas with unique"))
res = c.Message(makeMessage("!seabass says-tail message one"))
res = c.Message(makeMessage("!seabass says-tail with unique"))
assert.Len(t, mb.Messages, 2)
assert.True(t, res)
assert.Contains(t, mb.Messages[0], "this is message one")
@ -189,7 +189,7 @@ func TestBabblerBadSuffixSeed(t *testing.T) {
res = c.Message(seabass)
seabass.Body = "hi there"
res = c.Message(seabass)
res = c.Message(makeMessage("!seabass syas anything true"))
res = c.Message(makeMessage("!seabass says-tail anything true"))
assert.Len(t, mb.Messages, 1)
assert.True(t, res)
assert.Contains(t, mb.Messages[0], "seabass never said 'anything true'")
@ -203,7 +203,7 @@ func TestBabblerBookendSeed(t *testing.T) {
seabass := makeMessage("It's easier to test with unique messages")
seabass.User = &user.User{Name: "seabass"}
res := c.Message(seabass)
res = c.Message(makeMessage("!seabass says It's easier syas unique messages"))
res = c.Message(makeMessage("!seabass says-bridge It's easier | unique messages"))
assert.Len(t, mb.Messages, 1)
assert.True(t, res)
assert.Contains(t, mb.Messages[0], "it's easier to test with unique messages")
@ -217,7 +217,7 @@ func TestBabblerBookendSeedShort(t *testing.T) {
seabass := makeMessage("It's easier to test with unique messages")
seabass.User = &user.User{Name: "seabass"}
res := c.Message(seabass)
res = c.Message(makeMessage("!seabass says It's easier to test with syas unique messages"))
res = c.Message(makeMessage("!seabass says-bridge It's easier to test with | unique messages"))
assert.Len(t, mb.Messages, 1)
assert.True(t, res)
assert.Contains(t, mb.Messages[0], "it's easier to test with unique messages")
@ -231,12 +231,26 @@ func TestBabblerBadBookendSeed(t *testing.T) {
seabass := makeMessage("It's easier to test with unique messages")
seabass.User = &user.User{Name: "seabass"}
res := c.Message(seabass)
res = c.Message(makeMessage("!seabass says It's easier syas not unique messages"))
res = c.Message(makeMessage("!seabass says-bridge It's easier | not unique messages"))
assert.Len(t, mb.Messages, 1)
assert.True(t, res)
assert.Contains(t, mb.Messages[0], "seabass never said 'it's easier ... not unique messages'")
}
func TestBabblerMiddleOutSeed(t *testing.T) {
mb := bot.NewMockBot()
c := New(mb)
c.config.Babbler.DefaultUsers = []string{"seabass"}
assert.NotNil(t, c)
seabass := makeMessage("It's easier to test with unique messages")
seabass.User = &user.User{Name: "seabass"}
res := c.Message(seabass)
res = c.Message(makeMessage("!seabass says-middle-out test with"))
assert.Len(t, mb.Messages, 1)
assert.True(t, res)
assert.Contains(t, mb.Messages[0], "it's easier to test with unique messages")
}
func TestBabblerBatch(t *testing.T) {
mb := bot.NewMockBot()
c := New(mb)