def extract_domain(top_domain_file, full_extract=True):
        """
        Extract a dialogue domain from the XML specification

        :param top_domain_file: the filename of the top XML file
        :param full_extract: whether to extract the full domain or only the files
        :return: the extracted dialogue domain
        """
        # create a new, empty domain
        domain = Domain()

        # determine the root path and filename
        fl = open(top_domain_file, 'r')
        domain.set_source_file(Path(top_domain_file))

        # extract the XML document
        document = XMLUtils.get_xml_document(fl)
        main_node = XMLUtils.get_main_node(document)

        root_path = Path(top_domain_file).parent

        for child in main_node:
            domain = XMLDomainReader.extract_partial_domain(
                child, domain, root_path, full_extract)

        return domain
    def __init__(self, arg1=None):

        if arg1 is None:
            """
            Creates a new dialogue system with an empty dialogue system
            """
            self._settings = Settings()  # the system setting
            self._cur_state = DialogueState()  # the dialogue state

            self._domain = Domain()  # the dialogue domain
            self._paused = True  # whether the system is paused or active
            self._modules = []  # the set of modules attached to the system

            # Inserting standard modules
            system = self
            self._modules.append(GUIFrame(system))
            self._modules.append(DialogueRecorder(self))
            if self._settings.planner == 'forward':
                self.log.info("Forward planner will be used.")
                self._modules.append(ForwardPlanner(self))
            elif self._settings.planner == 'mcts':
                self.log.info("MCTS planner will be used.")
                self._modules.append(MCTSPlanner(self))
            else:
                raise ValueError("Not supported planner: %s" %
                                 self._settings.planner)
            self._init_lock()

        elif isinstance(arg1, Domain):
            domain = arg1
            """
            Creates a new dialogue system with the provided dialogue domain

            :param domain: the dialogue domain to employ
            """
            self.__init__()
            self.change_domain(domain)
        elif isinstance(arg1, str):
            domain_file = arg1
            """
            Creates a new dialogue system with the provided dialogue domain

            :param domain_file: the dialogue domain to employ
            """
            self.__init__()
            self.change_domain(XMLDomainReader.extract_domain(domain_file))
    def refresh_domain(self):
        """
        Refreshes the dialogue domain by rereading its source file (in case it has been changed by the user).
        """
        if self._domain.is_empty():
            return

        src_file = self._domain.get_source_file().get_path()

        try:
            self._domain = XMLDomainReader.extract_domain(src_file)
            self.change_settings(self._domain.get_settings())
            self.display_comment("Dialogue domain successfully updated")
        except Exception as e:
            self.log.critical("Cannot refresh domain %s" % e)
            self.display_comment("Syntax error: %s" % e)
            self._domain = Domain()
            self._domain.set_source_file(src_file)
Example #4
0
# Config file for the destination domain

import os
import sys
from keys import keys
from domains.domain import Domain

sys.path.append(os.path.join(sys.path[0], '../..'))  # for loading apis

from apis.maps.map_interface import MapInterface

# Initialize interfaces
interfaces = [MapInterface('google', keys['google_maps'])]

# Create a Domain object, which will be used from this file
destination_domain = Domain(
    'destination',
    interfaces,
    initialization_file='domains/destination/initialization.json',
    apis_file='domains/destination/apis.json',
    agent_templates='domains/destination/agent_templates.txt',
    user_templates='domains/destination/user_templates.txt',
)
Example #5
0
# Config file for the weather domain

import os
import sys
from keys import keys
from domains.domain import Domain

sys.path.append(os.path.join(sys.path[0], '../..'))  # for loading apis

from apis.weather.weather_interface import WeatherInterface
from apis.maps.map_interface import MapInterface

# Initialize interfaces
interfaces = [
    WeatherInterface(keys['darksky'], keys['wit_date']),
    MapInterface('google', keys['google_maps'])
]

# Create a Domain object, which will be used from this file
weather_domain = Domain(
    'weather',
    interfaces,
    initialization_file='domains/weather/initialization.json',
    apis_file='domains/weather/apis.json',
    agent_templates='domains/weather/agent_templates.txt')
Example #6
0
REPO_ROOT = pathlib.Path(__file__).resolve().parents[4]
sys.path.append(str(REPO_ROOT))  # For loading apis
sys.path.append(str(REPO_ROOT / "gui" / "backend"))  # For loading domains

from domains.domain import Domain
from apis.maps.map_interface import MapInterface

# Initialize interfaces
interfaces = [MapInterface('microworld', map_path='microworld_map.txt')]

# Create a Domain object, which will be used from this file
DOMAIN_DIR = REPO_ROOT / "gui/backend/domains/microworld"
microworld_domai1 = Domain(
    'microworld1',
    interfaces,
    initialization_file=DOMAIN_DIR / 'initialization1.json',
    apis_file=DOMAIN_DIR / 'apis.json',
    agent_templates=DOMAIN_DIR / 'agent_templates.txt',
    user_templates=DOMAIN_DIR / 'user_templates.txt',
)

# Microworld v2
microworld_domain2 = Domain(
    'microworld2',
    [MapInterface('microworld', map_path='microworld_map2.txt')],
    initialization_file=DOMAIN_DIR / 'initialization2.json',
    apis_file=DOMAIN_DIR / 'apis.json',
    agent_templates=DOMAIN_DIR / 'agent_templates.txt',
    user_templates=DOMAIN_DIR / 'user_templates.txt',
)