Question: Use C++. In this program you will create an artificial intelligence that is designed to copy the styles of famous authors and write a sentence
Use C++.
In this program you will create an artificial intelligence that is designed to copy the styles of famous authors and write a sentence in that style based upon the provided data sample. Imagine taking a book (say, Tom Sawyer or Moby Dick) and determining the probability with which each character occurs. You'd probably find that spaces are the most common, that the character 'e' is fairly common, and that the character 'q' is rather uncommon. After completing this level 0 analysis, you'd be able to produce random Tom Sawyer text based on character probabilities. It wouldn't have much in common with the real thing, but at least the characters would tend to occur in the proper proportion. In fact, here's an example of what you might produce: Level 0 rla bsht eS ststofo hhfosdsdewno oe wee h .mr ae irii ela iad o r te u t mnyto onmalysnce, ifu en c fDwn oee iteo Now imagine doing a slightly more sophisticated level 1 analysis by determining the probability with which each character follows every other character. You would probably discover that 'h' follows 't' more frequently than 'x' does, and you would probably discover that a space follows '.' more frequently that ',' does. You could now produce some randomly generated Tom Sawyer by picking a character to begin with and then always choosing the next character based on the previous one and the probabilities revealed by the analysis. Here's an example: Level 1 "Shand tucthiney m?" le ollds mind Theybooure He, he s whit Pereg lenigabo Jodind alllld ashanthe ainofevids tre lin--p asto oun theanthadomoere Now imagine doing a level k analysis by determining the probability with which each character follows every possible sequence of characters of length k. A level 5 analysis of Tom Sawyer for example, would reveal that 'r' follows ''Sawye'' more frequently than any other character. After a level k analysis, you'd be able to produce random Tom Sawyer by always choosing the next character based on the previous k characters (the seed) and the probabilities revealed by the analysis. At only a moderate level of analysis (say, levels 5--7), the randomly generated text begins to take on many of the characteristics of the source text. It probably won't make complete sense, but you'll be able to tell that it was derived from Tom Sawyer as opposed to, say, The Sound and the Fury. Here are some more examples: Level 2 "Yess been." for gothin, Tome oso; ing, in to weliss of an'te cle -- armit. Papper a comeasione, and smomenty, fropeck hinticer, sid, a was Tom, be suck tied. He sis tred a youck to themen Level 4 en themself, Mr. Welshman, but him awoke, the balmy shore. I'll give him that he couple overy because in the slated snufflindeed structure's kind was rath. She said that the wound the door a fever eyes that WITH him. Level 6 people had eaten, leaving. Come -- didn't stand it better judgment; His hands and bury it again, tramped herself! She'd never would be. He found her spite of anything the one was a prime feature sunset, and hit upon that of the forever.
For this program you have the flexibility to implement your AI in any form that you want. However, listed below are some methods / algorithms that might be useful.
CLASS WORDPAIR ()
You may want to consider a class that keeps track of two pieces of data. A string for a patter that you have found, and a single character that would follow them. For example if you are doing a level two search, you might have "th" matched with 'e' because those letters will often be followed by 'e'. Similarly for a level 5 search the string "ecaus" might be followed by 'e' for similar reasons. If you create this class, you may also want to implement a < operator for use in the STL's and a << operator for easy readability.
MULTISET CREATELIST(INT DEPTHTOLOOK)
Read though the file and create a multiset of all possible word strings and the corresponding following letter, using the provided depth from the main program. Note that this method returns the multiset. So open the file and then build it one wordpair at a time.
STRING MAKESENTENCE(MULTISET FROMME, INT DEPTH)
This method could be used to take the finished set of pairs, the necessary distance, and use the two to complete the sentence by taking data from the multiset and smooshing it together.
WORDPAIR CHOSERANDOMFROMMULTISET(MULTISET FROMME)
In the course of you work, you may want to build a smaller multiset from the larger multiset to find all the pairs of a particular pattern. However since you can't randomly access a multiset, you will need to build a custom method to randomly pick from the set. CHAR ISGOOD(CHAR X) You will want to ignore characters from the file that you can't see/print. You may want a method that finds all the useful characters and turns everything else into some character that you can then ignore in the main method. { if (isprint(x) ) return x; if (iscntrl(x) ) return ' '; return '~' ; }
STRING GRABLAST(STRING X ,INT DEPTHTOLOOK)
You may want a function to only look at the last couple of character of your string to compare them to the list of possibilities.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
