Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

rasa emotion bot

from typing import Any, Text, Dict, List

from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher
import requests
from nrclex import NRCLex


class ActionEmotion(Action):

    def name(self) -> Text:
        return "action_emotion"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

        text = str(tracker.latest_message["text"])

        emotion = NRCLex(text)
        
        dispatcher.utter_message(text="The Affect dictionary of the emotions detected are {}".format(emotion.affect_dict))
        dispatcher.utter_message(text="The raw emotion scores detected are {}".format(emotion.raw_emotion_scores))
        dispatcher.utter_message(text="The top emotions detected are {}".format(emotion.top_emotions))
        dispatcher.utter_message(text="The affect frequencies detected are {}".format(emotion.affect_frequencies))

        return []
Comment

PREVIOUS NEXT
Code Example
Python :: list x[:-1] 
Python :: list[:] 
Python :: python how to convert each word of each row to numeric value of a dataframe 
Python :: python regex exclude letters 
Python :: python simplenamespace to json 
Python :: loop regex 
Python :: pandas select random entry after groupby 
Python :: How to allow discord bot to respond to webhook. Python. Discord.py 
Python :: Fetch all links from a given webpage 
Python :: integration test python 
Python :: Repetition in code for routes in Flask (or Bottle) 
Python :: docstring python pycharm 
Python :: python class reflect method of member instance 
Python :: Evaluate mathematical expression 
Python :: connect labjack to python 
Python :: replace string in dictionary python 
Python :: ring Using Self.Attribute and Self.Method 
Python :: list duplicates of specific file in folder python 
Python :: Sum of diagonal elements of a matrix python without numpy 
Python :: Error: Directory not empty @ dir_s_rmdir - /usr/local/Cellar/python/3.7.3 
Python :: unpack list python 
Python :: regression avec sklearn best 
Python :: python save base64 temp file 
Python :: gensim wordvector vocabulary list 
Python :: how to insert value in admin panel in django 
Python :: creating environment variable in python 
Python :: python check if not none or empty 
Python :: 1038 solution python 
Python :: Python[17586:513448] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to 
Python :: python strong type 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =