Write program that is capable of generating a set words

Assignment Help Python Programming
Reference no: EM131230415

You will write a Python program that is capable of generating a likely set of completion words given the start of a word as input to the program.

You have all experienced how when you are typing a text message the application will provide potential words that complete what you are typing (and sometimes insist on completing them incorrectly). You will write a Python program that is capable of generating a likely set of completion words given the start of a word as input to the program.

In order to be able to make these suggestions, your program will first need to analyze a large amount of text (like a book) to get an idea of what words occur how often in regular text. Once this analysis is made, then it will be possible to do a quick lookup into a data structure described below to generate the potential words.

Step 1 - Text file analysis

Ask the user for the name of a file that contains the text to analyze. Open the file and read the lines of text. Break each line into words, stripping out all of the special symbols. For each word that you find that is longer than one character, do the following. First, add the word to a dictionary of words you have seen so far. The values in this dictionary should be a count of how many times each word has occurred in the text file. Second, add the word into a data structure that is keeping track of word information for the completion process. This data structure has 3 basic parts. The top level part is a list that will have as many elements in it as the number of characters in the longest word seen so far. Each element in this list will be a dictionary which is indexed by the 26 letters of the alphabet. The value for each entry in the dictionary will be a set of words. A word is added into this structure as follows. The word is first added to the set contained in the dictionary corresponding to slot 0 in the list, indexed by the key of the first letter in the word. Then, the second letter of the word is used to index into the dictionary corresponding to slot 1 in the list to add the word to that set. This continues for the remaining letters in the word. So this means that the word "help" would be added to the set of words that have an h as their first letter, the set having e as the second letter, the set for l as the third letter, and then p as the fourth letter.

Step 2 - Word completion

With these two structures of information constructed based on the input file, it is time to do word completion. Within a loop that can continue as long as the user wants, ask to read the starting portion of a word. You then must determine the set of all possible words you have seen that begin with this string of characters. This set of words can be computed by intersecting a group of sets extracted from the data structure. These sets are found by indexing into the dictionary corresponding to the character value of each position in the string. You can intersect all of these sets together two at a time to get your result. So if the string "he" was typed in, you would intersect the set of words that have h as their first letter with the set of words that have e as their second letter. This gives the set of words that start with "he".

Next you must rank the possible set of words based on how often they were found in the text, assuming that words that occur often are more likely to occur again. For each word in the final set of possibilities, extract the occurrence count from the other dictionary you constructed. Then sort the words based on these values. Print out the top five candidate words (or fewer if less than five exist) with a percentage of how likely each word is the proper completion of the string given. To compute percentages, first total up all of the occurrences of the words in the set, then divide the count for each by this amount.

Submission

Submit your commented source code. Acquire a few large text files to test your program. Plain text files of books are a good suggestion, like the War & Peace file we used in class. Things like Project Gutenberg are a good source for these. Submit some sample output from your program using one of these files.

Reference no: EM131230415

Questions Cloud

How do you go about making this decision : The expansion could be open a new restaurant, add an addition to your medical office, merge with another business, purchase a competitor, or relocate to an area where the market fits your business service. It can be any other scenario that would b..
Write cpp program that will allow a user to manage inventory : Write a C++ program that will allow a user to manage the inventory of a store. The inventory for a small electronics store for example will contain the information for each item in the inventory.
What changes did kmart make to its store in chicago : What marketing research methods would you recommend to a retailer like Kmart to learn more about the consumer shopping experience in its stores and to better understand what consumers think about Kmart?
Identify two barriers that influence your critical thinking : Identify two barriers that influence your critical thinking from the list of barriers in Thinking: - An Interdisciplinary Approach to Critical and Creative.
Write program that is capable of generating a set words : You will write a Python program that is capable of generating a likely set of completion words given the start of a word as input to the program.
Find one additional fact that relevant to berkeley college : Find one additional fact that is relevant to Berkeley College. This can be anything of your choosing. Be sure to provide a complete citation for your fact, so that I can access the original source material. Explain why and how it is useful inform..
Describes differences between data warehouse and data mart : Find a video, an image, or a slide deck (no articles) that describes the differences between a data warehouse data model and a data mart data model. Share this with your classmates.
What gives them the competitive advantage : Individual Assignment - HI5019 STRATEGIC INFORMATION SYSTEMS T2 2016 - identify the leaders in the market and what gives them the competitive advantage. Students are also required to identify the current gaps or challenges encountered by users or ..
Reflect on electronic marketing techniques : Reflect on electronic marketing techniques you have seen in practice. Explain how you, as a healthcare administrator in charge of a marketing campaign, might incorporate internet marketing and/or social media into the campaign.

Reviews

Write a Review

Python Programming Questions & Answers

  Ida to reverse engineer a piece of shellcode

You are a Malware Investigator at 0xC0ff33, Inc and an incident responder came across injected shellcode during an investigation. He has done all he can in IDA and has passed on the .idb file to you. Figure out what the purpose of the malware was ..

  Design a prgram using python

Design a prgram USING PYTHON that students can use to calculate what score they need on final exam to get a certan final grade for a course.

  How catch market trends

How catch market trends? Crossing n1­days moving average (MA) and n2­days moving average (n1>n2). When n2­days MA crosses n1­days MA, it is an indicator for the start of upward trend, and the other way around for downward trend

  Aussie best car abcdeclares that based on its yearly sales

aussie best car abcdeclares that based on its yearly sales it will award a bonus as follows. the bonus will be equally

  Create functions to simplify your code

Create functions to simplify your code. If you find yourself writing the same code over and over again, it should probably be made into a function.

  Which stores and manipulates times on a 24 hour clock.

Complete the class Time, which stores and manipulates times on a 24 hour clock. As specified below, write the required methods, including those needed for overloading operators. Exceptions messages should include the class and method names, and ident..

  Implement key exchange using the diffie-hellman algorithm

Implement key exchange using the Diffie-Hellman algorithm, when peer- to-peer connections are made between bots and achieve confidentiality through encryption of the client-server commu- nications with an appropriate block or stream cipher.

  Output the starting position and length

X Strings: Input a string. Output the starting position and length of the first occurrence of the longest substring of capital Xs in that string. The first letter is in position 1.

  In this assignment you will write a program that does

in this assignment you will write a program that does simple packet routing. your program will take three command-line

  Assume that the variables gpa , deanslist and studentname

Assume that the variables gpa , deansList and studentName , have been initialized. Write a statement that adds 1 to deansList and prints studentName to standard out if gpa exceeds 3.5.

  Question 1 research 5-8 species within one family of birds

question 1 research 5-8 species within one family of birds. be sure to use primary or very good secondary literature

  How do you prevent replay attacks

What was your choice of cipher? What mode of operation does it use? Why did you make these choices? How do you prevent attackers from tampering with messages in transit? How do you prevent replay attacks

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd