You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

169 lines
7.1 KiB

From: gherman at (Dinu C. Gherman)
Date: Thu, 22 Apr 1999 11:52:33 GMT
Subject: Project for newbie
References: <70alf7.qc6.ln@loopback>
Message-ID: <7fn2i0$7ql$>
Content-Length: 7024
X-UID: 114
In article <70alf7.qc6.ln at loopback>, morph at wrote:
> I've read my way through the tutorial, and am now stuck - where do I go
> from here? I want to learn how to use Python, but don't have any
> pressing projects at the moment - can anyone suggest a program I should
> have a go at writing, to help me learn the language further?
What about this little problem, assuming you're
interested in internet programming and keen to get
familiar with the Python XML module...? ;-)
Have fun,
The Altavista babelfish returns the following result
page (see appendix below) after issuing this request:
"translate 'water' from English to French"
on that WWW page:
Some quick testing reveales that you can do the same
with just typing the following (wrapped) URL in your
Exercise 1:
Write a program calling the Altavista
Babelfish over the WWW (using httplib, say) and parse
its HTML output using your favorite HTML/XML parser
(suggestion: use the XML module written by the Python
XML-SIG) in order to extract the result and print it
nicely in a terminal window like this:
darwin> python water en_fr
Exercise 2:
Improve your program by allowing multiple words to
be translated in a row, like this (you'll have to
send multiple requests as Babelfish will try to
treat your words as a sentence):
darwin> python spam eggs en_fr
Appendix: Sample Babelfish output
(see context description)
<html> <head><title>AltaVista: Translations</title> </head> <body
bgcolor=#ffffff text=#000000 link=#003399 vlink=#663366 alink=#ff0000> <MAP
NAME=header> <AREA SHAPE=RECT COORDS="144,0,323,32"
HREF="" ALT="AltaVista
Maps"> <AREA SHAPE=RECT COORDS="0,0,128,32"
HREF="" alt="AltaVista Home"> </MAP>
<center><table width=600 border=0 cellspacing=0 cellpadding=0> <tr><td> <img
src=/gifs/new.babelfish_head.gif border=0 NAME="AltaVista Translation"
WIDTH=383 HEIGHT=32 USEMAP=#header ALT="AltaVista Translation"></td><td
align=right valign=bottom> <font face=arial,helvetica size=-1> <a
href="/content/help.htm">Help</a> - <a
href=>AltaVista Home</a></font>
</td></tr> <tr><td colspan=2 BGCOLOR=#003399><img
src= border=0 width=0
height=2></td></tr> </table> <table border=0 width=600 cellspacing=0
cellpadding=2><tr><td><table width=100% bgcolor=#ffffff cellpadding=5
cellspacing=0 border=0> <tr><td align=center valign=center><ilayer id=ad1
visibility=hidden height=83></ilayer> <nolayer><iframe
width=500 height=83 marginwidth=0 marginheight=0 hspace=0 vspace=0
frameborder=0 scrolling=no bordercolor="#000000"><A
alt="Click Here"><img
src="" width=468
height=60 border=0 ismap><br><font size=-1 face=Arial,Helvetica><b>Click
<table border=0 cellspacing=0 cellpadding=0 width=600 BGCOLOR=#FFCC66>
<TR><td width=2><br></td><td><table border=0 cellspacing=0 cellpadding=4
width=596 BGCOLOR=WHITE>
<tr><td colspan=2 align=left BGCOLOR=#FFCC66><b>
<font face="arial, helvetica">En Fran?ais:</b></font>
<tr><td><img border=0 src="/gifs/clear.gif" width="15" height="0"></td>
<td align="left"><br>
<font face="arial, helvetica">l'eau
<tr><td align=right colspan=2>
<font face="arial, helvetica" size=-1><a
<font size=-1>Use the above text to search the
width=2><br></td></tr></table><table border=0 cellpadding=0 cellspacing=0
width=600 bgcolor=#ffcc66><tr><td align=center><table border=0 cellpadding=4
cellspacing=0 width="100" bgcolor=#ffcc66><form action="/cgi-bin/translate?"
<input type="hidden" name="doit" value="done">
<tr><td align=left valign=bottom><font size="-1" face="arial,
helvetica"><b>To translate, type <a href="/content/help.htm#trans_text">plain
text</a> or the <a href="/content/help.htm#trans_web">address (URL)</a> of a
Web page here:</b></font></td></tr> <tr><td align=left><textarea rows="6"
wrap=virtual cols="56" name="urltext">water</textarea></td></tr> <tr><td
align=left valign=top> <font size="-1" face="arial, helvetica"><B>Translate
from: <select name="lp"> <option value="en_fr" SELECTED>English to
French</option> <option value="en_de" >English to German</option> <option
value="en_it" >English to Italian</option> <option value="en_pt" >English
to Portuguese</option> <option value="en_es" >English to Spanish</option>
<option value="fr_en" >French to English</option> <option value="de_en"
>German to English</option> <option value="it_en" >Italian to
English</option> <option value="es_en" >Spanish to English</option> <option
value="pt_en" >Portuguese to English</option> </select> <input type="Submit"
value="Translate"></b></font> </td></tr></form></table> </td></tr></table>
<table width=600 cellpadding=0 cellspacing=0 border=0> <tr
bgcolor="#ffcc66"><td align=center><font size=-1 face="arial,helvetica"><br>
Put the power of Babel Fish into IE 5. <b><a
href="">Get AV Power Tools<b>
(119k)</a><p> <b><a href="">Download
SYSTRAN Personal</a> and translate your private documents in
seconds.</font></b><br><br></td></tr> <tr><td bgcolor=#003399 width=100%><img
src="" border=0 width=0
height=2></td></tr> </table> <table width=600 border=0 cellspacing=0
cellpadding=4> <tr><td width=440 align=left><font size=-2
face="arial,helvetica"> <a
href="">AltaVista Home</a> | <a
href="/content/help.htm">Help</a> | <a
href="/content/feedback.htm">Feedback</a> <BR> &copy;1995-98 | <a
href="">Disclaimer</a> | <a
href="">Privacy</a> | <a
href="">Advertising Info</a></font></td>
<td valign=middle align=right width=160> <a
href=""><IMG SRC="/gifs/systran_big_logo.gif"
WIDTH="138" HEIGHT="39" BORDER="0"></a> </td></tr></table> </center> <layer
visibility=hidden id=a1 width=590
a1.clip.height=83;visibility='show';"></layer> </BODY></HTML>
-----------== Posted via Deja News, The Discussion Network ==---------- Search, Read, Discuss, or Start Your Own