Skip to content

Commit 8ab57d1

Browse files
committed
Emotions handler and states created
1 parent 5d90db0 commit 8ab57d1

3 files changed

Lines changed: 1732 additions & 0 deletions

File tree

Chatbot_2020_Tutorial.vbproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
<ItemGroup>
8080
<Compile Include="AI_AgentModel.vb" />
8181
<Compile Include="ApplicationEvents.vb" />
82+
<Compile Include="Emotion_Handler.vb" />
8283
<Compile Include="Form_Chat_UI.designer.vb">
8384
<DependentUpon>Form_Chat_UI.vb</DependentUpon>
8485
</Compile>
@@ -113,6 +114,7 @@
113114
<Compile Include="SplashScreen.vb">
114115
<SubType>Form</SubType>
115116
</Compile>
117+
<Compile Include="Emotional_States.vb" />
116118
<Compile Include="SyS.vb" />
117119
</ItemGroup>
118120
<ItemGroup>

Emotion_Handler.vb

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
Public Class Emotional_State
2+
''' <summary>
3+
''' Current emotion
4+
''' </summary>
5+
Public CurrentState As EmotionType
6+
Public CurrentStateStr As String = "Neutral"
7+
''' <summary>
8+
''' If state has changed mood has changed
9+
''' </summary>
10+
Private StateChanged As Boolean = False
11+
''' <summary>
12+
''' Current detected state
13+
''' </summary>
14+
Private DetectedState As EmotionType
15+
''' <summary>
16+
''' New state has been detected
17+
''' </summary>
18+
Private StateDetected As Boolean = False
19+
''' <summary>
20+
''' Intensity of emotion increases if emotional state remains the same
21+
''' </summary>
22+
Public CurrentQuotient As Integer = 0
23+
'PROCESS: PRESERVE VARIABLES
24+
'EMOTION
25+
''' <summary>
26+
''' Used to make a Generic Emotional Response
27+
''' </summary>
28+
''' <param name="FoundEmotion">Provided emotion (HAPPY)</param>
29+
''' <returns></returns>
30+
Public Function MakeEmotionalResponse(ByVal FoundEmotion As String) As String
31+
MakeEmotionalResponse = ""
32+
Randomize()
33+
Dim C As Short = Int(Rnd() * 6 + 1)
34+
Select Case C
35+
Case 1
36+
MakeEmotionalResponse = "I detect emotion in your tone, you are feeling " & LCase(FoundEmotion) & " perhaps"
37+
Case 2
38+
MakeEmotionalResponse = "Are you feeling " & LCase(FoundEmotion) & " ?"
39+
Case 3
40+
MakeEmotionalResponse = "Perhaps ? you can tell me more about why you are feeling ? " & LCase(FoundEmotion)
41+
Case 4
42+
MakeEmotionalResponse = "Detecting " & LCase(FoundEmotion) & " maybe?"
43+
Case 5
44+
MakeEmotionalResponse = "feeling a bit " & LCase(FoundEmotion) & " ?"
45+
Case 6
46+
MakeEmotionalResponse = "" & LCase(FoundEmotion) & " "
47+
End Select
48+
End Function
49+
50+
Private Sub SetEmotionState(ByRef UserInput As String)
51+
'Reset Counters
52+
StateChanged = False
53+
DetectedState = EmotionType.Neutral
54+
StateDetected = False
55+
56+
'Start - Emotion Test
57+
Dim Handler As New EmotionHandler
58+
If Handler.DetectEmotion(UserInput) = True Then
59+
'Check if neutral - Then reduce current Quotient
60+
If Handler.DetectedEmotion = EmotionType.Neutral Then
61+
CurrentQuotient -= 1
62+
If CurrentQuotient = 0 Then
63+
CurrentState = EmotionType.Neutral
64+
Else
65+
End If
66+
End If
67+
68+
'Get State
69+
DetectedState = Handler.DetectedEmotion
70+
StateDetected = True
71+
'IF State is the same Increase Intensity
72+
If DetectedState = CurrentState Then
73+
CurrentQuotient += 1
74+
Else
75+
'IF State is the differnt then change
76+
CurrentStateStr = Handler.DetectedEmotionStr
77+
CurrentState = DetectedState
78+
StateChanged = True
79+
CurrentQuotient = 1
80+
End If
81+
End If
82+
End Sub
83+
''' <summary>
84+
''' Used to See if an emotion has been detected
85+
''' </summary>
86+
''' <param name="Userinput"></param>
87+
''' <returns></returns>
88+
Public Function NewEmotionDetected(ByRef Userinput As String) As Boolean
89+
SetEmotionState(Userinput)
90+
If StateChanged = True Then
91+
Return True
92+
Else
93+
Return False
94+
End If
95+
End Function
96+
End Class
97+
98+
''' <summary>
99+
''' Loads Emotions: Emotion interface provides a platform for the template of an emotion the the
100+
''' LoadEmotions; Function in The emotion handler will need to be adjusted for new emotions
101+
''' designed; the emotion handler loads all the emotions and executes each detector in the
102+
''' emotion set is a response is detected it is held in the handler. A response can then be
103+
''' generated as required from the subclass or the handler. the emotion Objects and functions are
104+
''' encapslated int this emotions Class Library.
105+
''' </summary>
106+
Public Class EmotionHandler
107+
108+
Private iLoadedEmotions As New List(Of Emotion)
109+
110+
Private mDetectedEmotion As EmotionType
111+
112+
Private mEmotion As String
113+
114+
Public ReadOnly Property DetectedEmotion As EmotionType
115+
Get
116+
Return mDetectedEmotion
117+
End Get
118+
End Property
119+
120+
Public ReadOnly Property DetectedEmotionStr As String
121+
Get
122+
Return mEmotion
123+
End Get
124+
125+
End Property
126+
127+
Public ReadOnly Property LoadedEmotions As List(Of Emotion)
128+
Get
129+
Return iLoadedEmotions
130+
End Get
131+
End Property
132+
133+
Public Sub New()
134+
iLoadedEmotions = LoadEmotions()
135+
End Sub
136+
137+
Public Sub AddEmotion(ByRef Emo As Emotion)
138+
iLoadedEmotions.Add(Emo)
139+
End Sub
140+
141+
Public Function DetectEmotion(ByRef Userinput As String) As Boolean
142+
For Each emo As Emotion In LoadedEmotions
143+
If emo.Detect(Userinput) = True Then
144+
mDetectedEmotion = emo.Type
145+
mEmotion = emo.Name
146+
Return True
147+
Else
148+
mDetectedEmotion = EmotionType.Neutral
149+
mEmotion = "Neutral"
150+
151+
End If
152+
153+
Next
154+
Return False
155+
End Function
156+
157+
Public Function LoadEmotions() As List(Of Emotion)
158+
Dim mLoadedEMOTIONs As New List(Of Emotion) From {
159+
New EmotionAngry,
160+
New EmotionConcerned,
161+
New EmotionCurious,
162+
New EmotionFailure,
163+
New EmotionFear,
164+
New EmotionGreatful,
165+
New EmotionHappy,
166+
New EmotionJealous,
167+
New EmotionJoy,
168+
New EmotionLaughing,
169+
New EmotionLove,
170+
New EmotionSad,
171+
New EmotionSerious,
172+
New EmotionSleepy,
173+
New EmotionSuprised
174+
}
175+
Return mLoadedEMOTIONs
176+
End Function
177+
178+
End Class
179+
180+
''' <summary>
181+
''' The emotion type can be used to catagorize some of the basic emotions the list is just a
182+
''' basic collection of emotiontypes ; the emotion finder class uses these basic emotion
183+
''' types to describe the current emotion detected by the class. this type list is no a
184+
''' complete list.
185+
''' </summary>
186+
Public Enum EmotionType
187+
Joy
188+
Happy
189+
Sad
190+
Love
191+
Laughing
192+
Surprised
193+
Sleepy
194+
Serious
195+
Angry
196+
Jealous
197+
curious
198+
Concerned
199+
Failure
200+
Fear
201+
Greatful
202+
Neutral
203+
End Enum
204+

0 commit comments

Comments
 (0)