Class 22 — Wednesday October 18
It's a fact, look it up
Really need to know — What lies farther down the road — Need a future map
Look both ways
- hacer 뭔가 frais oggi
- Get ready to move on
- Module url.py
- Problem what_did_you_say.py
- Problem spell_rite.py
- Look over artifacts
- Do homework
- Submit program
- dónde está mi lápiz
- donde esta mi lapiz
- hvor 是 该 tumili maleri av Munch
- est la baguette fraîche aujourd'hui
- est la baguette fraiche aujourd'hui
- je %#@#&# ból svayam !!
Text translation — progam what_did_you_say.py
- The latest version of url.py has a function
get_dictionary( link )
- Returns the contents of the CSV-formatted page indicated by parameter
linkas a dictionary.
- The web file babelfish is a translation dictionary in CSV format.
- What we want to produce is a program using the above web resource that can translate text to English. For example, some possible interactions are:
Enter phrase to be translated: dónde está mi lápiz
where is my pencil
Enter phrase to be translated: est la baguette fraîche aujourd'hui
is the baguatte fresh today
Enter phrase to be translated: je %#@#&# ból svayam
I ?%#@#&#? hurt myself
Enter phrase to be translated: hvor 是 该 tumili maleri av Munch
where is the scream painting by Münch
- If a word to be translated is not in the translation dictionary, then its translation is that word surrounded by question marks. For example, the French word
heureusefor happiness is not in the babelfish dictionary, so it would be translated as
- The translation of the user text should be accumulated word by word. The translation should be displayed with a single
print()statement. Because the accumulation is a string, then the accumulator should be initilized to
- When accumulating the translation, make sure there is a space following each word in the translation.
- To produce the accumulation, each word in the user-supplied text needs to be processed one by one.
- Important data structures that the program needs to accomplish its task.
- List of words making up the user text;
- Dictionary loaded with the entries from the babelfish web file;
- Translation accumulation.
- Every user word contributes to the translation. If a word is known to the babelish dictionary, its translation is added to the accumulation. Otherwise, if a word is not known, the word surrounded by question marks is added to the accumulation.
Spell correction — program spell_rite.py
- Web resources
- List of most commonly used words
- List of most common misspellings and their likely correction
- Goal is to produce a spell-checked version of user text; that is echo the user text word by word, unless a word is not known to be spelled correctly. In that case, if a correction is known, the correction is offered within asterisks; and if no correction is known, the word is flagged with quotation marks. For example, some possible interactions are:
Enter text: I am as happy as I can be
I am as happy as I can be
Enter text: I am a Newyorker livin in Virginia
I am a *New Yorker* ?livin? in Virginia
- Problem has great similarity with text translation.
- If a word is spelled correctly, then it is added to the accumulation.
- If instead a word has an unknown spelling, then if it is known to the corrections dictionary then the correction surrounded by asterisks is added to the accumulation.
- Otherwise, if a word has an unknown spelling and is unknown to the corrections dictionary, then the word surrounded by quotation marks is added to the accumulation.