summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--__main__.py32
-rw-r--r--modules/input_handlers/__init__.py0
-rw-r--r--modules/input_handlers/stdin_input.py9
3 files changed, 22 insertions, 19 deletions
diff --git a/__main__.py b/__main__.py
index 008ceb4..4677b7c 100644
--- a/__main__.py
+++ b/__main__.py
@@ -7,6 +7,7 @@ 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.input_handlers.stdin_input import get_input_stdin
from .modules.intents import *
@@ -37,25 +38,18 @@ def main():
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("<no match>")
- except KeyboardInterrupt:
- pass
+ for input_text in get_input_stdin():
+ result = recognize(input_text, 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("<no match>")
if __name__ == '__main__':
main() \ No newline at end of file
diff --git a/modules/input_handlers/__init__.py b/modules/input_handlers/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/modules/input_handlers/__init__.py
diff --git a/modules/input_handlers/stdin_input.py b/modules/input_handlers/stdin_input.py
new file mode 100644
index 0000000..044ac0d
--- /dev/null
+++ b/modules/input_handlers/stdin_input.py
@@ -0,0 +1,9 @@
+import sys
+
+def get_input_stdin():
+ for line in sys.stdin:
+ line = line.strip()
+ if not line:
+ continue
+
+ yield line \ No newline at end of file