Python Forum
Generating all simple sentence possibilities - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Generating all simple sentence possibilities (/thread-13305.html)



Generating all simple sentence possibilities - Max_77 - Oct-09-2018

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!


RE: Generating all simple sentence possibilities - ichabod801 - Oct-09-2018

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.


RE: Generating all simple sentence possibilities - Larz60+ - Oct-09-2018

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.


RE: Generating all simple sentence possibilities - Max_77 - Oct-10-2018

-Thanks for the replies everyone!