Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- use LWP::Simple;
- use XML::XPath;
- use Data::Dumper;
- use constant NOMRAL_DISPLAY => "\e[0;0m";
- #use constant NOMRAL_DISPLAY => "_";
- use constant UNDERLINE => "\e[0;4m";
- #use constant UNDERLINE => "_";
- use constant HOSTNAME => "http://services.aonaware.com";
- use constant DICTIONARY => "gcide";
- use constant STRATEGY => "lev";
- use constant DEFINE_URL =>
- HOSTNAME . "/DictService/DictService.asmx/DefineInDict?dictId=" . DICTIONARY . "&word=";
- use constant SEARCH_URL_1 => HOSTNAME ."/DictService/DictService.asmx/MatchInDict?dictId=" . DICTIONARY . "&word=";
- use constant SEARCH_URL_2 => "&strategy=" . STRATEGY;
- if ($#ARGV == -1) {
- print STDERR "No command line args specified\n";
- exit 1;
- }
- foreach my $argNum (0 .. $#ARGV) {
- my $rawXml = get(DEFINE_URL . $ARGV[$argNum]);
- my $xp = XML::XPath->new(xml => $rawXml);
- my $data = $xp->find('//Definition/WordDefinition');
- if ($data->size == 0) {
- print "No Matches for $ARGV[0]\n";
- $rawXml = get(SEARCH_URL_1 . $ARGV[$argNum] . SEARCH_URL_2);
- $xp = XML::XPath->new(xml => $rawXml);
- $data = $xp->find('//DictionaryWord/Word');
- if ($data->size > 0) {
- print "Did you mean: -\n";
- for my $def ($data->get_nodelist) {
- print $def->string_value . "\n";
- }
- }
- } else {
- my $count = 1;
- for my $def ($data->get_nodelist) {
- print UNDERLINE . $ARGV[$argNum] . " DEFINITION $count" . NOMRAL_DISPLAY . "\n";
- print $def->string_value . "\n";
- $count++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement