SHARE
TWEET

Tarski

a guest Jun 16th, 2010 849 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5. use LWP::Simple;
  6. use XML::XPath;
  7. use Data::Dumper;
  8.  
  9. use constant NOMRAL_DISPLAY => "\e[0;0m";
  10. #use constant NOMRAL_DISPLAY => "_";
  11. use constant UNDERLINE => "\e[0;4m";
  12. #use constant UNDERLINE => "_";
  13. use constant HOSTNAME => "http://services.aonaware.com";
  14. use constant DICTIONARY => "gcide";
  15. use constant STRATEGY => "lev";
  16. use constant DEFINE_URL =>
  17.         HOSTNAME . "/DictService/DictService.asmx/DefineInDict?dictId=" . DICTIONARY . "&word=";
  18. use constant SEARCH_URL_1 => HOSTNAME ."/DictService/DictService.asmx/MatchInDict?dictId=" . DICTIONARY . "&word=";
  19. use constant SEARCH_URL_2 => "&strategy=" . STRATEGY;
  20.  
  21. if ($#ARGV == -1) {
  22.         print STDERR "No command line args specified\n";
  23.         exit 1;
  24. }
  25.  
  26. foreach my $argNum (0 .. $#ARGV) {
  27.         my $rawXml = get(DEFINE_URL . $ARGV[$argNum]);
  28.         my $xp = XML::XPath->new(xml => $rawXml);
  29.         my $data = $xp->find('//Definition/WordDefinition');
  30.         if ($data->size == 0) {
  31.         print "No Matches for $ARGV[0]\n";
  32.                 $rawXml = get(SEARCH_URL_1 . $ARGV[$argNum] . SEARCH_URL_2);
  33.                 $xp = XML::XPath->new(xml => $rawXml);
  34.                 $data = $xp->find('//DictionaryWord/Word');
  35.                 if ($data->size > 0) {
  36.                         print "Did you mean: -\n";
  37.                         for my $def ($data->get_nodelist) {
  38.                                 print $def->string_value . "\n";
  39.                         }
  40.                 }
  41.         } else {  
  42.                 my $count = 1;
  43.                 for my $def ($data->get_nodelist) {
  44.                 print UNDERLINE . $ARGV[$argNum] . " DEFINITION $count" . NOMRAL_DISPLAY . "\n";
  45.                 print $def->string_value . "\n";
  46.                 $count++;
  47.                 }
  48.         }
  49. }
RAW Paste Data
Top