Python Forum

Full Version: Generating all simple sentence possibilities
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello all,

I am using Python 3.7.0 on Windows 7. I am trying to make a program that can generate all possible simple sentences. Here is the problem.

"Aaa aaa aaa." - is a message received and only lets you know about the capitalization and grammar of the sentence. Make a program that generates all possibilities in English.
The answer to the problem is: "The dog ran."

Any thoughts or pointers on how to start this problem or where to look would be great! The only go to reference source I have found is: Natural Language Processing in Python.


-Thanks!
You are going to need a word list. You are going to need to load that word list and store the words by length. Then you will need to combine them with product from the itertools library.

That will give you all the sentences, but a lot of them will not be grammatical (like 'ran dog the'). For weeding out the bad sentences, you are going to need serious natural language processing.
the natural language processing tool NLTK: http://www.nltk.org/ comes with a huge set of copora. It's quite easy to use, and is worth spending an hour or so looking at to see if it will fulfill your needs.
-Thanks for the replies everyone!