Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
PratikSavla committed Aug 30, 2019
1 parent 0fae92e commit 0d7c254
Show file tree
Hide file tree
Showing 5 changed files with 360 additions and 283 deletions.
431 changes: 180 additions & 251 deletions .ipynb_checkpoints/Bot-with emotion detection-checkpoint.ipynb

Large diffs are not rendered by default.

132 changes: 100 additions & 32 deletions Bot-with emotion detection.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 66,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -240,12 +240,19 @@
" nam = identifyu()\n",
" with open(nam+\".txt\", \"a\") as myfile:\n",
" myfile.write(aa)\n",
" return \"Would you like to tell me more about it?\""
" return \"Would you like to tell me more about it?\"\n",
"from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer\n",
"analyser = SentimentIntensityAnalyzer()\n",
"def sas(sentence):\n",
" if analyser.polarity_scores(sentence)['pos']>analyser.polarity_scores(sentence)['neg']:\n",
" return \"happy\"\n",
" else:\n",
" return \"sad\""
]
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 73,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -263,41 +270,79 @@
" if path.exists(nam+\".txt\"):\n",
" with open(nam+\".txt\", \"r\") as myfile:\n",
" daa = myfile.read()\n",
" with open(\"pratik.template\", \"r\") as myfile:\n",
" try:\n",
" mood = (myfile.readlines()[-2][2]) == \"m\"\n",
" except:\n",
" mood = False\n",
" if mood:\n",
" with open(nam+\".template\", \"r+\") as f:\n",
" d = f.readlines()\n",
" f.seek(0)\n",
" for i in d[:-2]:\n",
" f.write(i)\n",
" f.truncate()\n",
" with open(nam+\".template\", \"a\") as myf:\n",
" myf.write(\"\\n\\n{ mood : \"+daa+\" }\")\n",
" myf.write(\"\\n{ mood : \"+sas(daa)+\" }\")\n",
" myf.write(\"\\n{ reason : \"+daa+\" }\")\n",
" os.remove(nam+\".txt\")\n"
]
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 71,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hi pratik , nice to see you again.\n",
"> I am having a rough day...\n",
"> It is a rough day today\n",
"Would you like to talk about it?\n",
"> Yes Sure\n",
"> yes\n",
"Go ahead, tell me what happend.\n",
"> Okay so..\n",
"I had to walk 11 floors in techpark building\n",
"> bad time in two and a half men show\n",
"bad time in two and a half men show\n",
"Would you like to tell me more about it?\n",
"> No\n",
"How does that make you feel?\n",
"> Quit\n",
"Good-bye.\n",
"> no\n",
"no.\n",
"> quit\n",
"Good-bye.\n"
"Thank you for talking with me.\n"
]
}
],
"source": [
"chat()"
]
},
{
"cell_type": "code",
"execution_count": 74,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{ mood : sad }\n",
"\n",
"{ reason : bad time in two and a half men show }\n"
]
}
],
"source": [
"with open(\"pratik.template\", \"r\") as myfile:\n",
" try:\n",
" mood = (myfile.readlines()[-2][2]) == \"m\"\n",
" except:\n",
" mood = False\n",
"if mood:\n",
" with open(\"pratik.template\", \"r\") as myfile:\n",
" for line in myfile.readlines()[-2:]:\n",
" print(line)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -531,14 +576,19 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 47,
"metadata": {},
"outputs": [],
"source": [
"with open(\"Example.template\", \"r\") as myfile:\n",
" with open(\"test.template\", \"a\") as myf:\n",
" myf.write(\"name Pratik\\n\")\n",
" myf.write(myfile.read())"
"with open(\"pratik.template\", \"r\") as myfile:\n",
" try:\n",
" mood = (myfile.readlines()[-2][2]) == \"m\"\n",
" except:\n",
" mood = False\n",
"if mood:\n",
" with open(\"pratik.template\", \"r\") as myfile:\n",
" print(myfile.readlines()[-2:])\n",
" "
]
},
{
Expand Down Expand Up @@ -637,22 +687,40 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"import nltk\n",
"from nltk.sentiment.vader import SentimentIntensityAnalyzer \n",
" \n",
"hotel_rev = [\"Great place to be when you are in Bangalore.\"]\n",
" \n",
"sid = SentimentIntensityAnalyzer()\n",
"for sentence in hotel_rev:\n",
" print(sentence)\n",
" ss = sid.polarity_scores(sentence)\n",
" for k in ss:\n",
" print('{0}: {1}, '.format(k, ss[k]), end='')\n",
" print()"
"from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer\n",
"analyser = SentimentIntensityAnalyzer()"
]
},
{
"cell_type": "code",
"execution_count": 48,
"metadata": {},
"outputs": [],
"source": [
"def sentiment_analyzer_scores(sentence):\n",
" score = analyser.polarity_scores(sentence)\n",
" print(score)"
]
},
{
"cell_type": "code",
"execution_count": 49,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'neg': 0.0, 'neu': 0.508, 'pos': 0.492, 'compound': 0.4404}\n"
]
}
],
"source": [
"sentiment_analyzer_scores(\"It is a good day\")"
]
},
{
Expand Down
53 changes: 53 additions & 0 deletions pratik.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{% block %}
{% client %}((I('| a)m|my name is) )?(.*){% endclient %}
{% prev %}(.*)Can you please tell me your name{% endprev %}
{% response %}Thank you {name:%4}{% endresponse %}
{% endblock %}

{% block %}
{% client %}Do you remember my name{% endclient %}
{% response %}{% if {name} %}Yes I do {name}{% else %}No,{% chat what is my name %}{% endif %}{% endresponse %}
{% endblock %}

{% block %}
{% client %}(.*)(feeling|i feel|my feeling)(.*){% endclient %}
{% response %}{% call emo:%2 %}{% endresponse %}
{% endblock %}

{% block %}
{% client %}(Do you know about|who is|tell me about)(.*){% endclient %}
{% response %}{% call whoIs:%2 %}{% endresponse %}
{% endblock %}

{% block %}
{% client %}(let's get started){% endclient %}
{% response %}Hey, {% cap {% call identifyu:%2 %} %}{% endresponse %}
{% endblock %}

{% block %}
{% client %}(.*)(rough day)(.*){% endclient %}
{% response %}Would you like to talk about it?{% endresponse %}
{% endblock %}

{% block %}
{% client %}Yes|yes{% endclient %}
{% prev %}Would you like to talk about it?{% endprev %}
{% response %}Go ahead, tell me what happend.{% endresponse %}
{% endblock %}

{% block %}
{% client %}No|no|(.*)later(.*){% endclient %}
{% prev %}Would you like to talk about it?{% endprev %}
{% response %}Okay, can I help you in any other way?{% endresponse %}
{% endblock %}

{% block %}
{% client %}{% endclient %}
{% prev %}Go ahead, tell me what happend.{% endprev %}
{% response %}{% call whathappen:%2 %}{% endresponse %}
{% endblock %}



{ mood : sad }
{ reason : bad time in two and a half men show }
26 changes: 26 additions & 0 deletions test.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name Pratik
{% block %}
{% client %}((I('| a)m|my name is) )?(.*){% endclient %}
{% prev %}(.*)Can you please tell me your name{% endprev %}
{% response %}Thank you {name:%4}{% endresponse %}
{% endblock %}

{% block %}
{% client %}Do you remember my name{% endclient %}
{% response %}{% if {name} %}Yes I do {name}{% else %}No,{% chat what is my name %}{% endif %}{% endresponse %}
{% endblock %}

{% block %}
{% client %}(.*)(feeling|i feel|my feeling)(.*){% endclient %}
{% response %}{% call emo:%2 %}{% endresponse %}
{% endblock %}

{% block %}
{% client %}(Do you know about|who is|tell me about)(.*){% endclient %}
{% response %}{% call whoIs:%2 %}{% endresponse %}
{% endblock %}

{% block %}
{% client %}(let's get started){% endclient %}
{% response %}Hey, {% call identifyu:%2 %}{% endresponse %}
{% endblock %}
1 change: 1 addition & 0 deletions test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
appended textappended text aaa

0 comments on commit 0d7c254

Please sign in to comment.