Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

webster client

by gregorovius (Friar)
on May 04, 2000 at 21:07 UTC ( #10239=sourcecode: print w/ replies, xml ) Need Help??

Category: web robots
Author/Contact Info Claudio Garcia
claudio.garcia@stanfordalumni.org
Description: This is a simple web client that will bring a word definition from the UCSD web dictionary into your X terminal.

If people are interested I also have a server-simpler client version that allows this program to be deployed on a large number of machines without having to install the LWP and HTML packages it uses on each of them.
Usage: % webster_client word
#!/usr/bin/perl -w

use HTML::TreeBuilder;
use HTML::FormatText;
use LWP::UserAgent;

my $ua = new LWP::UserAgent;
$ua->agent("Dictionary");

#
# Uncomment if behind a firewall
#
#$ua->proxy([ 'http' ], 'http://www-dms.esd.sgi.com:8080/');

#
# Create a new request.
#
my $req = new HTTP::Request GET => "http://work.ucsd.edu:5141/cgi-bin/
+http_webster?isindex=$ARGV[0]&method=exact";

#
# Pass Request to the user agent and get a response back.
#
my $res = $ua->request($req);

#
# Print outcome of the response.
#
if(! $res->is_success) {
  print "Failure to connect to server: " . $res->message;
} else {
  my $html = $res->content;
  my $p = HTML::TreeBuilder->new;
  $p->parse($html);
  my $formatter = HTML::FormatText->new(leftmargin => 0, rightmargin =
+> 60);
  my $result = $formatter->format($p);
  
  my @paragraphs = split /^\s+/m, $result;

  #
  # Print only the paragraphs where the word definition is
  #
  for(my $x=2; !($paragraphs[$x] =~ /^From WordNet/) and $x < 10; $x++
+) {
    print $paragraphs[$x]."\n";
  } 
}

Comment on webster client
Download Code
RE: webster client
by Anonymous Monk on May 17, 2000 at 10:59 UTC
    This looks great! One question though, would it be possible to modify this for a foreign language dictonary? I'd love to be able to type check dog and have it give me from an online german dictonary der Hund, -e
      Sure! I have a Spanish-English version already. If you point me to an on-line english-german dictionary I'll make it work with it.(or you may do it yourself and post the new version back)
        A german-english dictionary is avaible at dict.leo.org
        This is the german dictionary I prefer. Providing as much information on the word as possible would be the most useful, such as article, the plural form, etc etc. I'll take a look at it myself and post my results, but I'd love to see your spanish port.
        http://www.quickdic.de/e_dic.html

Back to Code Catacombs

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://10239]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (16)
As of 2014-09-30 17:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (378 votes), past polls