1- # Java RiveScript Interpreter
1+ # RiveScript-Java
22
33[ ![ Gitter] ( https://badges.gitter.im/aichaos/rivescript-java.svg )] ( https://gitter.im/aichaos/rivescript-java?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge )
44[ ![ Build Status] ( https://travis-ci.org/aichaos/rivescript-java.svg?branch=master )] ( https://travis-ci.org/aichaos/rivescript-java )
55[ ![ Maven Central] ( https://maven-badges.herokuapp.com/maven-central/com.rivescript/rivescript-core/badge.svg )] ( https://maven-badges.herokuapp.com/maven-central/com.rivescript/rivescript-core )
66[ ![ MIT License] ( https://img.shields.io/badge/license-MIT-blue.svg )] ( ./LICENSE )
77
8- This is a Java implementation of a RiveScript interpreter, per the Working Draft
9- at http://www.rivescript.com/wd/RiveScript.html
8+ ## Introduction
109
11- This is * BETA QUALITY SOFTWARE* and hasn't been field tested as much as some of
12- the other RiveScript libraries in other languages.
10+ This is a RiveScript interpreter library written for the Java programming
11+ language. RiveScript is a scripting language for chatterbots, making it easy
12+ to write trigger/response pairs for building up a bot's intelligence.
1313
14- It is feature complete syntax-wise: it supports all of the RiveScript directives
15- and tags, but it doesn't natively support any dynamic language for object macros.
16- You can define object macros in Java at compile-time, and there's an example
17- that bridges Perl code; long-term plans include building in native support for
18- JavaScript.
14+ ** This project is currently in Beta status.** The API should be mostly stable
15+ but things might move around on you.
1916
20- This repository is a little bit light on examples; most of the examples for how
21- to do things are found in the source of ` RSBot.java ` and the RiveScript files
22- in the ` Aiden/ ` directory. These demonstrate things like Java object macros,
23- using the Perl macro bridge, etc.
17+ ## About RiveScript
2418
25- If you find a way to crash this library, please tell me how you did it so I can
26- improve this library!
19+ RiveScript is a scripting language for authoring chatbots. It has a very
20+ simple syntax and is designed to be easy to read and fast to write.
2721
28- Contributions are welcome. See ` CONTRIBUTING.md ` for more information.
22+ A simple example of what RiveScript looks like:
23+
24+ ```
25+ + hello bot
26+ - Hello human.
27+ ```
28+
29+ This matches a user's message of "hello bot" and would reply "Hello human."
30+ Or for a slightly more complicated example:
31+
32+ ```
33+ + my name is *
34+ * <formal> == <bot name> => <set name=<formal>>Wow, we have the same name!
35+ * <get name> != undefined => <set name=<formal>>Did you change your name?
36+ - <set name=<formal>>Nice to meet you, <get name>!
37+ ```
38+
39+ The official website for RiveScript is https://www.rivescript.com/
40+
41+ To test drive RiveScript in your web browser, try the
42+ [ RiveScript Playground] ( https://play.rivescript.com/ ) .
2943
3044## Documentation
3145
32- Documentation is available at < https ://www.rivescript.com/docs/java />
46+ API Documentation is available at < http ://www.javadoc.io/doc/com.rivescript/rivescript-core />
3347
3448Also check out the [ ** RiveScript Community Wiki** ] ( https://github.com/aichaos/rivescript/wiki )
3549for common design patterns and tips & tricks for RiveScript.
3650
37- ## Building from Source
51+ ## Installation
52+
53+ Add the ` rivescript-core ` dependency to your project:
54+
55+ _ Maven_ :
56+
57+ ``` xml
58+ <dependency >
59+ <groupId >com.rivescript.</groupId >
60+ <artifactId >rivescript-core</artifactId >
61+ <version >0.8.0</version >
62+ </dependency >
63+ ```
64+
65+ _ Gradle_ :
66+
67+ ``` groovy
68+ dependencies {
69+ compile "com.rivescript:rivescript-core:0.8.0"
70+ }
71+ ```
72+
73+ ## Usage
74+
75+ When used as a library for writing your own chatbot, the synopsis is as follows:
76+
77+ ``` java
78+ import com.rivescript.Config ;
79+ import com.rivescript.RiveScript ;
80+
81+ // Create a new bot with the default settings.
82+ RiveScript bot = new RiveScript ();
83+
84+ // To enable UTF-8 mode, you'd have initialized the bot like:
85+ RiveScript bot = new RiveScript (Config . utf8());
86+
87+ // Load a directory full of RiveScript documents (.rive files)
88+ bot. loadDirectory(" ./replies" );
89+
90+ // Load an individual file.
91+ bot. LoadFile (" ./testsuite.rive" );
92+
93+ // Sort the replies after loading them!
94+ bot. sortReplies();
95+
96+ // Get a reply.
97+ String reply = bot. reply(" user" , " Hello bot!" );
98+ ```
99+
100+ The ` rivescript-core ` distribution also includes an interactive shell for testing your
101+ RiveScript bot. Run it with the path to a folder on disk that contains your
102+ RiveScript documents. Example:
103+
104+ java com.rivescript.cmd.Shell [options] </path/to/documents>
105+
106+ ## Configuration
107+
108+ The ` com.rivescript.RiveScript ` constructor takes an optional ` Config ` instance.
109+ Here is a full example with all the supported options. You only need to provide
110+ values for configuration options that are different to the defaults.
111+
112+ ``` java
113+ RiveScript bot = new RiveScript (Config . newBuilder()
114+ .throwExceptions(false ) // Whether exception throwing is enabled
115+ .strict(true ) // Whether strict syntax checking is enabled
116+ .utf8(false ) // Whether UTF-8 mode is enabled
117+ .unicodePunctuation(" [.,!?;:]" ) // The unicode punctuation pattern
118+ .forceCase(false ) // Whether forcing triggers to lowercase is enabled
119+ .depth(50 ) // The recursion depth limit
120+ .sessionManager(sessionManager) // The session manager for user variables
121+ .errorMessages(errors) // Map of custom error messages
122+ .build());
123+ ```
124+
125+ For convenience, you can use shortcuts:
126+
127+ ``` java
128+ // The default constructor uses a basic configuration.
129+ RiveScript bot = new RiveScript ();
130+
131+ // This is similar as:
132+ RiveScript bot = new RiveScript (Config . basic());
133+
134+ // To use the basic configuration with UTF-8 mode enabled use:
135+ RiveScript bot = new RiveScript (Config . utf8());
136+ ```
137+
138+ ## UTF-8 Support
139+
140+ UTF-8 support in RiveScript is considered an experimental feature. It is
141+ disabled by default.
142+
143+ By default (without UTF-8 mode on), triggers may only contain basic ASCII
144+ characters (no foreign characters), and the user's message is stripped of all
145+ characters except letters, numbers and spaces. This means that, for example,
146+ you can't capture a user's e-mail address in a RiveScript reply, because of
147+ the @ and . characters.
148+
149+ When UTF-8 mode is enabled, these restrictions are lifted. Triggers are only
150+ limited to not contain certain metacharacters like the backslash, and the
151+ user's message is only stripped of backslashes and HTML angled brackets
152+ (to protect from obvious XSS if you use RiveScript in a web application).
153+ Additionally, common punctuation characters are stripped out, with the default
154+ set being ` [.,!?;:] ` . This can be overridden by providing a new regexp
155+ string to the ` Config.Builder#unicodePunctuation() ` method. Example:
156+
157+ ``` java
158+ // Make a new bot with UTF-8 mode enabled and override the punctuation
159+ characters that get stripped from the user' s message.
160+ RiveScript bot = new RiveScript(Config.Builder
161+ .utf8()
162+ .unicodePunctuation("[.,!?;:]")
163+ .build());
164+ ```
165+
166+ The `<star>` tags in RiveScript will capture the user' s " raw" input, so you can
167+ write replies to get the user' s e-mail address or store foreign characters in
168+ their name.
169+
170+ ## Building
38171
39172To compile, test, build all jars and docs run:
40173
@@ -56,18 +189,15 @@ These commands may be used at your input prompt in RSBot:
56189 /dump sorted - Dump the internal trigger sort buffers (debugging)
57190 /last - Print the last trigger you matched.
58191
59- ## Quickstart
60-
61192To execute `RSBot` to begin chatting with the demo Eliza-based bot that
62193tends to ship with RiveScript libraries run:
63194
64- ./gradlew :rivescript-samples-rsbot:runApp --console plain
65-
66- ## Unit Testing
195+ ./gradlew :rivescript-samples-rsbot:runBot --console plain
67196
68- This library is tested using [ JUnit ] ( http://junit.org/ ) . To execute the test suite run:
197+ ## Authors
69198
70- ./gradlew clean test
199+ * Noah Petherbridge, https://www.kirsle.net/
200+ * Marcel Overdijk, https://twitter.com/marceloverdijk
71201
72202## License
73203
@@ -94,7 +224,3 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
94224OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
95225SOFTWARE.
96226```
97-
98- ## AUTHOR
99-
100- Noah Petherbridge, https://www.kirsle.net/
0 commit comments