Class 22 — Wednesday October 14
It's a fact, look it up
Really need to know — What lies farther down the road — Need a future map
Look both ways
Agenda
- hacer 뭔가 frais oggi
- Get ready to move on
Updated 10/14/2020
- Module url.py
Examples
- Program que_dijiste.py (need to redownload)
- Problem what_did_you_say.py
- Problem spell_rite.py
To do
- Look over artifacts
- Do homework
- Submit program
spell_rite.py
today
Huh?
- 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
Babelfish — a translation dictionary in CSV format
a, a
aab, water
aamadam, came
aamadand, came
aamad, came
aamadi, came
aamadid, came
aamadim, came
aanhaa, they
aan, it
aashpaz-khaaneh, kitchen
abajo, down
...
zauberformel, spell
zauberhaft, enchanting
zehn, ten
zeichen, characters
zeigt, show
ziba, beautiful
zur, to
zu, to
zwei, two
Problem que_dijiste.py
- Reads and prints the babelfish web file as a translation dictionary
Program run
{'aab': 'water', 'aamadam': 'came', 'aamadand': 'came', 'aamad': 'came', 'aamadi': 'came',
...
'wollen': 'want', 'wort': 'word', 'wo': 'where', 'y': 'and', 'yo': 'I', 'Yo': 'I', 'yun': 'wool', 'yün': 'wool', 'zahl': 'number', 'zauberformel': 'spell', 'zauberhaft': 'enchanting', 'zehn': 'ten', 'zeichen': 'characters', 'zeigt': 'show', 'ziba': 'beautiful', 'zur': 'to', 'zu': 'to', 'zwei': 'two', '是': 'is', '该': 'the'}
Problem text translation using babelfish dictionary
Goal
- Produce a program using translate text to English.
Some possible interactions
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 er den skriget maleri af Munch
where is the scream painting by Münch
Enter phrase to be translated: hacer 뭔가 frais oggi
do something cool today
Brainstorming
- How should we store the translations?
- How should we store the input?
- How should we store the result?
- What types of loops do we need?
Discussion and requirements
- 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.
- If a word to be translated is not in the translation dictionary, then its translation is that word surrounded by question marks.
- For example, French word
heureuse
for happiness is not in the babelfish dictionary, so it would be translated as?heureuse?
.
- 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.
- Every user word contributes to the translation.
- If a word is known to the babelish dictionary, its translation is added to the accumulation.
- If instead a word is unknown, the word surrounded by question marks is added to the accumulation.
Spell correction — program spell_rite.py
Web resources
- most-common — list of most commonly used words
- corrections — list of most common misspellings and their likely correction
Goal
- Produce a spell-checked version of user text that echos the user text word by word, unless a word is not known to be spelled correctly
- If a correction is known, the correction is offered within asterisks
- If insteadn no correction is known, the word is flagged with quotation marks
Some possible program interactions
Enter text: I am as happy as I can be
I am as happy as I can be
Enter text: I am a Newyorker who is livin in virginia
I am a *New Yorker* who is ?livin? in *Virginia*
Enter text:
Brain storming
- 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.
Babelfish — Hitchhiker's Guide to the Galaxy
Ziggurat of Ur
© 2020 Jim Cohoon | Resources from previous semesters are available. |