Thesaurus plugin

Posted by Nick Gammon on Thu 12 Oct 2006 11:11 PM — 7 posts, 40,296 views.

Australia Forum Administrator #0
Below is a simple plugin that lets you access a Thesaurus from MUSHclient.

You need to find the actual thesaurus yourself, I used one from this page:

http://www.dcs.shef.ac.uk/research/ilash/Moby/mthes.html

If you download the file 'mthes.tar.Z' (and unzip it with WinZip or similar) you will find two files inside it. The one used in the plugin is 'mobythes.aur', which the plugin expects to find in the same directory as the MUSHclient.exe program. You can modify the plugin if you want to put the thesaurus file somewhere else.

[EDIT]

That file may not work if it has "Mac" line endings. If you have trouble with it, try this file:

http://www.gammon.com.au/files/mushclient/mobythes.zip (8.8 Mb)


When the plugin is loaded it reads the entire thesaurus file, building up an "index" of where each word is in the file. This takes about a second.

After that, you can lookup any word by typing "lookup word".

Or, you can type "lookup" on its own to be prompted for the word.

If the word is found, a listbox is presented showing all the words found in the thesaurus matching that word. If you select one and click OK it will be copied to the clipboard.

In order for the plugin to be able to use the Lua io table to do the reading of the file, you have to mark the plugin as "trusted" in the Global Preferences -> Lua, like this:


  local trusted_plugins = {
     [""] = "",            -- trust main script (ie. if no plugin running)
     ["03ca99c4e98d2a3e6d655c7d"] = "Chat",  
     ["982581e59ab42844527eec80"] = "Random_Socials", 
     ["4a267cd69ba59b5ecefe42d8"] = "Installer_sumcheck",  
     ["83beba4e37b3d0e7f63cedbc"] = "Reconnecter",   
     ["fed86e24fd1ed8a47d97ecb6"] = "Thesaurus",  --> add this line
     }  -- end of trusted_plugins 


This is the plugin, copy between the lines and save it as Thesaurus.xml, then install that using the Plugin installer under the File menu:


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Friday, October 13, 2006, 8:55 AM -->
<!-- MuClient version 3.80 -->

<!-- Plugin "Thesaurus" generated by Plugin Wizard -->

<muclient>
<plugin
   name="Thesaurus"
   author="Nick Gammon"
   id="fed86e24fd1ed8a47d97ecb6"
   language="Lua"
   purpose="Lookup a word in a thesaurus"
   date_written="2006-10-13 08:54:06"
   requires="3.80"
   version="1.0"
   >
<description trim="y">
<![CDATA[
Type:

lookup

or

lookup <word>

eg. 

lookup eat
]]>
</description>

</plugin>


<!--  Aliases  -->

<aliases>
  <alias
   match="^lookup( (?P&lt;word&gt;.*)){0,1}$"
   enabled="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>-- find the word they want
local word = "%&lt;word&gt;"

if #word == 0 then
  word = utils.inputbox ("Word to lookup in Thesaurus?", "Thesaurus")
end -- word not supplied

-- nil if dialog cancelled
if not word then
  return
end -- cancelled dialog

-- see if in index
local pos = thes [word:lower ()]

-- don't know that word?
if not pos then
  utils.msgbox ("The word '" .. word .. "' is not in the Thesaurus", "Not Found")
  return
end -- not found

-- seek to it in the main file
thes_file:seek ("set", pos)

-- read that line
local line = thes_file:read ()

-- convert into table
local t = utils.split (line, ",")

-- display in list box
local choice = utils.listbox (
  "Matching words for '" .. word .. 
  "'\\n\\nClick OK to copy to the clipboard", -- message
  "Thesaurus: " .. word,  -- title
  t)  -- table of words

if choice then
  SetClipboard (t [choice])
end -- if one chosen
</send>
  </alias>
</aliases>

<!--  Plugin help  -->

<aliases>
  <alias
   script="OnHelp"
   match="Thesaurus:help"
   enabled="y"
  >
  </alias>
</aliases>

<script>
<![CDATA[

function OnPluginInstall ()
thes = {}
local name = GetInfo (66) .. "mobythes.aur"
thes_file = io.input (name)
repeat
  local pos = thes_file:seek ()  --> where we are
  local line = thes_file:read ()  --> read a line
  if line then
    local w = string.match (line, "[^,]+")
    thes [w:lower ()] = pos
  end -- of having a line
until not line 

ColourNote ("white", "blue", "Thesaurus loaded")

end -- OnPluginInstall 

function OnHelp ()
  world.Note (world.GetPluginInfo (world.GetPluginID (), 3))
end
]]>
</script> 

</muclient>
Amended on Mon 04 Jan 2010 11:31 PM by Nick Gammon
#1
I can't get the thesaurus plugin to work.

Every word I lookup gives the word is not in the thesaurus msgbox.

Here is how I'm installing the plugin:

C:\Program Files\MUSHclient\mobythes.aur
C:\Program Files\MUSHclient\worlds\plugins\Thesaurus.xml

File > Global Preferences > Lua

trust_all_worlds = true
trust_all_plugins = true

File > Plugins > Add > Thesaurus.xml (see "Thesaurus loaded" message)
Australia Forum Administrator #2
Yes I can reproduce that. It seems that the download of the words is now a Macintosh format file (with line-endings being only 0x0D). That means that when it reads the file in, it does not find any line endings (usually, 0x0A).

To save posting a lengthy work-around (it is easy if you have a suitable conversion program), I have fixed the line-endings and made a copy available here:

http://www.gammon.com.au/files/mushclient/mobythes.zip

That is 8.8 Mb. You just need to unzip that and use the file in it (mobythes.aur).
#3
Thanks Nick! It's working fine now.
#4
This is the only plugin I use terribly often, and I can't seem to get it to work since reinstalling MUSHclient on a new computer.

What I install the plugin:

[code]Run-time error
Plugin: Thesaurus (called from world: LAbN)
Function/Sub: OnPluginInstall called by Plugin Thesaurus
Reason: Executing plugin Thesaurus sub OnPluginInstall
[string "Plugin"]:4: Function 'io.input' disabled in Lua sandbox - see MUSHclient global preferences
stack traceback:
[C]: in function 'error'
[string "Sandbox"]:39: in function 'input'
[string "Plugin"]:4: in function <[string "Plugin"]:1>
Error context in script:
1 : function OnPluginInstall ()
2 : thes = {}
3 : local name = GetInfo (66) .. "mobythes.aur"
4*: thes_file = io.input (name)
5 : repeat
6 : local pos = thes_file:seek () --> where we are
7 : local line = thes_file:read () --> read a line
8 : if line then[/code]


The plugin is okayed in the Lua global preferences as per the initial post up there by Mr. Gammon. Thesaurus.xml is in the worlds/plugins folder, copied from the post above... And mobythes.aur is in the same folder as MUSHClient.exe.

I'm not sure what I've done wrong. Any help is appreciated!
Amended on Sun 04 Mar 2012 08:23 PM by Lmclarke
Australia Forum Administrator #5
It's because of the sandbox. Read this:

http://www.gammon.com.au/security

You need to disable the sandbox to let it read files.
#6
Ah! Thanks so much. It's working swimmingly.