is an option that specifies how the input should be preprocessed.
PreprocessingRules
is an option that specifies how the input should be preprocessed.
Details
- The rules given by PreprocessingRules are applied to each expression.
- Typical settings are:
-
Automatic an automatic choice of preprocessing None no preprocessing rules explicit set of preprocessing rules - Rules for PreprocessingRules can involve patterns.
Examples
open all close allBasic Examples (2)
Scope (2)
Specify a default processing rule:
WordCloud[RandomInteger[9, 100], PreprocessingRules -> {n_ ? PrimeQ :> Style[n, Red], n_ :> Style[n, Blue]}]Without a default rule, automatic styling is used:
WordCloud[data = RandomInteger[9, 100], PreprocessingRules -> {n_ ? PrimeQ :> Style[n, Red]}]Compare with all default styles:
WordCloud[data]Applications (3)
Spellcheck strings before displaying them:
WordCloud[{"dog", "bananna", "elefant", "peple"}, PreprocessingRules -> s_String :> First[SpellingCorrectionList[s]]]Round real numbers to their closest integers:
WordCloud[RandomReal[10, 100]]WordCloud[RandomReal[10, 100], PreprocessingRules -> x_Real :> Round[x]]Create a function that takes the first match in the dictionary given a word stem:
string = DeleteStopwords@Import["https://en.wikipedia.org/wiki/Word_stem"];stems = GroupBy[DictionaryLookup[], WordStem];
firstByStem[s_] := First[Lookup[stems, WordStem[s], {s}]]Use it to regularize the input of WordCloud:
WordCloud[string, PreprocessingRules -> s_String :> firstByStem[s]]Modify the function to only return verbs:
firstVerbByStem[s_] := First[Flatten[TextCases[Lookup[stems, WordStem[s], {s}], "Verb"]], {}]WordCloud[string, PreprocessingRules -> s_String :> firstVerbByStem[s]]Properties & Relations (2)
When the preprocessing splits the word into multiple words, weights are propagated to new words:
words = Tally[TextWords[Import["http://www.wolfram.com"]]];
Short[words]WordCloud[words]WordCloud[words, PreprocessingRules -> s_String :> Characters[s]]If a word matches more than one pattern, the first match is used:
WordCloud[Range[100],
PreprocessingRules -> {
n_ ? PrimeQ :> Style[n, Red, Italic],
n_ /; n > 50 :> Style[n, Darker@Green]},
ColorFunction -> StandardGray, WordSpacings -> {6, 2}
]Related Guides
History
Text
Wolfram Research (2017), PreprocessingRules, Wolfram Language function, https://reference.wolfram.com/language/ref/PreprocessingRules.html.
CMS
Wolfram Language. 2017. "PreprocessingRules." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/PreprocessingRules.html.
APA
Wolfram Language. (2017). PreprocessingRules. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/PreprocessingRules.html
BibTeX
@misc{reference.wolfram_2026_preprocessingrules, author="Wolfram Research", title="{PreprocessingRules}", year="2017", howpublished="\url{https://reference.wolfram.com/language/ref/PreprocessingRules.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_preprocessingrules, organization={Wolfram Research}, title={PreprocessingRules}, year={2017}, url={https://reference.wolfram.com/language/ref/PreprocessingRules.html}, note=[Accessed: 12-June-2026]}