import os import sys import yaml from pathlib import Path from .modules.config import load_config from .modules.hassil.recognize import recognize from .modules.hassil.util import merge_dict from .modules.hassil.intents import Intents, TextSlotList from .modules.intents import * def main(): config = load_config() input_dict = {"intents": {}} yaml_path = Path(config.intents_dir) yaml_file_paths = yaml_path.glob("*.yaml") processes = [] for file in os.listdir(config.applications_dir): if file == "[": continue full_path = os.path.join(config.applications_dir, file) if os.path.isfile(full_path) or os.path.islink(full_path): processes.append(file) slot_lists = { "process": TextSlotList.from_strings(processes) } for yaml_file_path in yaml_file_paths: with open(yaml_file_path, "r", encoding="utf-8") as yaml_file: merge_dict(input_dict, yaml.safe_load(yaml_file)) intents = Intents.from_dict(input_dict) try: for line in sys.stdin: line = line.strip() if not line: continue result = recognize(line, intents, slot_lists=slot_lists) if result is not None: result_dict = { "intent": result.intent.name, **{e.name: e.value for e in result.entities_list}, } print(result_dict) handler = getattr(globals()[result_dict["domain"]], result_dict["intent"]) handler(result_dict, config) else: print("") except KeyboardInterrupt: pass if __name__ == '__main__': main()