Class 23 — Friday March 27
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 3/22/2021
- Module url.py
Examples
- 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
...
ziba, beautiful
zur, to
zu, to
zwei, two
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 underscores (_).
- 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 underscores 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 instead no correction is known, the word is flagged with underscores.
-
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 underscores is added to the accumulation.
Here we go
- Question: Why bother with functions?
- Makes problem solving possible. Without them you would need to figure out
- How to communicate with your keyboard to read what it’s being typed
- How to communicate to your display so that information can be displayed
- How to specify the range of integers a
for
statement uses to loop.
- How to ...
- Question: What built-in functions are missing — how should Python be updated?
- The
url.py
module is an attempt by me to let you skip the tedious web processing setup to do something interesting
- One of your classmates asked whether there was some function
ints()
that would handle a string containing a bunch of integers.
- We will get to that likely in another three classes or so.
You are already experienced with functions and modules (e.g,, wc.py
)
- Used built-in functions
- Used string and list manipulating functions
- Imported standard modules and then made use of their functions
- Imported url.py and then made use of its functions
Babelfish — Hitchhiker's Guide to the Galaxy
Ziggurat of Ur
🦆 © 2022 Jim Cohoon | Resources from previous semesters are available. |