check_spelling: Check Spelling

Description Usage Arguments Details Value Examples

View source: R/check_spelling.R

Description

This function performs spell-checking on input text. It can provide a list of errors and probable correct spellings, as well as returning the input text with all errors corrected.

Usage

1
check_spelling(inputText, mode, customSpellingList)

Arguments

inputText

A character string or vector of character strings

mode

This defines the mode of operation. Options include "output", "replace", or "both". See Details below.

customSpellingList

(Optional argument) If provided, the function will use this list to correct spelling errors. Must be in the same format as the result of "output" mode, and only works in "replace" mode.

Details

This function has three modes: In the "output" mode, a dataframe is produced with three columns: the spelling errors present in the input text, how frequently they appear, and the most likely correct spelling for each word. A frequency graph is also plotted. In the "replace" mode, a character string (or vector of character strings) is produced, where all of the spelling errors identified are replaced by their most likely correct spelling. When customSpellingList = TRUE, the "replace" mode will only correct words in the provided list In the "both" mode, both of the above results will be produced (i.e. a list containing a dataframe of errors and suggestions, as well as the text with corrected spellings)

As a warning, this function is particularly slow, and make take a significantly long time on a sizeable vector of character strings.

Value

A dataframe (mode="output"), a character string or vector of character strings (mode="replace"), or a two-object list containing both results (mode="both")

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
myString = "I went to the stroe and bought some egggs for a good porce!"

spell_check_results = check_spelling(myString, mode = "output")
spell_check_results
# error    freq    suggested_correction
# egggs    1       eggs
# stroe    1       store
# porce    1       pore

spell_correction_results = check_spelling(myString, mode = "replace")
spell_correction_results
# "I went to the store and bought some eggs for a good pore!"

error = c("egggs", "stroe", "porce")
suggested_correction = c("eggs", "store", "price")
my_corrections = data.frame(error=error, suggested_correction = suggested_correction)
correction_results = check_spelling(myString, mode = "replace", customSpellingList = my_corrections)
correction_results
# "I went to the store and bought some eggs for a good price!"

nlanderson9/languagePredictR documentation built on June 10, 2021, 11 a.m.