[Home] [Downloads] [Search] [Help/forum]

Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Tips and tricks
. . -> [Subject]  Using Word to do a Thesaurus lookup

Using Word to do a Thesaurus lookup

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Posted by Nick Gammon   Australia  (23,003 posts)  [Biography] bio   Forum Administrator
Date Tue 14 Dec 2004 04:29 AM (UTC)
I don't have this working perfectly yet, but enough to be worth documenting. It might save someone (like me, in a month) half a day's work working out the details.

The intention was to get MUSHclient to lookup a word, as in using a thesaurus, using Word as the thesaurus engine, as a lot of people would have Word installed.

For a start, to do this you will need a COM object. I have tried to do it in Lua, with partial success. Maybe the problem is the Lua COM implementation. ;)

Here is the code for a proposed "lookup word" alias:

require "luacom"

function GetSynonym (name, line, wildcards)

word = luacom.GetObject("Word.Application")

if not word then
  ColourNote ("white", "red", "Word is not running")
end -- if

word.Visible = true  -- make Word visible
word:Activate ()  -- bring Word to the front

if word.Documents.count == 0 then
  ColourNote ("white", "red", "No document open in Word")
end -- if

doc = word.ActiveDocument  -- get active document

doc.Words (1):InsertBefore (wildcards [1] .. " ")  
doc.Words (1):CheckSynonyms ()

-- show resulting word
ColourNote ("white", "blue", doc.Words (1).Text)

ActivateClient ()  -- reactivate MUSHclient

-- release COM objects
doc = nil
word = nil

end -- function 

I couldn't get the COM interface to create a new object and add a new Word document, so for this to work you need to start Word yourself, and have an empty document open.

Then this should insert the wanted word as word 1 in the document (InsertBefore) and look up the thesaurus (CheckSynonyms). Then the word you replace it with is recovered (doc.Words (1).Text) and displayed in the output window.

Apart from the annoyance of having to start Word, and the possibility this would corrupt any existing Word document you might have open, it also has the annoyance that it only works once. Trying it a second time seems to hang Word, or at least it does for my version.

Maybe some COM expert out there can see what I am doing wrong. However it is a starting point for the general idea.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Morat   (18 posts)  [Biography] bio
Date Reply #1 on Mon 04 Jan 2010 11:05 AM (UTC)

Amended on Mon 04 Jan 2010 11:07 AM (UTC) by Morat

I got an online thesaurus working using WordNet and LuaSocket.

About WordNet

WordNet Search

Communicating with the Internet (with LuaSocket)

WordNet Search: bash
 (n) knock, bash, bang, smash, belt (a vigorous blow) 
 (n) bash, do, brawl (an uproarious party) 
 (v) sock, bop, whop, whap, bonk, bash (hit hard) 

   match="wordnet *"
  <send>local http = require "socket.http"
local url = "http://wordnetweb.princeton.edu/perl/webwn"
local search = "?c=0&amp;s=" .. string.gsub("%1", " ", "+")
local html = http.request(url .. search)
AnsiNote("\\n" .. ANSI(37) .. "WordNet Search: %1")
for m in string.gmatch(html, "S:&lt;/a&gt;([^\\n]*)\\n") do
  local s = string.gsub(m, "&lt;[^&gt;]*&gt;", "")
  AnsiNote(ANSI(32) .. s)

The only problem is the script hangs if princeton.edu is too slow to respond.
[Go to top] top

Posted by Shadowfyr   USA  (1,786 posts)  [Biography] bio
Date Reply #2 on Mon 04 Jan 2010 05:42 PM (UTC)

Amended on Mon 04 Jan 2010 05:43 PM (UTC) by Shadowfyr

First thing you are doing wrong is assuming that sane people that use your client have word installed, instead of Open Office. lol

Seriously though, this snippet of code, for VB, implies you don't need to go as far as opening a document:

Dim si As SynonymInfo
Dim wordApp As Word._Application
wordApp = CreateObject("Word.Application")
si = wordApp.SynonymInfo("good")

No idea if there is one for Antonyms too.
[Go to top] top

Posted by Nick Gammon   Australia  (23,003 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Mon 04 Jan 2010 11:30 PM (UTC)
In response to your other post, I have found out why the plugin doesn't work, so you may want to go back to using that.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum

[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]