[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Hello all.



Okay, here's a paste of the "define" feature... I was using version 0.44.3
and this was in the myRoutines.pl file:

use Net::Dict;
        } elsif ($message =~ /^[Dd]efine (\S+)/) {
            my $definition = "$1";
            my($dict) = Net::Dict->new("dict.org");
            my ($h) = $dict->define($1);
            my ($i, $def, $dict);
            my $ty = "int";
            my $nit = "1";
            my (%mydef);
            my (@jout);
            my $gotadef=0;
            foreach $i (@{$h}) {
              ($dict, $def) = @{$i};
              if ($dict eq "wn") {
                $gotadef=1;
                foreach (split(/[\r\n]+/, $def)) {
                  next if (/^$definition/);
                  if (/^     (\w ){0,3}(\d+): /) {
                    $ty=$1 if (defined $1);
                    $nit=$2;
                  }
                  (s/^\s+//g);
                  (s/\s+$//g);
                  $mydef{$ty}[$nit].=$_." ";
                  $mydef{$ty}[0]=$nit;
                }
              }
            }
            my ($curline);
            foreach $ty (keys %mydef) {
              if ($ty eq "int") {
                push(@jout, "$definition: $mydef{$ty}[1]");
                next;
              }
              if (defined $curline) {
                push(@jout, "$curline");
                undef($curline);
              }
              for (1..$mydef{$ty}[0]) {
                if (defined $curline) {
                  if (((length($mydef{$ty}[$_]))+(length($curline))) >
480) {
                    push (@jout, "$curline");
                    $curline=$mydef{$ty}[$_];
                  } else {
                    $curline.=" ".$mydef{$ty}[$_];
                  }
                } else {
                  $curline=$mydef{$ty}[$_];
                }
              }
            }
            push (@jout, "$curline");
            if ($gotadef) {
                if ($msgType eq 'public') {
                    for (0..($#jout-1)) {
                        &say($jout[$_]);
                        sleep 2;
                    }
                    &say($jout[$#jout]);
                } else {
                    for (0..($#jout-1)) {
                        &msg($who, $jout[$_]);
                                sleep 2;
                            }
                            &msg($who, $jout[$#jout]);
                        }
                    } else {
                        if ($msgType eq 'public') {
                            &say("$definition: Not in my listing");
                        } else {
                            &msg($who, "No definition found for
$definition");
                        }
                    }
                    return 'NOREPLY';
                }
            }

Most of that code is purely for the formatting of the response, which can
only be done with fat code if you look at how Net::Dict returns stuff.

Scott - critique away, this is the product of another insomnia-inspired
hack... 

Possible additions:  a Thesoraus (sp?) would be cool, but I haven't looked
into it.  Another thing would be to make this a function and pass the "wn"
(wordnet listing) to it, that way folks could request stuff like the
"jargon" listing or the webster's 1913 definition....

Cool things about this: It will split off noun/verb etc into different
responses, and shove as much as irc will allow (~480 max msg len) into a
response.

On Wed, 24 Nov 1999 duff@cbi.tamucc.edu wrote:

> On Wed, Nov 24, 1999 at 05:26:35AM -0600, Jay Jacobs wrote:
> > Dictionary:
> >   Uses the Net::Dict package and does realtime definitions for words:
> 
> Damn you!  I was going to do that!  (As my one and probably only
> contribution to the infobot source)  
> 
> :-)
> 
> Oh well, I'll just critique your implementation when you're done ;-)
> 
> -Scott
> -- 
> Jonathan Scott Duff
> duff@cbi.tamucc.edu
>