Output cleaned up ngrams to text files before importing.

The cleaned-up ngrams are writtent to files first, then the files are
imported. Also add a "checkdb" routine to check what ngrams are already
in the database (to prevent duplicate import).