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

Reimplement #636 #1602

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions core/abbreviate/abbreviate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
43 changes: 38 additions & 5 deletions core/text/text_and_dictation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -143,12 +148,14 @@ def prose_time(m) -> str:
return str(m)


@mod.capture(rule="({user.vocabulary} | <word>)")
@mod.capture(rule="({user.vocabulary} | <user.abbreviation> | <word>)")
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))
)
Expand All @@ -161,7 +168,7 @@ def text(m) -> str:


@mod.capture(
rule="(<phrase> | {user.vocabulary} | {user.punctuation} | {user.prose_snippets} | <user.prose_currency> | <user.prose_time> | <user.prose_number> | <user.prose_percent> | <user.prose_modifier>)+"
rule="(<phrase> | {user.vocabulary} | {user.punctuation} | {user.prose_snippets} | <user.prose_currency> | <user.prose_time> | <user.prose_number> | <user.prose_percent> | <user.prose_modifier> | <user.abbreviation>)+"
)
def prose(m) -> str:
"""Mixed words and punctuation, auto-spaced & capitalized."""
Expand All @@ -170,13 +177,39 @@ def prose(m) -> str:


@mod.capture(
rule="(<phrase> | {user.vocabulary} | {user.punctuation} | {user.prose_snippets} | <user.prose_currency> | <user.prose_time> | <user.prose_number> | <user.prose_percent>)+"
rule="(<phrase> | {user.vocabulary} | {user.punctuation} | {user.prose_snippets} | <user.prose_currency> | <user.prose_time> | <user.prose_number> | <user.prose_percent> | <user.abbreviation>)+"
)
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} | <phrase>)+")
def text_dragon(m) -> str:
"""A sequence of words, including user-defined vocabulary."""
return format_phrase(m)


@ctx_dragon.capture(
"user.prose",
rule="(<phrase> | {user.vocabulary} | {user.punctuation} | {user.prose_snippets} | <user.prose_currency> | <user.prose_time> | <user.prose_number> | <user.prose_percent> | <user.prose_modifier>)+",
)
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="(<phrase> | {user.vocabulary} | {user.punctuation} | {user.prose_snippets} | <user.prose_currency> | <user.prose_time> | <user.prose_number> | <user.prose_percent>)+",
)
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)
Expand Down