Ejemplo n.º 1
0
def init_code(dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
        import directory_loader as dl
        d = dl.Directory()

        try:
            input_type = tracker.latest_message['entities'][0]['entity']
            value = tracker.latest_message['entities'][0]['value']
        except:
            input_type = 'code'
            value = tracker.get_slot('code')

        if not value:
            dispatcher.utter_template('utter_fallback', tracker)
            return None

        if input_type == 'name':
            results = d.search(value)
            if len(results) == 0:
                dispatcher.utter_template("utter_code_does_not_exist", tracker, name=value)
                return None
            elif len(results) > 1:
                dispatcher.utter_message('There are multiple results for {}:'.format(value))
                for r in results:
                    i = d[r[0]]
                    dispatcher.utter_message('{} {}'.format(i.code(), i.get_name()))
                dispatcher.utter_message('Please reply with the correct code.')
                return None
            else:
                result = d[results[0][0]]

        elif input_type == 'code':
            try:
                result = d[value]
            except KeyError:
                dispatcher.utter_template("utter_code_does_not_exist", tracker, code=value)
                return None
        else:
            dispatcher.utter_template('utter_fallback', tracker)
            return None

        return result
Ejemplo n.º 2
0
 def run(self, dispatcher: CollectingDispatcher,
         tracker: Tracker,
         domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
     import directory_loader as dl
     d = dl.Directory()
     input_type = tracker.latest_message['entities'][0]['entity']
     value = tracker.latest_message['entities'][0]['value']
     if not value:
         dispatcher.utter_template('utter_fallback', tracker)
         return []
     if input_type == 'name':
         results = d.search(value)
         if len(results) == 0:
             dispatcher.utter_name_does_not_exist("utter_default", tracker, name=value)
             return []
         elif len(results) > 1:
             dispatcher.utter_message('There are multiple results for {}:'.format(value))
             for r in results:
                 i = d[r[0]]
                 dispatcher.utter_message('{} {}'.format(i.code(), i.get_name()))
             dispatcher.utter_message('Please reply with the correct code.')
             return []
         else:
             result = d[results[0][0]]
     elif input_type == 'code':
         try:
             result = d[value]
         except KeyError:
             dispatcher.utter_code_does_not_exist("utter_default", tracker, code=value)
             return []
     else:
         dispatcher.utter_template('utter_fallback', tracker)
         return []
     dispatcher.utter_message('{} {} is a {} at UTS. For more info, visit {}'.format(result.code(),
                                                                                     result.get_name(),
                                                                                     result.get_type(),
                                                                                     result.url()))
     return [SlotSet("code", result.just_code())]
Ejemplo n.º 3
0
#
# See this guide on how to implement these action:
# https://rasa.com/docs/rasa/core/actions/#custom-actions/


# This is a simple example for a custom action which utters "Hello World!"

from typing import Any, Text, Dict, List

from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.events import SlotSet
import directory_loader as dl
from functools import reduce

d = dl.Directory()
map = {
    "":"when does 48024 in  take classes?",
            "bachelor of information technology":"Bachelor of Information Technology",
            "bachelor of science ( honours ) in information technology":"Bachelor of Science (Honours) in Information Technology",
            "business information systems management in bachelor of science in information technology":"Business Information Systems Management in Bachelor of Science in Information Technology",
            "data analytics in bachelor of science in information technology":"Data Analytics in Bachelor of Science in Information Technology",
            "enterprise systems development in bachelor of science in information technology":"Enterprise Systems Development in Bachelor of Science in Information Technology",
            "interaction design in bachelor of science in information technology":"Interaction Design in Bachelor of Science in Information Technology",
            "networking and cybersecurity in bachelor of science in information technology":"Networking and Cybersecurity in Bachelor of Science in Information Technology",
            "business information systems management in bachelor of computing science":"Business Information Systems Management in Bachelor of Computing Science (Honours)",
            "interaction design in bachelor of computing science":"Interaction Design in Bachelor of Computing Science (Honours)",
            "networking and cybersecurity in bachelor of computing science":"Networking and Cybersecurity in Bachelor of Computing Science (Honours)",
            "enterprise systems development in bachelor of computing science":"Enterprise Systems Development in Bachelor of Computing Science (Honours)",
            "artificial intelligence and data analytics in bachelor of computing science":"Artificial Intelligence and Data Analytics in Bachelor of Computing Science (Honours)",
            "mathematical analysis in bachelor of computing science":"Mathematical Analysis in Bachelor of Computing Science (Honours)",