MOO-cows Mailing List Archive

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

[darkowl@darkowl.pr.mcs.net: Re: dictionary server? [LONG]]



------- Start of forwarded message -------
Return-Path: nop@ccs.neu.edu
Date: Tue, 11 Mar 1997 14:13:55 PST
From: Don Schwarz <darkowl@darkowl.pr.mcs.net>
Reply-To: Don Schwarz <darkowl@mcs.net>
To: Kimberly Bobrow <kbobrow@parc.xerox.com>
cc: MOO-COWS <moo-cows@parc.xerox.com>,
        Jacqueline Hamilton <kira@metronet.com>
Subject: Re: dictionary server? [LONG]
In-Reply-To: <199703111950.OAA20052@soho.ios.com>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
Sender: MOO-Cows-Errors@parc.xerox.com
Precedence: bulk
Resent-From: clue-cows <nop@nop.com>
Errors-To: clue-cows <nop@nop.com>

On Tue, 11 Mar 1997, Kimberly Bobrow wrote:

> On Tue, 11 Mar 1997 06:45:07 PST, Jacqueline Hamilton wrote:
> 
> >We've got scrabble on our MOO and had a "lookup" verb that would query the
> >dictionary server at citi.umich.edu 2627.  However that server seems to
> >have up and died, and I'm having a hard time finding any others.  Anyone
> >know of a non-web-based dictionary server I can point to?
>
> I have the same habit, and the same problem, and also haven't been
> able to find anything...the old one got 'upgraded' to a web version -
> bleah!
> 
> I moo-mailed with someone on Lambda who thought he might be writing
> something to strip the html off one of the web versions, and offerred
> to share it.
That would be me :)

The web gateway at http://gs213.sp.cs.cmu.edu/prog/webster, which used to be
using citi.umich.edu, came back online about a week after the umich server
closed down, so he must have found another websters server.  It's back down
again, though, so that one might have closed down also.  I ended up just
converting all my code to use www.m-w.com instead, but that site seems to be
very unstable.  I think it's been unreachable for at least a few hours every
day this week (like now, for example *sigh*).

> If he doesn't end up doing it before too long I'll
> probably do it myself, and I'll be happy to share.  If he does it,
> I'll ask if I (or he can, if he's on here - I don't know his real
> name) can post it here.
>
I'm not sure if I'd suggest switching to www.m-w.com right away, since it's
been so unstable recently, but here's some of my code just in case... it's
not very efficient but I was just trying to get it working as quickly as
possible.

<--- snip --->

#426:contact_mw   this none this
":contact_mw (STR line) => {STRs} result";
{line} = args;
if (`connection_name(this.current_connection) ! ANY')
  return E_MAXREC;
elseif (typeof(conn = $network:open(@this.mw_server)) != OBJ)
  return conn;
endif
this.current_connection = conn;
command = tostr("GET /cgi-bin/netdict?", strsub(line, " ", "%20"));
$network:notify(conn, command);
ptid = task_id();
fork tid (0)
  result = {};
  while (typeof(line = $network:read(conn)) == STR)
    result = {@result, line};
  endwhile
  if ($code_utils:task_valid(ptid))
    resume(ptid, result);
  else
    $network:close(conn);
  endif
endfork
if (this.current_connection == conn)
  this.current_connection = 0;
endif
if (r = suspend(this.server_timeout))
  $network:close(conn);
  return r;
else
  kill_task(tid);
  $network:close(conn);
  return E_MAXREC;
endif



#426:open_to_page   this none this
":open_to_page (STR page)";
{page} = args;

"[...local code snipped...]";

if (!(result = this:contact_mw(page)))
  return "That page seems to be blank.";
elseif (index(toliteral(result), "Main Entry:"))
  definition = {};
  started = E_NONE;
  for x in (result)
    if (started == 0 && !index(x, $string_utils.tab))
      started = 1;
    endif
    if (started)
      x = strsub(strsub(strsub(x, "&lt;", "<"), "&gt;", ">"), "&amp;", "&");
      if (i = index(x, "<center>"))
        if (i != 1)
          x[i..$] = "";
          while (m = match(x, "</?[abift][^>]*>"))
            if (x[m[1]..m[2]] == "<br>")
              definition = {@definition, x[1..m[1] - 1]};
              x[1..m[2]] = "";
            else
              x[m[1]..m[2]] = "";
            endif
          endwhile
          definition = {@definition, x};
        endif
        this.open = {page, this:prepare_page(definition)};
        return 1;
      elseif (!index(x, "<"))
        definition = {@definition, x};
      else
        while (m = match(x, "</?[abift][^>]*>"))
          if (x[m[1]..m[2]] == "<br>")
            definition = {@definition, x[1..m[1] - 1]};
            x[1..m[2]] = "";
          else
            x[m[1]..m[2]] = "";
          endif
        endwhile
        definition = {@definition, x};
      endif
    elseif (index(x, $string_utils.tab))
      started = 0;
    endif
  endfor
  return "Someone seems to have spilled coffee all over that page.";
else
  options = this:get_poss(result);
  if (!options)
    return tostr("\"", iobjstr, "\" was not in ", this:name(), ".");
  elseif (length(options) == 1)
    return tostr("\"", iobjstr, "\" was not in ", this:name(), ", maybe you meant ", substitute("%1", m), ".");
  else
    ret = {tostr("\"", iobjstr, "\" was not in ", this:name(), ", maybe you meant one of the following:")};
    if (length(options) > 60)
      length = tostr("...or one of the other ", $string_utils:group_number(length(options)), " words matched.");
      options = options[1..60];
    else
      length = "";
    endif
    noptions = extra = {};
    ll = player:linelen();
    for x in (options)
      if (length(x) > ll / 3)
        extra = {@extra, "  " + x};
      else
        noptions = {@noptions, "  " + x};
      endif
    endfor
    return {@ret, @$string_utils:columnize(noptions, 3, ll), @extra, length};
  endif
endif



#426:get_poss   this none this
{result} = args;
options = {};
for x in (result)
  if (index(x, "<option>") == 1)
    options = setadd(options, x[9..$]);
  endif
endfor
return options;
        


:prepare_page is just a verb that takes a list of strings as an argument and
moves the line breaks to make the text look a little better.
------- End of forwarded message -------


Home | Subject Index | Thread Index