As society moves to smart phones like the iPhone and Palm Pre with software Qwerty keyboards, this interesting piece of computer science will become a forgotten artifact, but the lessons of predictive text will still be applicable when faces with similar limitations.
Number | Letters |
---|---|
1 | |
2 | ABC |
3 | DEF |
4 | GHI |
5 | JKL |
6 | MNO |
7 | PQRS |
8 | TUV |
9 | WXYZ |
Write a function called text_to_nums(text)
which will translate a given string of
text into the numbers which should be pressed on the keypad to create this text. You should use a
dictionary with the letters as keys and the numbers as values. Be sure to remove all punctuation
from the text, capitalize all the incoming text, and translate the space character as "*".
A textonym is a word that is composed of the same underlying numeric key. For example, "cool" is mapped to 2665, which is also the same number for "book".
To automatically make a choice between these two words we need some more information. Predictive text algorithms use the relative likelihood of the words in the English language. We will be using statistics gathered from the British National Corpus, a 100 million word collection of samples of written and spoken language from a wide range of sources. We have a BNC word frequency list, with each line listing the word count followed by the word and some extra information on the part of speech.
Now, we can translate a number back into it's most likely word choice. Since "book" is more popular in this corpus than "cool", it will be the first word returned when typing in those numbers.
Write a function called nums_to_text(nums)
which will translate a given string of
numbers separated by "*" into the most likely words that created this string of numbers. Use a
dictionary with the numbers as keys and the most likely word as the value.
Use your function to translate the following numbers back into the most likely text.
textonyms(text)
to find all textonyms for a given word.
Use your function to find the textonyms of the following words:
nums_to_text
function above, such that all possible
text messages are printed out.
Write a function called predict_text()
to allow the user to enter numbers and create
a text message. This function will repeatedly ask the user for individual
numbers, and after each letter, will display the most likely word that starts with the sequence of
numbers entered. If the user hits enter without a number, add this most likely word to a
growing text message and start the next word from scratch. If the user hits enter without a
number twice in a row, print the written text message for the user and exit the function.
lab12_evaluation.txt
cs.centenary.edu
through either Secure FTP or WinSCP using your
cs login and password. Create a subdirectory from csc207
called lab12
. Copy your substitution.py
project into this directory. Make sure
you have followed the Python Style Guide, and
have run your project through the Automated Style Checker.You must hand in: