replaceWords - Replace words in documents - MATLAB (original) (raw)
Replace words in documents
Syntax
Description
[newDocuments](#d126e42901) = replaceWords([documents](#d126e42811),[oldWords](#mw%5Fc6dc604a-9e0b-42f7-98b2-40bc9bf8d85a),[newWords](#mw%5Ffbe272ed-1fa7-4c8b-b557-0f00c975bd32))
updates the specified documents by replacing the words in oldWords
with the corresponding words in newWords
. The function, by default, is case sensitive.
[newDocuments](#d126e42901) = replaceWords([documents](#d126e42811),[oldWords](#mw%5Fc6dc604a-9e0b-42f7-98b2-40bc9bf8d85a),[newWords](#mw%5Ffbe272ed-1fa7-4c8b-b557-0f00c975bd32),'IgnoreCase',true)
replaces the words in oldWords
ignoring case.
Examples
Use the replaceWords
function to replace shorthand words with their corresponding full words.
Create an array of tokenized documents.
str = [ ... "Increased activity Mon to Fri." "Reduced activity Sat to Sun."]; documents = tokenizedDocument(str)
documents = 2×1 tokenizedDocument:
6 tokens: Increased activity Mon to Fri .
6 tokens: Reduced activity Sat to Sun .
Replace the shorthand words with their corresponding full words.
oldWords = ["Mon" "Tue" "Wed" "Thu" "Fri" "Sat" "Sun"]; newWords = ["Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" "Sunday"]; documents = replaceWords(documents,oldWords,newWords)
documents = 2×1 tokenizedDocument:
6 tokens: Increased activity Monday to Friday .
6 tokens: Reduced activity Saturday to Sunday .
Input Arguments
Words to replace, specified as a string array, character vector, or cell array of character vectors.
Data Types: string
| char
| cell
New words, specified as a string array, character vector, or cell array of character vectors.
newWords
must contain one word or be the same size asoldWords. If newWords
contains only one word, then the function replaces all the words in oldWords
with this word.
Data Types: string
| char
| cell
Output Arguments
Tips
Version History
Introduced in R2019a