The Accidental Rubyist

invalid byte sequence in UTF-8

Ecto script: ABBR

leave a comment »

Now I know, Mr Shinckel has already posted a python script to do some word replacements. And I don’t claim this is much of a help because ecto already provides spell-checking. But just in case you like using your own short forms for things, you could use this. It uses a dictionary file that is outside the script, and replaces ALL instances. So its more of a spell-checker or “abbr” like facility than the first occurrence replacer that Mr Shinckel has shared.

#!/usr/bin/env ruby
require "yaml"
file = ARGV[0];
text = File.open(file,"r").readlines.join;
mymap = YAML::load( File.open("dict.yaml")); 
mymap.each_pair{ |key, value|
  text.gsub!(key, value);
}
File.open(file, "w").puts text;

The dictionary file is as follows:

cant: can't 
dont: don't 
wrogn: wrong
the: the
prog;: programming
lang;: language

The abbr script is available here, and here is the dict. You will have to add entries in the dict. You can even add URLs and they will be globally replaced.

Advertisements

Written by totalrecall

March 1, 2007 at 5:00 pm

Posted in ecto, ruby

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: