A real person doesn't always just respond to what others have typed. To make the ChatBot more realisitic, we will have it sometimes generate spontaneous random sentences or questions.
This program will use two Threads to behave like two different programs running at the same time. The code to make this happen is given to you and you only need to insert your code into the correct place of the skeleton.
I like broccoli. I like ice cream. I hate broccoli. I hate ice cream. You like broccoli. You like ice cream. You hate broccoli. You hate ice cream.The sample solution uses the following hardwired arrays which can generate 616 different sentences (not all of which make any sense e.g. "Cats run kiwi." - but that is ok for this assignment).
private String[] subjects = { "I","you","dogs","cats","people","students","men","women"};
private String[] verbs = { "like","hate","eat","run","study","want","drive"};
private String[] directObjects =
{
"people","dogs","you","me","them","students","men","women","kiwi","a volvo","a junker"
};
The
contents of the various arrays can be read from a file or hardwired
into the program as shown above.
Your program should generate both statements (as above) and questions. Generating questions is just like generating sentences except that in the sample solution, in addition to subject, verb, and direct object, the question begins with some interrogative. The sample solution uses
private String[] questions = {
"do","where do","what do","why do", "when do"
};
which when combined with the sentence arrays above yields 3080
different questions such as "Do students eat kiwi?" and "Why do men want a
volvo?".
You are provided a simple ChatBot program that responds to only a single pattern and at random intervals prints "Say something." The complete program consists of four classes, ChatBotV5, Message, MessageGenerator, and SaySomething. All four of these can be found in /afs/cats/courses/cmps012a-cm/prog5. The program will actually work as is, although it is missing most of the required features.
To integrate your code with the starter, you have three primary tasks. You need to modify the method readPatterns() in MessageGenerator, to use your code that reads the patterns from a file. You also need to modify the method respondTo(), also in class MessageGenerator, to use your code that responds to messages from standard input. The primary difference is that the "sentences" you respond to are now passed as a parameter to respondTo() - ie. msg.content - and instead of printing your response using System.out.println(), you will send your response to the chat room using the method send() provided in class MessageGenerator. Finally, you need to modify the run() method in SaySomething to produce random sentences instead of always sending "Say something."
You should not need to make any changes to the classes ChatBotV5 and Message, or to the other methods in MessageGenerator, although you may want ta add some additional helper methods in MessageGenerator and SaySomething.
java -jar chatServer.jar portNumberwhere portNumber is the port to use. It should be some number between 2000 and 10000.
To run chat client type:
java -jar chatClient.jar hostName portNumber screenNameThe hostName is the IP address of the server. If testing on your local machine you can use "localhost". The portNumber is the same number you used for the server. The screenName is whatever name you want to use in the chat room. You can of course start up as many chat clients at once as you wish.
Once you have the chat server and at least one client connected, you start up your version of chatBot using:
java ChatBotV5 hostName portNumber screenName patternFileThe patternFile of course is the name of the file (in the current working directory) of the file containing the patterns and responses.
If for some reason you are working using an ssh connection and cannot run the chatClient.jar chat client (which has a graphical user interface), there is also a simple text only chat client in the same directory as the others. It is called textChatClient.jar. You run it just like chatClient.jar but it has a simple text interface instead of a graphical interface.
java -jar hw5Solution.jar hostName portNumber screenName patternFileMake sure there is a patternFile in the current directory. You are welcome to start with the one from /afs/cats/courses/cmps012a-cm/prog5/patterns.txt.
10 points - correctly reads a pattern file and generates responses based on those patterns
5 points - responds to multiple patterns (could be hardwired or read from a file)
5 points - avoids making the same response twice in a row
10 points - generates random sentences and questions at least as complex as the sample solution