I am trying to leverage the AI used in MS Word to ascertain the part of speech of every word in a doc file. That is, for a sentence like: "The cat sat on it.", I would get something along the lines of: "The [wdDeterminer] cat[wdNoun] sat[wdVerb] on[wdPreposition] it[wdPronoun]".
I know that Word must do this internally for its grammar proofing tools to work. My question is: is it possible for a script to access this information.
Please note, I am NOT trying to run spellcheck through VBA (though this will be a trivial part of the solution). Also, I am not interested in the thesaurus module.
There are solutions outside of VBA, such as the python Lemmatization with NLTK, but I was wondering if anyone knew of a purely VBA solution. My investigations so far suggest no, but I'm hoping I've overlooked something.
CodePudding user response:
The Word extensibility model doesn't provide anything for that. The best what you could use are the following properties and methods:
- The Options.CheckGrammarWithSpelling property controls whether Word checks grammar when you check spelling by using the Spelling command (Tools menu).
- The Options.CheckGrammarAsYouType property marks grammatical errors, but to see them on screen, you must set the
ShowGrammaticalErrors
property toTrue
. - The Application.CheckGrammar method checks a string for grammatical errors. Returns a Boolean to indicate whether the string contains grammatical errors. True if the string contains no errors.
- The Application.CheckSpelling method checks a string for spelling errors. Returns a
Boolean
to indicate whether the string contains spelling errors.True
if the string has no spelling errors.