diff options
author | Botond Hende <nettingman@gmail.com> | 2024-10-16 17:32:13 +0200 |
---|---|---|
committer | Botond Hende <nettingman@gmail.com> | 2024-10-16 17:32:13 +0200 |
commit | a585d159a5acf03d0d75fc39d74ff5ee24e28b8a (patch) | |
tree | 7acc8ab195ca8626222c309a2925b941248a4ecd | |
parent | c435f1d1175f090619cb1ae75e5000e0eafb35e3 (diff) |
name based intent handling
-rw-r--r-- | __init__.py | 0 | ||||
-rw-r--r-- | __main__.py | 47 | ||||
-rw-r--r-- | modules/intents/__init__.py | 4 | ||||
-rw-r--r-- | modules/intents/process.py | 12 |
4 files changed, 63 insertions, 0 deletions
diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/__init__.py diff --git a/__main__.py b/__main__.py new file mode 100644 index 0000000..79d6a23 --- /dev/null +++ b/__main__.py @@ -0,0 +1,47 @@ +import sys +import yaml + +from pathlib import Path +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(): + input_dict = {"intents": {}} + + yaml_path = Path(sys.argv[1]) + yaml_file_paths = yaml_path.glob("*.yaml") + + slot_lists = {} + + 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) + else: + print("<no match>") + except KeyboardInterrupt: + pass + +if __name__ == '__main__': + main()
\ No newline at end of file diff --git a/modules/intents/__init__.py b/modules/intents/__init__.py new file mode 100644 index 0000000..1cb91d4 --- /dev/null +++ b/modules/intents/__init__.py @@ -0,0 +1,4 @@ +from os.path import dirname, basename, isfile, join +import glob +modules = glob.glob(join(dirname(__file__), "*.py")) +__all__ = [ basename(f)[:-3] for f in modules if isfile(f) and not f.endswith('__init__.py')]
\ No newline at end of file diff --git a/modules/intents/process.py b/modules/intents/process.py new file mode 100644 index 0000000..4b3fdab --- /dev/null +++ b/modules/intents/process.py @@ -0,0 +1,12 @@ +import os +from typing import Dict + + +def switch_to_workspace(data: Dict): + os.popen(f"swaymsg workspace {data["workspace"]}") + +def HesExecuteProcess(data: Dict): + if "workspace" in data: + switch_to_workspace(data) + + os.popen(data["process"].strip()) |