summary refs log tree commit diff
path: root/kaylee.py
diff options
context:
space:
mode:
authorClayton G. Hobbs <clay@lakeserv.net>2015-12-30 23:33:29 -0500
committerClayton G. Hobbs <clay@lakeserv.net>2015-12-30 23:33:29 -0500
commite19d76f0515b291f9c6994bfd0faccccf5b894aa (patch)
treedb29ef0dbecee06e0788d9f72c9d327caa1b1479 /kaylee.py
parent57f58295a48dfa4d893eb1546c5f2f64133c0e7f (diff)
Added number parsing capabilities
See commands.tmp for an example.  It's pretty neat, but it could still
use some work.  I thought of a really clever way to parse numbers, better
than the one I came up with last night, but since I have a working
implementation now I figure I'd better commit it.

We have a new bug which causes the dictionary to be updated every time the
program starts.  I hope I didn't force that to happen last night or
something, but I have a vague feeling I did.
Diffstat (limited to 'kaylee.py')
-rwxr-xr-xkaylee.py27
1 files changed, 22 insertions, 5 deletions
diff --git a/kaylee.py b/kaylee.py
index 7aedb22..0ea9a16 100755
--- a/kaylee.py
+++ b/kaylee.py
@@ -2,8 +2,8 @@
 
 # This is part of Kaylee
 # -- this code is licensed GPLv3
-# Copyright 2013 Jezra
 # Copyright 2015 Clayton G. Hobbs
+# Portions Copyright 2013 Jezra
 
 from __future__ import print_function
 import sys
@@ -17,6 +17,7 @@ import json
 from recognizer import Recognizer
 from config import Config
 from languageupdater import LanguageUpdater
+from numberparser import NumberParser
 
 
 class Kaylee:
@@ -33,6 +34,9 @@ class Kaylee:
         self.config = Config()
         self.options = vars(self.config.options)
 
+        # Create number parser for later use
+        self.number_parser = NumberParser()
+
         # Read the commands
         self.read_commands()
 
@@ -79,7 +83,10 @@ class Kaylee:
                 # This is a parsible line
                 (key, value) = line.split(":", 1)
                 self.commands[key.strip().lower()] = value.strip()
-                strings.write(key.strip() + "\n")
+                strings.write(key.strip().replace('%d', '') + "\n")
+        # Add number words to the corpus
+        for word in self.number_parser.number_words:
+            strings.write(word + "\n")
         # Close the strings file
         strings.close()
 
@@ -104,6 +111,7 @@ class Kaylee:
 
     def recognizer_finished(self, recognizer, text):
         t = text.lower()
+        numt, nums = self.number_parser.parse_all_numbers(t)
         # Is there a matching command?
         if t in self.commands:
             # Run the valid_sentence_command if there is a valid sentence command
@@ -113,9 +121,18 @@ class Kaylee:
             # Should we be passing words?
             if self.options['pass_words']:
                 cmd += " " + t
-                self.run_command(cmd)
-            else:
-                self.run_command(cmd)
+            self.run_command(cmd)
+            self.log_history(text)
+        elif numt in self.commands:
+            # Run the valid_sentence_command if there is a valid sentence command
+            if self.options['valid_sentence_command']:
+                subprocess.call(self.options['valid_sentence_command'], shell=True)
+            cmd = self.commands[numt]
+            cmd = cmd.format(*nums)
+            # Should we be passing words?
+            if self.options['pass_words']:
+                cmd += " " + t
+            self.run_command(cmd)
             self.log_history(text)
         else:
             # Run the invalid_sentence_command if there is an invalid sentence command