This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def required_slots(tracker): | |
# type: () -> List[Text] | |
"""A list of required slots that the form has to fill""" | |
if tracker.get_slot('cuisine') == 'greek': | |
return ["cuisine", "num_people", "outdoor_seating", | |
"preferences", "feedback"] | |
else: | |
return ["cuisine", "num_people", | |
"preferences", "feedback"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RestaurantForm(FormAction): | |
"""Example of a custom form action""" | |
def name(self): | |
"""Unique identifier of the form""" | |
return "restaurant_form" | |
@staticmethod | |
def required_slots(tracker: Tracker) -> List[Text]: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def slot_mappings(self): | |
# type: () -> Dict[Text: Union[Dict, List[Dict]]] | |
"""A dictionary to map required slots to | |
- an extracted entity | |
- intent: value pairs | |
- a whole message or a list of them, where a first | |
match will be picked""" | |
return { "outdoor_seating": [self.from_entity(entity="seating"), | |
self.from_intent(intent='affirm', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def validate(self, | |
dispatcher: CollectingDispatcher, | |
tracker: Tracker, | |
domain: Dict[Text, Any]) -> List[Dict]: | |
"""Validate extracted requested slot | |
else reject the execution of the form action | |
""" | |
# extract other slots that were not requested | |
# but set by corresponding entity | |
slot_values = self.extract_other_slots(dispatcher, tracker, domain) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import nltk | |
from nltk.classify import NaiveBayesClassifier | |
from nltk.corpus import twitter_samples | |
from nltk.tokenize import RegexpTokenizer | |
from nltk.corpus import stopwords | |
from nltk.stem.wordnet import WordNetLemmatizer | |
class SentimentClassifier(object): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rasa_nlu.components import Component | |
from rasa_nlu import utils | |
from rasa_nlu.model import Metadata | |
from sentiment_classifier import SentimentClassifier | |
import nltk | |
from nltk.classify import NaiveBayesClassifier | |
from nltk.corpus import twitter_samples | |
from nltk.tokenize import RegexpTokenizer | |
from nltk.corpus import stopwords |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rasa.nlu.components import Component | |
from rasa.nlu import utils | |
from rasa.nlu.model import Metadata | |
import nltk | |
from nltk.classify import NaiveBayesClassifier | |
import os | |
import typing | |
from typing import Any, Optional, Text, Dict |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rasa.nlu.components import Component | |
from rasa.nlu import utils | |
from rasa.nlu.model import Metadata | |
import nltk | |
from nltk.sentiment.vader import SentimentIntensityAnalyzer | |
import os | |
class SentimentAnalyzer(Component): | |
"""A pre-trained sentiment component""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rasa.nlu.components import Component | |
class SentimentAnalyzer(Component): | |
"""A pre-trained sentiment component""" | |
name = "sentiment" | |
provides = ["entities"] | |
requires = ["tokens"] | |
defaults = {} | |
language_list = ["en"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pyaudio | |
from deepspeech import Model | |
import scipy.io.wavfile as wav | |
import wave | |
WAVE_OUTPUT_FILENAME = "test_audio.wav" | |
def record_audio(WAVE_OUTPUT_FILENAME): | |
CHUNK = 1024 |