mIRC Homepage
Posted By: maconga text-replacement script - 13/05/10 11:59 PM
I make a lot of typo's and do not notice them.
I was wondering if its possible to have a script that see's my typo's and can replace them automatically as I type.
I would like to have 2-3 words done, and i can figure out the rest.

I type " dont "
Script correction " don't "

Posted By: FroggieDaFrog Re: text-replacement script - 14/05/10 12:06 AM
Code:
on *:INPUT:#,?:{
  if (!$ctrlenter && /* !iswm $1) {
    var %wordMistakes = /\b(word1|word2|word3|...)\b/ig
    tokenize 32 $regsubex($1-,%wordmistakes,$fixword(\t))
    msg $active $1-
    halt
  }
}
alias fixword {
  if ($1- == word1) { return word1replacement }
  elseif ($1- == word2) { return word2replacement }
  elseif ($1- == word3) { return word3replacement }
  elseif ($1- == ...) { return ...replacement }
  else { return $1- }
}

how I would do it, anyways
Posted By: Riamus2 Re: text-replacement script - 14/05/10 12:35 AM
I think I'd recommend a hash table if you plan to add a lot of words. If it's only a few, then an the above works fine.... except that you'd probably want $1 in the alias instead of $1- if you're using single words.

A quick way (and it might work better combining it with regex...

Code:
on *:input:*: {
  if (!$ctrlenter && !$inpaste && $left($1,1) != $readini(mirc.ini,text,commandchar)) {
    CreateSpelling
    var %text = $1-, %t = $numtok($1-,32)
    while (%t) {
      var %text = $iif($hget(Spelling,$gettok(%text,%t,32)),$replace(%text,$gettok(%text,%t,32),$v1),%text)
      dec %t
    }
    msg $active %text
    halt
  }
}

alias CreateSpelling {
  if (!$hget(Spelling)) {
    hmake Spelling 10
    if ($exists(Spelling.hsh)) { hload Spelling Spelling.hsh }
  }
}

menu * {
  Spelling
  .Load Spelling:CreateSpelling
  .Add Word:hadd Spelling $$?="Enter misspelled word" $$?="Enter correct spelling"
  .Remove Word:hdel Spelling $$?="Enter the misspelled word you want to remove"
}


Note that you may also want to throw in some checks for punctuation as this won't match "dont" if it has punctuation next to it (e.g. "dont!"). This was just a quick thing I put together to give a general idea of how it works. It lets you add as many words as you want to with just a right click menu without editing the script at all.
Posted By: FroggieDaFrog Re: text-replacement script - 14/05/10 12:42 AM
Quote:
except that you'd probably want $1 in the alias instead of $1-


the reason I used $1- was so he/she could take into account strings of words. He/She could use to it replace something like "I am" with "I'm"
Posted By: Riamus2 Re: text-replacement script - 14/05/10 12:53 AM
Ok. smile
Posted By: maconga Re: text-replacement script - 14/05/10 02:26 AM
Riamus2,

once again, thanks for your script. i love it.
also, I do plan on slowly adding 1000-2000 words as I am a HORRIBLE at spelling.

i changed this
Quote:
var %text = $iif($hget(Spelling,$gettok(%text,%t,32)),$replace(%text,$gettok(%text,%t,32),$v1),%text)


into
Quote:
var %text = $iif($hget(Spelling,$gettok(%text,%t,32)),$puttok(%text,$v1,%t,32),%text)




changed this
Quote:
.Add Word:hadd Spelling $$?="Enter misspelled word" $$?="Enter correct spelling"
.Remove Word:hdel Spelling $$?="Enter the misspelled word you want to remove"



into this

Quote:
.Add Word:hadd Spelling $$?="Enter misspelled word" $$?="Enter correct spelling" | hsave Spelling Spelling.hsh
.Remove Word:hdel Spelling $$?="Enter the misspelled word you want to remove" | hsave Spelling Spelling.hsh




FroggieDaFrog,

thanks for that script, but I'm looking for something really easy ( no offense ) [quote][/quote]
Posted By: Tomao Re: text-replacement script - 14/05/10 03:25 AM
It may be possible to do a socket script for this, which finds a website that does the spell checking for you and outputs it with the correct spelling. The best part is, you don't have to store a thing.
Posted By: maconga Re: text-replacement script - 14/05/10 03:43 AM
Tomao,

yeah may be, but I'm looking for something simple that i can add/remove and not have to rely on anything else.



also, This is the text replacement from Pidgin, a multi-protocol program, and it would be interesting to have something like this in a script ( if possible )



Posted By: Riamus2 Re: text-replacement script - 14/05/10 11:51 AM
Yeah, I forgot to put the /hsaves in there. Oops. smile

That popup could be created using dialogs and "loading" the hash table data into the dialog listbox and then adding a bit more information to the hash table including the checkbox information. It really wouldn't take much effort other than taking time to create the dialog. The only change to what you currently have is to add the checkbox values when you use /hadd and then only use the first token when you're using $hget() to display the correct spelling. The other thing you'd need changed is if you want to replace multiple words (like it' snot). What I gave you doesn't handle multiple words as-is. You can $replace spaces with another character (something you don't expect to see in the channel(s) you visit) to make it work.

If you do want to use something like that, I'd recommend trying to set up the dialog yourself and see if you can get it working. That part should be fairly easy as dialogs are all basically the same. They just usually take a lot more time to set up. That's really the only "hard" thing about dialogs.

Then, if you have any issues with it, post what you have and we'll help out.
Posted By: maconga Re: text-replacement script - 27/07/10 12:32 AM
So far the script has been flawless until I noticed when I do a
Quote:
/me
in a channel, the script does not correct any words I have. How can I fix this?

Code:
on *:input:*: {
  if (!$ctrlenter && !$inpaste && $left($1,1) != $readini(mirc.ini,text,commandchar)) {
    CreateSpelling
    var %text = $1-, %t = $numtok($1-,32)
    while (%t) {
      var %text = $iif($hget(Spelling,$gettok(%text,%t,32)),$puttok(%text,$v1,%t,32),%text)      
      dec %t
    }
    msg $active %text
    halt
  }
}

alias CreateSpelling {
  if (!$hget(Spelling)) {
    hmake Spelling 10
    if ($exists(Spelling.hsh)) { hload Spelling Spelling.hsh }
  }
}

menu * {
  Spelling
  .Load Spelling:CreateSpelling
  .Add Word:hadd Spelling $$?="Enter misspelled word" $$?="Enter correct spelling" | hsave Spelling Spelling.hsh
  .Remove Word:hdel Spelling $$?="Enter the misspelled word you want to remove" | hsave Spelling Spelling.hsh
}
Posted By: FroggieDaFrog Re: text-replacement script - 27/07/10 07:29 AM
add:
Code:
alias me {
  var %text = $1-, %t = $numtok($1-,32)
  while (%t) {
    var %text = $iif($hget(Spelling,$gettok(%text,%t,32)),$puttok(%text,$v1,%t,32),%text)      
    dec %t
  }
  $iif($show,!me,!.me) %text
}
Posted By: maconga Re: text-replacement script - 27/07/10 07:55 AM
FroggieDaFrog,

Thank You so much, its working
Posted By: FroggieDaFrog Re: text-replacement script - 27/07/10 08:02 AM
That's what this forum is for smile
Posted By: chacha Re: text-replacement script - 27/07/10 08:03 AM
hi
you can put in a file .txt columns in the format:

dont don't

and the code will be some thing like this just an EG

Code:
on *:input:*:{
  if $left($1,1) != / {
    var %x 1
    while ($gettok($1-,%x,32)) var %v $v1,%t %t $iif($read(file.txt,s,%v),$v1,%x %x + 1
    msg $active %t
    haltdef
  }
}

Posted By: maconga Re: text-replacement script - 27/07/10 08:25 AM
chacha,

Your script, how do I integrate it? Please bare with me, as I have absolutely no understanding of scripting.
Posted By: chacha Re: text-replacement script - 27/07/10 09:12 AM
that was just an eg but if you realy need it ok

creates a file (NotePad) and named wdic.txt and write in it

word the defenition here
dont don't
isnt is not

now take this part and put it into remote

Code:
on *:input:*:{
  if $left($1,1) != / {
    var %x 1
    while ($gettok($1-,%x,32)) var %v $v1,%t %t $iif($read(wdic.txt,s,$(,$+(%,v))),$v1,$(,$+(%,v))),%x %x + 1
    msg $active %t
    haltdef
  }
}
Posted By: maconga Re: text-replacement script - 27/07/10 09:26 AM
chacha,

It works now, I see what I was doing wrong. I was doing
Quote:
dont=don't
instead of
Quote:
dont don't


Once again, Many Thanks.
© mIRC Discussion Forums