1. Using lower, make all words lower case, so you need not worry about capitalization.
2. Apply my allwords code to the string. Use spaces and any appropriate punctuation as separator characters.
3. Use unique to get the distinct words in that list. The third argument from unique will be important.
4. Apply accumarray to that third argument from unique to count the words.
Essentially 4 quick lines of code.