-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatbot.java
More file actions
121 lines (97 loc) · 3.79 KB
/
Chatbot.java
File metadata and controls
121 lines (97 loc) · 3.79 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
package chatbot.infra;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import chatbot.component.DialogueManager;
import chatbot.component.DomainClassifier;
import chatbot.component.GymIntentClassifier;
import chatbot.component.SlotFiller;
import chatbot.component.WeatherIntentClassifier;
public class Chatbot {
private String userName = "YOUR NAME HERE";
private String botName = "BOT NAME HERE";
private DomainClassifier nowDomainClassifier;
private WeatherIntentClassifier weatherIntentClassifier;
private GymIntentClassifier gymIntentClassifier;
private SlotFiller nowSlotFiller;
private DialogueManager nowDialogueManager;
public Chatbot(String userName, String botName) {
this.userName = userName;
this.botName = botName;
this.nowDomainClassifier = new DomainClassifier();
this.weatherIntentClassifier = new WeatherIntentClassifier();
this.gymIntentClassifier = new GymIntentClassifier();
this.nowSlotFiller = new SlotFiller();
this.nowDialogueManager = new DialogueManager();
}
/*
* Task 3: Add a response in Chatbot.java to respond to user message
*
* Please modify the getResponse() method in the Chatbot class to respond
* to three or more different user messages meaningfully. I provided one
* example in the getResponse().
*/
public String getResponse(String nowInputText) {
System.out.println("--------------");
System.out.println("User Message: "+nowInputText);
String nowDomain = nowDomainClassifier.getLabel(nowInputText);
System.out.println("Domain: "+nowDomain);
String nowIntent = "";
Hashtable<String, String> extractedSlotValues = nowSlotFiller.extractSlotValues(nowInputText);
if(!nowDomain.equals("Other")) {//in-domain message
if(nowDomain.equals("Gym")) {//Food domain
nowIntent = gymIntentClassifier.getLabel(nowInputText);
//}else if(nowDomain.equals("Weather")) {//Weather domain
//nowIntent = weatherIntentClassifier.getLabel(nowInputText);
}else {//this shouldn't happen
System.err.println("Domain name is incorrect!");
System.exit(1);
return null;
}
}else {//out-of-domain message.
//return "This message is out of the domains of the chatbot.";
}
System.out.println("Intent: "+nowIntent);
String nowLoggingData = "Domain = "+nowDomain+"; Intent = "+nowIntent;
nowLoggingData += slotTableToString(extractedSlotValues);
System.out.println(nowLoggingData);
String nextState = nowDialogueManager.getNextState(nowDomain, nowIntent, extractedSlotValues);
System.out.println("nextState: "+nextState);
String nowResponse = nowDialogueManager.executeStateAndGetResponse(nextState);
System.out.println("nowResponse: "+nowResponse);
return nowResponse;
}
/*
* Method slotTableToString() is added for Assignment 1-3
*
* [Input]
* A Hashtable returned by extractSlotValues() in
* SlotFiller.java
*
* [Output]
* A string that list all the extracted slot values
*
*/
private String slotTableToString(Hashtable<String, String> extractedSlotValues) {
String result = " (";
for(String nowKey: extractedSlotValues.keySet()) {
String nowValue = extractedSlotValues.get(nowKey);
System.out.println(nowKey+"="+nowValue);
result += nowKey+"="+nowValue+"; ";
}
result += ")";
return result;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getBotName() {
return botName;
}
public void setBotName(String botName) {
this.botName = botName;
}
}