diff --git a/core/abbreviate/abbreviate.py b/core/abbreviate/abbreviate.py index cb43d5c192..388744fee6 100644 --- a/core/abbreviate/abbreviate.py +++ b/core/abbreviate/abbreviate.py @@ -449,6 +449,11 @@ } +@mod.capture(rule="brief {user.abbreviation}") +def abbreviation(m) -> str: + return m.abbreviation + + @track_csv_list( "abbreviations.csv", headers=("Abbreviation", "Spoken Form"), default=abbreviations ) diff --git a/core/text/text_and_dictation.py b/core/text/text_and_dictation.py index b60302bf2e..c4e79693a0 100644 --- a/core/text/text_and_dictation.py +++ b/core/text/text_and_dictation.py @@ -27,6 +27,11 @@ ) ctx = Context() +ctx_dragon = Context() +ctx_dragon.matches = r""" +speech.engine: dragon +""" + # Maps spoken forms to DictationFormat method names (see DictationFormat below). ctx.lists["user.prose_modifiers"] = { "cap": "cap", @@ -143,12 +148,14 @@ def prose_time(m) -> str: return str(m) -@mod.capture(rule="({user.vocabulary} | )") +@mod.capture(rule="({user.vocabulary} | | )") def word(m) -> str: """A single word, including user-defined vocabulary.""" - try: + if hasattr(m, "vocabulary"): return m.vocabulary - except AttributeError: + elif hasattr(m, "abbreviation"): + return m.abbreviation + else: return " ".join( actions.dictate.replace_words(actions.dictate.parse_words(m.word)) ) @@ -161,7 +168,7 @@ def text(m) -> str: @mod.capture( - rule="( | {user.vocabulary} | {user.punctuation} | {user.prose_snippets} | | | | | )+" + rule="( | {user.vocabulary} | {user.punctuation} | {user.prose_snippets} | | | | | | )+" ) def prose(m) -> str: """Mixed words and punctuation, auto-spaced & capitalized.""" @@ -170,13 +177,39 @@ def prose(m) -> str: @mod.capture( - rule="( | {user.vocabulary} | {user.punctuation} | {user.prose_snippets} | | | | )+" + rule="( | {user.vocabulary} | {user.punctuation} | {user.prose_snippets} | | | | | )+" ) def raw_prose(m) -> str: """Mixed words and punctuation, auto-spaced & capitalized, without quote straightening and commands (for use in dictation mode).""" return apply_formatting(m) +# For dragon, omit support for abbreviations +@ctx_dragon.capture("user.text", rule="({user.vocabulary} | )+") +def text_dragon(m) -> str: + """A sequence of words, including user-defined vocabulary.""" + return format_phrase(m) + + +@ctx_dragon.capture( + "user.prose", + rule="( | {user.vocabulary} | {user.punctuation} | {user.prose_snippets} | | | | | )+", +) +def prose_dragon(m) -> str: + """Mixed words and punctuation, auto-spaced & capitalized.""" + # Straighten curly quotes that were introduced to obtain proper spacing. + return apply_formatting(m).replace("“", '"').replace("”", '"') + + +@ctx_dragon.capture( + "user.raw_prose", + rule="( | {user.vocabulary} | {user.punctuation} | {user.prose_snippets} | | | | )+", +) +def raw_prose_dragon(m) -> str: + """Mixed words and punctuation, auto-spaced & capitalized, without quote straightening and commands (for use in dictation mode).""" + return apply_formatting(m) + + # ---------- FORMATTING ---------- # def format_phrase(m): words = capture_to_words(m)