How when you are typing a text message

Assignment Help Python Programming
Reference no: EM131232453

Python programming

The assignment instruction is:

"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: EM131232453

Questions Cloud

National league of professional baseball clubs history : Explain the National League of Professional Baseball Clubs history.
What the college lacks and what you cold argue it needs : Explore around a college campus in order to figure out what the college lacks and what you cold argue it needs.- Then you will need to propose a solution as to how the change should occur.
Develop full plc ladder logic for the logic solver : INSTRUMENTATION AND CONTROL ETEN4001 - Develop full PLC ladder logic for the logic solver to implement your SIS design based on the fault tolerance and redundancy levels chosen.
What image or images appeal to your senses of sight : Analyze the symbolism, the physical images or objects that represent abstract ideas or emotions, and imagery, mental pictures created by words, to determine a pattern of images and ideas.
How when you are typing a text message : 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).
An excerpt from an article : Where do you think the practice of using the same format, even the same language, for business documents might have come from?
Weaknesses of the various approaches : Discuss making a decision using Baye'sdecision rule (probabilities) for "the maximax approach", "the maximin approach", the "maximum likelihood approach" and how it can be used/applied to your personal life and also in professional situations. Pl..
Satisficing rather than optimizing : The text asserts that managers generally choose the first solution that satisfies minimal decision criteria, i.e. they engage in satisficing rather than optimizing. Do you agree? Can you provide examples that would support this or challenge it?
Example of a task in function : Describe the functions carried out by healthcare managers, and give an example of a task in each function.

Reviews

Write a Review

Python Programming Questions & Answers

  Demonstrates the benefits of well-designed data abstraction

Demonstrates the benefits of well-designed data abstraction and modularity in that most methods and functions need no modification or consideration at all, but continue to do their jobs flawlessly and abstractly.

  Tower of hanoi game

Tower of Hanoi game that you can let a player to move discs between the towers using a mouse - Each move consists of taking the upper disk from one of the pegs and sliding it onto another rod, on top of the other disks that may already be present o..

  Determines number of occurrences of a given letter in string

In this last checkpoint, you will write a new program that determines the number of occurrences of a given letter in a string. To do so, you are only allowed to use the replace() and len() functions.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Two-dimensional word puzzle

Write a python function called find_words that finds and prints the list of valid words in a two-dimensional word puzzle

  Interaction between the customer and the machine

In Python:Simulate a cash register or ATM including the interaction between the customer and the machine (i.e. assume that you are automating the responses)

  Find the output of the given script in python

Find the output of the following script in Python. Note: All statements are valid. Rewrite the following for loop Python statements using while loop.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

  Evaluate quality of the random number generator in python

This program is going to evaluate the quality of the random number generator in Python by simulating dice rolls and looking at the distributions of the values.

  Provide the code for a boolean-valued function

Provide the code for a Boolean-valued function perfect(n)that calculates and returns the Boolean value True or False according to whether the value of the parameter n is a perfect number or not, respectively

  How many of each package should be made to minimize cost

Each Bronze package has 1 pen, each Silver package has 5 pens, and each Gold package has 2 pens. How many of each package should be made to minimize their cost? What is the minimum cost?

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