aichaos / rivescript-go

A RiveScript interpreter for Go. RiveScript is a scripting language for chatterbots.
https://www.rivescript.com/
MIT License
60 stars 16 forks source link

(?) in golang #45

Closed hamidreza01 closed 1 year ago

hamidreza01 commented 2 years ago

Hi, this operator (?) in goo language causes errors .

$ go run . 
[WARN] Unknown command '?' at brain\index.rive line 2
[WARN] Response found before trigger at brain\index.rive line 3
[WARN] Response found before trigger at brain\index.rive line 4
kirsle commented 2 years ago

This feature hasn't been implemented outside the JavaScript version of RiveScript; there it was added because JS regular expressions have Unicode issues where a + [*] keyword [*] style trigger didn't translate properly if the keyword was Unicode symbols (the \b word-boundary metacharacter in JavaScript only binds to latin A-Za-z0-9 characters).

If you'd like to submit a pull request to bring this to rivescript-go, the JavaScript implementation was here: https://github.com/aichaos/rivescript-js/blob/423cd4ac41ecc4f837639ee8bc8d2163bf61860b/src/parser.js#L200-L219 and some background in its pull request: https://github.com/aichaos/rivescript-js/pull/256

It basically translates the ? command into a + trigger which turns the keyword into various permutations of optional wildcards [*] or regular wildcards * on either side as a sort of hacky work-around for the JavaScript Unicode issue. For Go, the ? command could probably just translate to a regular + [*] keyword [*] trigger since Go didn't have the regular expression matching issues.

Or I'll leave this ticket open and implement a fix when I can.

hamidreza01 commented 2 years ago

Thank you for your detailed explanation, the exact problem you described in javascript also exists in Go, it would be great if you could add this. And another issue, how can you directly use regex in rive(go) ?

kirsle commented 1 year ago

This is fixed now as of v0.4.0 of rivescript-go with the addition of the ?Keyword command: https://github.com/aichaos/rivescript-go/pull/48