#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
if __name__ == '__main__':
import autopath
import argparse
from alex.applications.exceptions import SemHubException
from alex.components.hub import Hub
from alex.components.slu.da import DialogueAct, DialogueActNBList
from alex.components.slu.exceptions import DialogueActException, DialogueActItemException
from alex.components.dm.common import dm_factory, get_dm_type
from alex.utils.config import Config
[docs]class SemHub(Hub):
"""
SemHub builds a text based testing environment for the dialogue manager components.
It reads dialogue acts from the standard input and passes it to the selected dialogue manager.
The output is the form dialogue acts.
"""
hub_type = "SHub"
def __init__(self, cfg):
super(SemHub, self).__init__(cfg)
dm_type = get_dm_type(cfg)
self.dm = dm_factory(dm_type, cfg)
self.dm.new_dialogue()
[docs] def output_da(self, da):
"""Prints the system dialogue act to the output."""
print "System DA:", unicode(da)
print
[docs] def run(self):
"""Controls the dialogue manager."""
try:
self.cfg['Logging']['system_logger'].info("""Enter the first user dialogue act. You can enter multiple dialogue acts to create an N-best list.
The probability for each dialogue act must be be provided before the the dialogue act itself.
When finished, the entry can be terminated by a period ".".
For example:
System DA 1: 0.6 hello()
System DA 2: 0.4 hello()&inform(type="bar")
System DA 3: .
""")
while True:
self.cfg['Logging']['session_logger'].turn("system")
self.dm.log_state()
sys_da = self.dm.da_out()
self.output_da(sys_da)
nblist = self.input_da_nblist()
self.dm.da_in(nblist)
#print "#102", nblist
except:
self.cfg['Logging']['system_logger'].exception('Uncaught exception in SHUB process.')
raise
#########################################################################
#########################################################################
if __name__ == '__main__':
parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
description="""
SemHub is a text based testing environment for the dialogue manager components.
It reads dialogue acts from the standard input and passes it to the selected dialogue manager.
The output is the form dialogue acts.
The program reads the default config in the resources directory ('../resources/default.cfg') config
in the current directory.
In addition, it reads all config file passed as an argument of a '-c'.
The additional config files overwrites any default or previous values.
""")
parser.add_argument('-c', "--configs", nargs='+',
help='additional configuration files')
args = parser.parse_args()
cfg = Config.load_configs(args.configs)
#########################################################################
#########################################################################
cfg['Logging']['system_logger'].info("Sem Hub\n" + "=" * 120)
cfg['Logging']['system_logger'].session_start("localhost")
cfg['Logging']['system_logger'].session_system_log('config = ' + unicode(cfg))
cfg['Logging']['session_logger'].session_start(cfg['Logging']['system_logger'].get_session_dir_name())
cfg['Logging']['session_logger'].config('config = ' + unicode(cfg))
cfg['Logging']['session_logger'].header(cfg['Logging']["system_name"], cfg['Logging']["version"])
cfg['Logging']['session_logger'].input_source("dialogue acts")
shub = SemHub(cfg)
shub.run()