Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load word.txt from .caster\filters and documentation update #626

Merged
merged 5 commits into from
Jul 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Index.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

* [Easy Setup](caster/doc/Installation.md) and Configurable Settings

* Customize commands(Specs) and their actions via [simplified filter rules](https://caster.readthedocs.io/en/latest/caster/doc/readthedocs/CCR/#rule-filters-simplified) and [filter rules](https://caster.readthedocs.io/en/latest/caster/doc/readthedocs/examples/rules/Caster%20Rules/#rule-filters)([code](https://github.com/dictation-toolbox/caster/tree/master/caster/user/filters/examples)).
* Customize commands(Specs) and their actions via [simplified filter rules](https://caster.readthedocs.io/en/latest/caster/doc/readthedocs/CCR/#simplified-filter-rules) and [filter rules](https://caster.readthedocs.io/en/latest/caster/doc/readthedocs/examples/rules/Caster%20Rules/#rule-filters)([code](https://github.com/dictation-toolbox/caster/tree/master/caster/user/filters/examples)).

* Compatible Speech Recognition Engines

Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ include _caster.py
include post_setup.py
include ReadMe.md
include castervoice/bin/data/configdebug.txt
include castervoice/bin/share/bringme.toml.defaults
include castervoice/bin/share/FilterRules/words.txt
include castervoice/bin/share/git_repo_local_to_remote_match.toml.defaults
include castervoice/bin/VirtualDesktopAccessor.dll
include castervoice/bin/reboot.bat
Expand Down
6 changes: 6 additions & 0 deletions castervoice/bin/share/FilterRules/words.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<<<SPEC>>>
shock -> earthquake
<<<NOT_SPECS>>>
sauce -> up
dunce -> down
lease -> left
2 changes: 1 addition & 1 deletion castervoice/doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Donate at [![Bountysource](https://www.bountysource.com/badge/team?team_id=40790

- Configurable Settings in `C:\Users\%USERNAME%\.caster`

- Customize Commands aka `Specs` and their actions via [simplified filter rules](https://caster.readthedocs.io/en/latest/readthedocs/CCR/#rule-filters-simplified) and [filter rules](https://caster.readthedocs.io/en/latest/readthedocs/CCR/#Rule-Filters)[code](https://github.com/dictation-toolbox/caster/tree/master/caster/user/filters/examples) (WIP).
- Customize Commands aka `Specs` and their actions via [simplified filter rules](https://caster.readthedocs.io/en/latest/readthedocs/CCR/#simplified-filter-rules) and [filter rules](https://caster.readthedocs.io/en/latest/readthedocs/CCR/#Rule-Filters)[code](https://github.com/dictation-toolbox/caster/tree/master/caster/user/filters/examples) (WIP).

- Compatible Speech Recognition Engines

Expand Down
6 changes: 3 additions & 3 deletions castervoice/doc/readthedocs/CCR.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- [Types of Rules](#types-of-rules)
- [How to Add and Modify Rules](#how-to-add-and-modify-rules)
- [Rule Filters](#rule-filters)
- [Rule Filters Simplified ](#rule-filters-simplified)
- [Simplified Filter Rules](#simplified-filter-rules)
- [Other Features of MergeRule](#other-features-of-mergerule)
- [How to Register Caster CCR Rules](#how-to-register-caster-ccr-rules)

Expand Down Expand Up @@ -65,9 +65,9 @@ Let's go through these.

What rule filters do is expose pairs of rules to the user, allowing the user to change the rules' mapping as they see fit, and/or enable/disable compatibility checking which follows the rule filters.

#### Rule Filters Simplified
#### Simplified Filter Rules

Though rule filters are very powerful, setting one up for the first time is not trivial. Therefore, a simplified method for common use cases has been created. Create the file `.caster\data\words.txt` and it will be read at boot time, and a rule filter created from it and added to Caster's list of rule filters. The following is an example `words.txt`:
Though rule filters are very powerful, setting one up for the first time is not trivial. Therefore, a simplified method for common use cases has been created. Create the file `.caster\filters\words.txt` and it will be read at boot time, and a rule filter created from it and added to Caster's list of rule filters. The following is an example `words.txt`:

```
<<<SPEC>>>
Expand Down
61 changes: 27 additions & 34 deletions castervoice/lib/ccr/recording/bringme.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,21 @@
from castervoice.apps.gitbash import terminal_context
from castervoice.apps.file_dialogue import dialogue_context


class BringRule(SelfModifyingRule):
pronunciation = "bring me"

def refresh(self):
self.mapping = {
"bring me <program>":
R(Function(self.bring_program)),
"bring me <website>":
R(Function(self.bring_website)),
"bring me <folder> [in <app>]":
R(Function(self.bring_folder)),
"bring me <file>":
R(Function(self.bring_file)),

"refresh bring me":
R(Function(self.load_and_refresh)),
"<program> to bring me as <key>":
R(Function(self.bring_add)),
"to bring me as <key>":
R(Function(self.bring_add_auto)),
"remove <key> from bring me":
R(Function(self.bring_remove)),
"restore bring me defaults":
R(Function(self.bring_restore)),
"bring me <program>": R(Function(self.bring_program)),
"bring me <website>": R(Function(self.bring_website)),
"bring me <folder> [in <app>]": R(Function(self.bring_folder)),
"bring me <file>": R(Function(self.bring_file)),
"refresh bring me": R(Function(self.load_and_refresh)),
"<program> to bring me as <key>": R(Function(self.bring_add)),
"to bring me as <key>": R(Function(self.bring_add_auto)),
"remove <key> from bring me": R(Function(self.bring_remove)),
"restore bring me defaults": R(Function(self.bring_restore)),
}
self.extras = [
Choice(
Expand All @@ -38,7 +29,7 @@ def refresh(self):
Choice("app", {
"terminal": "terminal",
"explorer": "explorer",
}),
}),
Dictation("key"),
]
self.extras.extend(self._rebuild_items())
Expand All @@ -47,11 +38,11 @@ def refresh(self):

def __init__(self):
# Contexts
self.browser_context = AppContext(["chrome", "firefox"])
self.browser_context = AppContext(["chrome", "firefox"])
self.explorer_context = AppContext("explorer.exe") | dialogue_context
self.terminal_context = terminal_context
# Paths
self.config_path = settings.SETTINGS["paths"]["BRINGME_PATH"]
self.config_path = settings.SETTINGS["paths"]["BRINGME_PATH"]
self.defaults_path = settings.SETTINGS["paths"]["BRINGME_DEFAULTS_PATH"]
self.terminal_path = settings.SETTINGS["paths"]["TERMINAL_PATH"]
self.explorer_path = "C:\\Windows\\explorer.exe"
Expand All @@ -66,11 +57,10 @@ def bring_website(self, website):

def bring_folder(self, folder, app):
if not app:
ContextAction(
Function(lambda: Popen([self.explorer_path, folder])),
[(self.terminal_context, Text("cd \"%s\"\n" % folder)),
ContextAction(Function(lambda: Popen([self.explorer_path, folder])), [
(self.terminal_context, Text("cd \"%s\"\n" % folder)),
(self.explorer_context, Key("c-l/5") + Text("%s\n" % folder))
]).execute()
]).execute()
elif app == "terminal":
Popen([self.terminal_path, "--cd=" + folder.replace("\\", "/")])
elif app == "explorer":
Expand Down Expand Up @@ -113,11 +103,11 @@ def bring_add(self, launch, key):
def bring_add_auto(self, key):
def add(launch):
return Function(lambda: self.bring_add(launch, key))
ContextAction(
add("program"),
[(self.browser_context, add("website")),

ContextAction(add("program"), [
(self.browser_context, add("website")),
(self.explorer_context, add("folder")),
]).execute()
]).execute()

def bring_remove(self, key):
# Remove item from bring me
Expand All @@ -132,8 +122,9 @@ def bring_remove(self, key):
def _rebuild_items(self):
# E.g. [Choice("folder", {"my pictures": ...}), ...]
return [
Choice(header, {key: os.path.expandvars(value)
for key, value in section.iteritems()})
Choice(header,
{key: os.path.expandvars(value)
for key, value in section.iteritems()})
for header, section in self.config.iteritems()
]

Expand Down Expand Up @@ -187,8 +178,10 @@ def bring_restore(self, startup=False):
"caster bring me": "%USERPROFILE%\\.caster\\data\\bringme.toml",
"caster ccr": "%USERPROFILE%\\.caster\\data\\ccr.toml",
"caster config debug": "%USERPROFILE%\\.caster\\data\\configdebug.txt",
"caster words": "%USERPROFILE%\\.caster\\data\\words.txt",
"caster words": "%USERPROFILE%\\.caster\\filter\\words.txt",
"caster log": "%USERPROFILE%\\.caster\\data\\log.txt",
}}
}
}


control.non_ccr_app_rule(BringRule(), context=None, rdp=False, filter=True)
8 changes: 4 additions & 4 deletions castervoice/lib/dfplus/merge/gfilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ def __init__(self, lines):

DEFS = None

if os.path.isfile(settings.SETTINGS["paths"]["FILTER_WORDS_DEFS_PATH"]):
'''user must create castervoice/user/fdefs.txt for it to get picked up here'''
with io.open(settings.SETTINGS["paths"]["FILTER_WORDS_DEFS_PATH"],
if os.path.isfile(settings.SETTINGS["paths"]["SIMPLIFIED_FILTER_RULES_PATH"]):
'''User must create or place words.txt in '.caster\filters' folder for it to get picked up here'''
with io.open(settings.SETTINGS["paths"]["SIMPLIFIED_FILTER_RULES_PATH"],
"rt",
encoding="utf-8") as f:
lines = f.readlines()
Expand Down Expand Up @@ -223,7 +223,7 @@ def spec_override_from_config(mp):


if DEFS is not None:
print("Global rule filter from file 'words.txt' activated ...")
print("Global simplified rule filter 'words.txt' activated...")


def run_on(rule):
Expand Down
4 changes: 2 additions & 2 deletions castervoice/lib/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ def _find_natspeak():
_USER_DIR + "/data/ccr.toml",
"DLL_PATH":
BASE_PATH + "/lib/dll/",
"FILTER_WORDS_DEFS_PATH":
_USER_DIR + "/data/words.txt",
"SIMPLIFIED_FILTER_RULES_PATH":
_USER_DIR + "/filters/words.txt",
"LOG_PATH":
_USER_DIR + "/log.txt",
"RECORDED_MACROS_PATH":
Expand Down