diff options
author | Irene Knapp <ireneista@irenes.space> | 2025-09-06 19:09:55 -0700 |
---|---|---|
committer | Irene Knapp <ireneista@irenes.space> | 2025-09-06 19:09:55 -0700 |
commit | a1d3db61140b397e30bd1e1d2142ef1467019eab (patch) | |
tree | 094ff4671efaea77e4aa458e476b6188689a8486 /src/pollyanna/pollyanna.py | |
parent | 63ed2e5a680b6e0e352721a8238e2918cb3e70ff (diff) |
Force-Push: yeah Change-Id: Ibe3a058173cded6355fadd413349cf9cc8823fdd
Diffstat (limited to 'src/pollyanna/pollyanna.py')
-rw-r--r-- | src/pollyanna/pollyanna.py | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/src/pollyanna/pollyanna.py b/src/pollyanna/pollyanna.py index 295a1e5..b1ad38d 100644 --- a/src/pollyanna/pollyanna.py +++ b/src/pollyanna/pollyanna.py @@ -9,6 +9,7 @@ import os.path import subprocess from gi.repository import GObject, GLib +from pollyanna.arbitrary import ArbitraryParser from pollyanna.recognizer import Recognizer from pollyanna.util import * from pollyanna.numbers import NumberParser @@ -26,8 +27,9 @@ class Pollyanna: self.options = vars(self.config.options) self.commands = self.options['commands'] - # Create number parser for later use + # Create parsers for later use self.number_parser = NumberParser() + self.arbitrary_parser = ArbitraryParser() # Create a hasher self.hasher = Hasher(self.config) @@ -88,10 +90,13 @@ class Pollyanna: with open(self.config.strings_file, 'w') as strings: # Add command words to the corpus for voice_cmd in sorted(self.commands.keys()): - strings.write(voice_cmd.strip().replace('%d', '') + "\n") + strings.write(re.sub(r'%[ds]', '', voice_cmd.strip()) + "\n") # Add number words to the corpus for word in self.number_parser.number_words: strings.write(word + " ") + # Add dictionary words for arbitrary substrings to the corpus + for word in self.arbitrary_parser.all_words: + strings.write(word + " ") strings.write("\n") def log_history(self, text): @@ -139,11 +144,26 @@ class Pollyanna: self.run_command(cmd) self.log_history(text) else: - # Run the invalid_sentence_command if it's set - if self.options['invalid_sentence_command']: - subprocess.call(self.options['invalid_sentence_command'], - shell=True) - print("no matching command {0}".format(t)) + is_matched = False + for command in self.commands: + match_result = self.arbitrary_parser.match(command, t) + if match_result != None: + is_matched = True + break + if is_matched: + cmd = self.commands[command] + cmd = cmd.format(' '.join(match_result)) + # 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 it's set + if self.options['invalid_sentence_command']: + subprocess.call(self.options['invalid_sentence_command'], + shell=True) + print("no matching command {0}".format(t)) # If there is a UI and we are not continuous listen if self.ui: if not self.continuous_listen: |