Added logging and refactored word type collecting.

Word type collecting is moved to a private method since it's used by all
three parsing methods.

It also "memoizes" the collection of word types because it can take a
long time for large files.