From e19d76f0515b291f9c6994bfd0faccccf5b894aa Mon Sep 17 00:00:00 2001 From: "Clayton G. Hobbs" Date: Wed, 30 Dec 2015 23:33:29 -0500 Subject: 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. --- kaylee.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'kaylee.py') 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 -- cgit 1.4.1