vocabulary
The community/core/vocabulary
directory contains files that manage custom vocabulary and word replacement for Talon.
The most important file is vocabulary.py
, which defines how custom vocabulary is loaded, modified, and used by Talon. It provides actions to add words to the vocabulary, either as direct vocabulary entries or as replacements for other words or phrases. It uses two files to store the user's customizations: words_to_replace.csv
(not included here) and vocabulary.talon-list
.
vocabulary.py
has these key features:
PhraseReplacer
: This class handles the replacement of words and phrases. It stores phrases to be replaced in a way that prioritizes longer phrases, ensuring that"this is a test"
is replaced before"this is"
. It can be updated with a dictionary of phrases.on_word_map
: This function loads words fromwords_to_replace.csv
using@track_csv_list
and uses them to update both thePhraseReplacer
and thedictate.word_map
setting (used by Talon's built-in word replacement).dictate.replace_words
: This action is overridden to use thePhraseReplacer
to replace words. If the phrase replacer fails, it falls back to Talon's default word replacement._create_vocabulary_entries
: This helper function expands vocabulary entries to include possessives (e.g.,"john" -> "john's"
) or plurals (e.g.,"cat" -> "cats"
), which are added to vocabulary._add_selection_to_file
: This helper adds selected text as new vocabulary entries to eithervocabulary.talon-list
orwords_to_replace.csv
. It skips adding entries that are identical to what they replace or that are already in the list.append_to_vocabulary
: This helper appends new vocabulary entries tovocabulary.talon-list
, handling the different formats used in that file.get_vocabulary_file_path
: An action that returns the path tovocabulary.talon-list
.add_selection_to_vocabulary
andadd_selection_to_words_to_replace
: These actions are used to add new vocabulary words or replacements to the appropriate files.
vocabulary.talon-list
contains a list of custom vocabulary words and phrases. Each line is either a single word, or a colon-separated pair of a spoken form and a written form. The written form may be a quoted string.
edit_vocabulary.talon
provides commands to add selected text to the vocabulary or to the word replacements. These commands use the actions defined in vocabulary.py
, and allow you to optionally specify a spoken form for the new entry. The possessive and plural variants can be added automatically.
In summary, vocabulary.py
defines how custom vocabulary and word replacements are managed in Talon. vocabulary.talon-list
stores custom vocabulary, and edit_vocabulary.talon
provides the commands used to easily add new words and phrases to the vocabulary from Talon.