Skip to content

Treat any ActiveRecord's string field as a dictionary to do word suggesting & spelling checking using Hunspell

License

Notifications You must be signed in to change notification settings

jasoncheow/acts_as_dictionary

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ActsAsDictionary
================

ActsAsDictionary creates Hunspell (http://hunspell.sourceforge.net/) dictionaries using data from ActiveRecord models and provides class methods to access these dictionaries.

Pre-requisites
==============

This plugin requires the Hunspell library and RubyInline gem.

To install Hunspell:
	
	curl -O http://nchc.dl.sourceforge.net/sourceforge/hunspell/hunspell-1.2.7.tar.gz
	tar -zxvf hunspell-1.2.7.tar.gz
	cd hunspell-1.2.7
	./configure
	make
	sudo make install
	
To install RubyInline:

	gem install RubyInline
		
Setup
=====

Within a model, define the column you want to work with:

	class Klass < ActiveRecord::Base
	  acts_as_dictionary :checks => :name
	end

Or, if you want to create dictionaries using two or more columns

	class Klass < ActiveRecord::Base
	  acts_as_dictionary :checks => [:name, :type]
	end

Once done, you can proceed to generate basic Hunspell dictionary files with:

	rake dict:generate

In the above example, the following files will be generated:

	#{Rails.root}/dict/klass_names.aff
	#{Rails.root}/dict/klass_names.dic
	#{Rails.root}/dict/klass_types.aff
	#{Rails.root}/dict/klass_types.dic
	
Each pair of these files (*.aff and *.dic) are Hunspell dictionary definition files	which you can further configure if needed (see http://sourceforge.net/docman/display_doc.php?docid=29374&group_id=143754).

Note that if manually configure the files, running the dict:generate Rake task again will override your manual configurations.

Usage
=====

With this plugin, the following dynamic class methods are available (replace * with a column name you have specified to check):

	>> Klass.find_by_*_with_spell_check("Naem")
	=> #<Klass id: 1, name: "Name">
	
	>> Klass.suggest_*("Naem")
	=> ["Name", "Name2"]
	
	>> Klass.check_*("Name")
	=> true

About

Treat any ActiveRecord's string field as a dictionary to do word suggesting &amp; spelling checking using Hunspell

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published