Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This small project will use a dict data structure for a text algorithm with some whimsy to it. The program will be able to produce
This small project will use a dict data structure for a text algorithm with some whimsy to it. The program will be able to produce a random imitation of any source text.
Programming language - python
# --- Define your functions here --- def main(): args = sys.argv[1:) # Two possible command-line forms: # filename # filename limit_num minimum = 25 default minimum value pass if __name_ main() - '_main__': Mimic Output Here is some random text we get with this algorithm from the gettysburg address. It has a feverish quality, somehow echoing the words and tone of the original but without completely making sense. Four score and proper that these honored dead shall not consecrate -- we here have a great battle-field of that nation, under God, shall have died in a new birth of that field, as a great battle-field of devotion to the people, for us the living, rather, to the people, by the earth. Here we have the declaration of independence. You can see where it sort of gets stuck in a loop at times: When in the causes which impel them to assume among the causes which have connected them to which the Course of human events it becomes necessary for one people to the separation. We hold these truths to the Course of Nature's God entitle them, a decent respect to assume among these truths to be self-evident, that all men are endowed by their Creator with another and equal station to be self-evident, that all men are created equal, that they are endowed by their Creator with another and equal station to assume among these are endowed by their Creator with certain unalienable Rights, that they are created equal, that they should declare the pursuit of human events it becomes necessary for one people to the powers of Nature's God entitle them, a decent respect to the Laws of mankind requires that they should declare the pursuit of Nature and the Course of Happiness Aside: you are building what is known as a "Markov Model": imagine each word is a node with arrows leading out of it to each possible next word. The algorithm randomly chases through this network, picking a random arrow out of a node for each hop seven score and dedicated Bigrams Algorithm Given a text, we'll say the "bigrams" data records what words come immediately after other words in the text. For example the text: This and that and the other. Yields the bigrams: This' 'and' 'and' + 'that', 'the 'that' + 'and' 'the' + 'other.' In the text, 'This' is followed only by 'and', but 'and' is followed by both 'that' and thel Call the 2 words in the pair "previous" and "next". In terms of a data structure, the bigrams dict has a key in it for every previous word in the text (the last word in the text is not necessarily a previous word). The value of each key is a list of all the words that immediately follow previous in the text (duplicates are allowed in the list). As a one-off addition, the empty string" is treated as being previous to the very first word. So for example the text 'This and that and the other.' yields the following bigrams dict: "': ['This'], This': ['and'). and': ['that', 'the'], 'that': ['and' ], the': [ 'other.'], Here's a bit of the bigrams of the Gettysburg address: '': [ 'Four'). Four': ['score'), score': l'and' l. and seven dedicated' so proper dead text is not necessarily a previous word). The value of each key is a list of all the words that immediately follow previous in the text (duplicates are allowed in the list). As a one-off addition, the empty string " is treated as being previous to the very first word. So for example the text "This and that and the other.' yields the following bigrams dict: "': [ 'This'], This': ['and' ], 'and': ['that', 'the 'that': ['and' ], 'the': ['other.'], Here's a bit of the bigrams of the Gettysburg address: '': [ 'Four'), 'Four': ['score'), 'score': ['and'). 'and': ['seven', 'dedicated', 'so', 'proper', 'dead,', 'that'). 'seven': [ 'years'], The word 'Four' only has the word 'score' after it, but the word 'and' has many words which appear after it. Bigrams Output What is the bigrams data good for? The bigrams data enables an algorithm that chases through the words, creating a random text that resembles the original like this: 1. Start with the empty string" as the choice 2. Look up words that come after the choice in the bigrams 3. Select one of those words at random and print it followed by a space but no 'n 4. Go back to step 2 with the word just printed as the choice and repeat 5. If in step 2 the choice is not in the bigrams, use" instead which is always present # --- Define your functions here --- def main(): args = sys.argv[1:) # Two possible command-line forms: # filename # filename limit_num minimum = 25 default minimum value pass if __name_ main() - '_main__': Mimic Output Here is some random text we get with this algorithm from the gettysburg address. It has a feverish quality, somehow echoing the words and tone of the original but without completely making sense. Four score and proper that these honored dead shall not consecrate -- we here have a great battle-field of that nation, under God, shall have died in a new birth of that field, as a great battle-field of devotion to the people, for us the living, rather, to the people, by the earth. Here we have the declaration of independence. You can see where it sort of gets stuck in a loop at times: When in the causes which impel them to assume among the causes which have connected them to which the Course of human events it becomes necessary for one people to the separation. We hold these truths to the Course of Nature's God entitle them, a decent respect to assume among these truths to be self-evident, that all men are endowed by their Creator with another and equal station to be self-evident, that all men are created equal, that they are endowed by their Creator with another and equal station to assume among these are endowed by their Creator with certain unalienable Rights, that they are created equal, that they should declare the pursuit of human events it becomes necessary for one people to the powers of Nature's God entitle them, a decent respect to the Laws of mankind requires that they should declare the pursuit of Nature and the Course of Happiness Aside: you are building what is known as a "Markov Model": imagine each word is a node with arrows leading out of it to each possible next word. The algorithm randomly chases through this network, picking a random arrow out of a node for each hop seven score and dedicated Bigrams Algorithm Given a text, we'll say the "bigrams" data records what words come immediately after other words in the text. For example the text: This and that and the other. Yields the bigrams: This' 'and' 'and' + 'that', 'the 'that' + 'and' 'the' + 'other.' In the text, 'This' is followed only by 'and', but 'and' is followed by both 'that' and thel Call the 2 words in the pair "previous" and "next". In terms of a data structure, the bigrams dict has a key in it for every previous word in the text (the last word in the text is not necessarily a previous word). The value of each key is a list of all the words that immediately follow previous in the text (duplicates are allowed in the list). As a one-off addition, the empty string" is treated as being previous to the very first word. So for example the text 'This and that and the other.' yields the following bigrams dict: "': ['This'], This': ['and'). and': ['that', 'the'], 'that': ['and' ], the': [ 'other.'], Here's a bit of the bigrams of the Gettysburg address: '': [ 'Four'). Four': ['score'), score': l'and' l. and seven dedicated' so proper dead text is not necessarily a previous word). The value of each key is a list of all the words that immediately follow previous in the text (duplicates are allowed in the list). As a one-off addition, the empty string " is treated as being previous to the very first word. So for example the text "This and that and the other.' yields the following bigrams dict: "': [ 'This'], This': ['and' ], 'and': ['that', 'the 'that': ['and' ], 'the': ['other.'], Here's a bit of the bigrams of the Gettysburg address: '': [ 'Four'), 'Four': ['score'), 'score': ['and'). 'and': ['seven', 'dedicated', 'so', 'proper', 'dead,', 'that'). 'seven': [ 'years'], The word 'Four' only has the word 'score' after it, but the word 'and' has many words which appear after it. Bigrams Output What is the bigrams data good for? The bigrams data enables an algorithm that chases through the words, creating a random text that resembles the original like this: 1. Start with the empty string" as the choice 2. Look up words that come after the choice in the bigrams 3. Select one of those words at random and print it followed by a space but no 'n 4. Go back to step 2 with the word just printed as the choice and repeat 5. If in step 2 the choice is not in the bigrams, use" instead which is always present Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started