-
Notifications
You must be signed in to change notification settings - Fork 249
Expand file tree
/
Copy pathConversation.java
More file actions
156 lines (112 loc) · 4.01 KB
/
Conversation.java
File metadata and controls
156 lines (112 loc) · 4.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
/**
* Class for user and bot conversation to occur
*/
class Conversation{
/**
* Execution of conversation begins here
*/
public static void main(String[] arguments){
// You will start the conversation here.
//Declaration of variables
var user_input = new Scanner(System.in);
//input = new Scanner(System.in);
System.out.println("How many rounds of conversation?");
//Variable that stores the number of rounds
int num_rounds = user_input.nextInt();
//List to save the transcript
ArrayList <String> transcript = new ArrayList<>();
//Random number generator
Random rand = new Random();
//List that stores conversational starters
ArrayList <String> convo_starter = new ArrayList<String>();
convo_starter.add("What are you thinking about?");
convo_starter.add("How was your day?");
convo_starter.add("What do you wanna talk about?");
convo_starter.add("What's up?");
convo_starter.add("Hi, how are you?");
//List that stores canned responses
ArrayList <String> canned_responses = new ArrayList<String>();
canned_responses.add("I see");
canned_responses.add("Very interesting");
canned_responses.add("Oh, really?");
canned_responses.add("Wow, that's crazy");
canned_responses.add("Me too");
canned_responses.add("I don't know much about that..");
//Prints line one
int index = rand.nextInt(convo_starter.size()-1);
String line_one = convo_starter.get(index);
System.out.println(line_one);
//Adds line_one to the transcript
transcript.add(line_one);
//Defines scanner
Scanner response = new Scanner(System.in);
//for loop for the amount of rounds the user sellected
for (int i= 0; i< num_rounds; i++){
String user_response = response.nextLine();
user_response = user_response + " ";
transcript.add(user_response);
//First response
String bot_response = "";
String [] words = user_response.split(" ");
//Iterates through the words in the user response, and replaces the mirror words.
for (int r=0; r < words.length; r++){
if (words[r].equals("you")){
words[r] = "I";
bot_response = bot_response + words[r] +" ";
}
else if (words[r].equals("I")||words[r].equals("i")){
words[r] = "you";
bot_response = bot_response + words[r] +" ";
}
else if (words[r].equals("are")){
words[r] = "am";
bot_response = bot_response + words[r] +" ";
}
else if (words[r].equals("was")){
words[r] = "were";
bot_response = bot_response + words[r] +" ";
}
else if (words[r].equals("am")){
words[r] = "are";
bot_response = bot_response + words[r] +" ";
}
else if (words[r].equals("my")){
words[r] = "your";
bot_response = bot_response + words[r] +" ";
}
else if (words[r].equals("your")){
words[r] = "my";
bot_response = bot_response + words[r] +" ";
}
else if (words[r].equals("me")){
words[r] = "you";
bot_response = bot_response + words[r] +" ";
}
else{
bot_response = bot_response + words[r] +" ";
}
}
//If the response has no mirror words it selects a canned response
if (user_response.equals(bot_response)){
int index2 = rand.nextInt(canned_responses.size()-1);
String canned_response = canned_responses.get(index2);
System.out.println(canned_response);
transcript.add(canned_response);
}
else{
System.out.println(bot_response);
transcript.add(bot_response);
}
}
System.out.println("See ya next time!");
System.out.println("TRANSCRIPT");
System.out.println(transcript);
//Close scanners
user_input.close();
//Closes response scanner
response.close();
}
}