Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
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";
  } 
}

Replies are listed 'Best First'.
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
Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://10239]
help
Chatterbox?
[TCLion]: Good Morning Monks, I am parsing logs and some date time formats are inconsistent. I am trying to make output all same format. What is the best way to convert a month(word) to month(number)?
[Corion]: TCLion: I'm not aware of a better way than manually building the hash, as all strptime incarnations I know have nasty edge cases

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (15)
As of 2017-03-23 14:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (287 votes). Check out past polls.