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

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Suggestions
. . -> [Subject]  List of spellcheck suggestions
Home  |  Users  |  Search  |  FAQ
Register forum user name
Forgotten password?

List of spellcheck suggestions

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

Posted by Worstje   Netherlands  (899 posts)  [Biography] bio
Date Sun 29 Apr 2012 09:09 AM (UTC)

Amended on Sun 29 Apr 2012 10:04 AM (UTC) by Worstje

(Please please please do not let this feature be in MUSHclient already... I swear I triplechecked the help again!)

We can interact with the spellcheck engine in a number of ways. However, it is thus far impossible to programmatically request the list of possible corrections that you can see when you press Ctrl+J when there's some misspellings in the title bar.

Basically, I am looking for a:


that acts like:


{ 1="industry", 2="industry's", 3="windsurf" } -- Note: most likely corrections at beginning!

Basically I need it for a right-click popup I am making in my mini-window, which will offer to add words to the dictionary and to immediately fix a spelling error. (That said... suppose one does add stuff to the user dict, where can one find what is currently in it? Or get it out again, for that matter? My users are bound to ask...)


After a bit of struggling I figured out user stuff is in the spell.sqlite database as well. Aren't SQLite databases supposed to be openable from SQLite explorer and such tools at the same time as MUSHclient has them opened? I couldn't properly open them until I shut MUSHclient down.. which is annoying since it seems the only way to remove stuff from there at present. (Haven't tried internal MUSH SQLite bindings, but I honestly don't want to mess with SQL just to view what stuff I've put into the userdict... :/
[Go to top] top

Posted by Fiendish   USA  (1,641 posts)  [Biography] bio   Global Moderator
Date Reply #1 on Sun 29 Apr 2012 08:44 PM (UTC)
Aren't SQLite databases supposed to be openable from SQLite explorer and such tools at the same time as MUSHclient has them opened
You should read


[Go to top] top

Posted by Worstje   Netherlands  (899 posts)  [Biography] bio
Date Reply #2 on Sun 29 Apr 2012 09:28 PM (UTC)

My 'problem' is that I can open the prefs database for example just fine while MUSHclient is running. But other tools have trouble even showing the defined tables in case of the spell database, nevermind trying to add or delete a record. MUSHclient doesn't seem to notice that. Ergo, I feel like something is 'off' compared to the way the other databases behave when accessing with another applicaton.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Mon 30 Apr 2012 01:16 AM (UTC)

Amended on Mon 30 Apr 2012 08:25 PM (UTC) by Nick Gammon

This will do it:

local METAPHONE_LENGTH = 4   -- how many characters of metaphone to get back
local EDIT_DISTANCE = 4      -- how close a word must be to appear in the list of suggestions
local CASE_SENSITIVE = false -- compare case? true or false

local make_upper  -- this becomes the upper-case conversion function, see below

-- sort function for sorting the suggestions into edit-distance order
local function suggestions_compare (word)
   return function (a, b)
     local diff = utils.edit_distance (make_upper (a), word) - 
                  utils.edit_distance (make_upper (b), word) 
     if diff == 0 then
       return make_upper (a) < make_upper (b)
       return diff < 0
     end -- differences the same?
  end -- compareit
end -- function suggestions_compare

function GetSpellCheckCorrections (word)

  -- make a suitable function depending on whether they want case-sensitive or not
    make_upper = function (s) return s end -- return original
    make_upper = function (s) return s:upper () end  -- make upper case
  end -- case-sensitivity test

  uc_word = make_upper (word)  -- convert to upper-case if wanted

  -- path to the spell check dictionaries
  local directory = utils.info ().app_directory .. "spell\\"

  -- open database on disk
  db = assert (sqlite3.open( directory .. "spell.sqlite"))

  -- table of suggestions, based on the metaphone
  local keyed_suggestions = {}
  -- get both metaphones
  local m1, m2 = utils.metaphone (word, METAPHONE_LENGTH)
  local function lookup_metaphone (m)
    local found = false
    for row in db:rows(string.format ("SELECT name FROM words WHERE metaphone = '%s'", m)) do
      local word = row [1]
      if make_upper (word) == uc_word then
        found = true -- found exact match
      end  -- found
      if utils.edit_distance (make_upper (word), uc_word) < EDIT_DISTANCE then
        keyed_suggestions [word] = true
      end -- close enough
    return found
  end -- lookup_metaphone
  -- look up first metaphone
  if lookup_metaphone (m1) then
    db:close ()
    return word, "ok"
  end -- word found

  -- try 2nd metaphone
  if m2 then
    if lookup_metaphone (m2) then
      db:close ()
      return word, "ok"
    end -- word found
  end -- have alternate metaphone

  -- pull into indexed table
  local suggestions = {}
  for k in pairs (keyed_suggestions) do
    table.insert (suggestions, k)
  end -- for 
  table.sort (suggestions, suggestions_compare (uc_word))

  db:close ()
  return suggestions

end -- GetSpellCheckCorrections

Test it:

t = GetSpellCheckCorrections ("indstry")
tprint (t)



This is based on the spellchecker.lua file. Note the 2nd return value is "ok" if it finds an exact match on the metaphone. You may or may not want to keep that. I can't remember what that is for.

[EDIT] Amended the two paths above that return "ok" to close the database first.

- Nick Gammon

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

Posted by Worstje   Netherlands  (899 posts)  [Biography] bio
Date Reply #4 on Mon 30 Apr 2012 07:41 AM (UTC)
Sweet. Thank you! I'll study and test it later today. :) I admit I had considered digging into the source to see how it was done, but I wasn't sure how viable it is as in most situations, one would consider a solution like that an implementation specific hack. :-)

Are there any plans to improve the UI for as far the custom user-added spellcheck words are concerned? I'm worried that making it easy to add new words to the dictionary will mean that mistakes are going to happen, and if people cannot easily revert it that's going to be a problem.

(Writing an entire interface just to manage such accidental clicks is a bit beyond the scope of my plugin I'd dare say.)
[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 FutureQuest]