diff --git a/.gitignore b/.gitignore
index 072ca34..4f71bae 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
**/.DS_Store
api_keys.py
__pycache__
-__pycache__/*
\ No newline at end of file
+__pycache__/*
+*.pyc
\ No newline at end of file
diff --git a/README.md b/README.md
index c2596a3..1671571 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,13 @@
-# cbot
+#### The Project
A chatbot project, aimed at students building there first hack attempt using Microsoft Cognitive Services and the Python SDK.
The chatbot is far from realistic, but hopefully will give you more an idea of what Microsoft Cognitive Services can be used for.
-Prerequisites:
-sudo pip install git+https://github.com/dpallot/simple-websocket-server.git
\ No newline at end of file
+Tutorial Link: https://blogs.msdn.microsoft.com/uk_faculty_connection/2016/11/28/creating-my-first-chatbot-using-microsoft-cognitive-services-and-python/
+
+If you have any questions, please don't hesitate to email me at alanduu50[at]gmail[dot]com.
+
+#### Prerequisites:
+- Python 3 installed
+- Simple Websocket Server: https://github.com/dpallot/simple-websocket-server
+- Microsoft Cognitive Services (free): https://www.microsoft.com/cognitive-services/en-US/subscriptions?mode=NewTrials
\ No newline at end of file
diff --git a/generate_reply.py b/generate_reply.py
index 2ef42c8..b343025 100644
--- a/generate_reply.py
+++ b/generate_reply.py
@@ -1,77 +1,3 @@
-import random
-from linguistic import getPOS
-from sentiment import getSentiment
-
-greetings = [ "hi", "hello", "hey", "yo", "greetings" ]
-greetings_responses = [ "Hi there." , "Greetings human.", "Hello there.", "Hey." ]
-
-# Returns JJ if sentence structure is You Are {word}+ JJ {word}+.
-def findYouAreJJ(pos):
- foundYou = False
- foundAre = False
-
- for e in pos:
- if e[0].lower() == 'you':
- foundYou = True
- continue
- if e[0].lower() == 'are':
- foundAre = True
- continue
- if foundYou and not foundAre:
- return False
- if foundAre and e[1] == 'JJ':
- return e[0]
- return False
-
-# Returns JJ if sentence structure is I Am {word}+ JJ {word}+.
-def findIAmJJ(pos):
- foundYou = False
- foundAre = False
-
- for e in pos:
- if e[0].lower() == 'i':
- foundYou = True
- continue
- if e[0].lower() == 'am':
- foundAre = True
- continue
- if foundYou and not foundAre:
- return False
- if foundAre and e[1] == 'JJ':
- return e[0]
- return False
-
# Generates a bot response from a user message
def generateReply(message):
- pos = getPOS(message)
- tokens = message.split(" ")
- sentiment = getSentiment(message)
-
- # If first word of message is an element of greetings
- if len(tokens) > 0 and tokens[0].lower() in greetings:
- return random.choice(greetings_responses) # Then respond with a greeting
-
- # If user said 'You are ... {adjective} ...'
- youAreJJ = findYouAreJJ(pos)
- if youAreJJ:
- if sentiment >= 0.5:
- return "Thank you, I know I'm "+youAreJJ+"."
- else:
- return "No! I'm not "+youAreJJ+"!"
-
- # If user said 'I am ... {adjective} ...'
- IAmJJ = findIAmJJ(pos)
- if IAmJJ:
- if sentiment >= 0.5:
- return "I'm happy for you that you're "+IAmJJ+"."
- else:
- return "Don't be mean on yourself. I'm sure you're not really "+IAmJJ+"!"
-
- if sentiment >= 0.5:
- return "I'm happy to hear that!"
- else:
- return "I feel sad about that."
-
-print(generateReply("I am cool"))
-
-
+ return "I don't understand." # Otherwise the bot doesn't understand what the user said
\ No newline at end of file
diff --git a/generate_reply_completed.py b/generate_reply_completed.py
index 8779b4e..0dc0ba6 100644
--- a/generate_reply_completed.py
+++ b/generate_reply_completed.py
@@ -5,6 +5,22 @@
greetings = [ "hi", "hello", "hey", "yo", "greetings" ]
greetings_responses = [ "Hi there." , "Greetings human.", "Hello there.", "Hey." ]
+# Returns JJ if sentence structure is You Are {word}+ JJ {word}+.
+def findYouAreJJ(pos):
+ foundYou = False
+ foundYouAre = False
+
+ for e in pos:
+ if e[0].lower() == 'you':
+ foundYou = True
+ elif e[0].lower() == 'are' and foundYou:
+ foundYouAre = True
+ elif foundYou and not foundYouAre:
+ foundYou = False
+ elif foundYouAre and e[1] == 'JJ':
+ return e[0]
+ return False
+
# Generates a bot response from a user message
def generateReply(message):
pos = getPOS(message)
@@ -12,10 +28,10 @@ def generateReply(message):
# If error occurred getting POS
if not pos:
- return "I am not functioning at the moment."
+ return "I am not functioning at the moment. Perhaps check your API keys."
# If user greeted
- if pos[0][0] in greetings:
+ if pos[0][0].lower() in greetings:
return random.choice(greetings_responses)
# If user said 'You are ... {adjective} ...'
@@ -40,39 +56,18 @@ def generateReply(message):
return "I feel sad about that."
-# Returns JJ if sentence structure is You Are {word}+ JJ {word}+.
-def findYouAreJJ(pos):
- foundYou = False
- foundAre = False
-
- for e in pos:
- if e[0].lower() == 'you':
- foundYou = True
- continue
- if e[0].lower() == 'are':
- foundAre = True
- continue
- if foundYou and not foundAre:
- return False
- if foundAre and e[1] == 'JJ':
- return e[0]
- return False
-
-
# Returns JJ if sentence structure is I Am {word}+ JJ {word}+.
def findIAmJJ(pos):
- foundYou = False
- foundAre = False
+ foundI = False
+ foundIAm = False
for e in pos:
if e[0].lower() == 'i':
- foundYou = True
- continue
- if e[0].lower() == 'am':
- foundAre = True
- continue
- if foundYou and not foundAre:
- return False
- if foundAre and e[1] == 'JJ':
+ foundI = True
+ elif e[0].lower() == 'am' and foundI:
+ foundIAm = True
+ elif foundI and not foundIAm:
+ foundI = False
+ elif foundIAm and e[1] == 'JJ':
return e[0]
return False
\ No newline at end of file
diff --git a/index.html b/index.html
index 4286728..452b21f 100644
--- a/index.html
+++ b/index.html
@@ -12,24 +12,36 @@
ws.close();
});
- ws.onerror= function(event) {
+ ws.onerror = function(event) {
location.reload();
}
ws.onmessage = function(event) {
- var message_received = event.data;
- chat_add_message("Bot", message_received);
+ var message_received = event.data;
+ chat_add_message(message_received, false);
};
// Add a message to the chat history
- function chat_add_message(name, message) {
- chat_add_html(""+name+": "+message+"
");
+ function chat_add_message(message, isUser) {
+ var class_suffix = isUser ? '_user' : '';
+
+ var html = '\
+