GithubHelp home page GithubHelp logo

segabor / hunspell Goto Github PK

View Code? Open in Web Editor NEW
33.0 4.0 11.0 734 KB

Ruby wrapper for the famous spell checker library hunspell.

License: GNU Lesser General Public License v3.0

Ruby 41.91% C 58.09%
ruby hunspell rubygem hunspell-spell-checker

hunspell's Introduction

Hunspell Gem Version Build Status

Ruby interface to hunspell spell checker Copyright 2007, Gabor SEBESTYEN

WHAT IS THIS?

Hunspell is an simple native Ruby interface to the famous Hunspell spell checker library which is part of OpenOffice and Mozilla products. With this bundle you can start to develop your own AJAX based spell checker service for Ruby on Rails.

REQUIREMENTS

Before installing Hunspell ensure you have the following components already installed:

  • Ruby >= 1.8
  • rubygems
  • hunspell native library >= 1.3 (libhunspell-1.3)
  • dictionary files: download from LibreOffice or OpenOffice websites.

INSTALLATION

The best way to get Hunspell is to use gem package manager

gem install hunspell

NOTE: if install fails on newer OSX versions, try this command

sudo ARCHFLAGS="-arch x86_64" gem install hunspell

If you want to build Hunspell from scratch grab the source from here and execute the following command

ruby extconf.rb && make

FreeBSD gotcha: hunspell spell checker package does not deploy its header files. Run gem or ruby command with an extra option:

gem install hunspell -- --with-include-dir=<incdir>

or

ruby extconf.rb --with-include-dir=<incdir> && make

Replace incdir with the path pointing to hunspell includes.

FIRST STEPS

Here's a basic example how to use Hunspell. Cut it and run in ruby.

example.rb

require "rubygems" # import gem package manager
gem "hunspell"     # load Hunspell module
require "Hunspell" # inject Hunspell class to Ruby namespace

# instantiate Hunspell with Hungarian affix and dictionary files
#

sp = Hunspell.new("hu_HU.aff", "hu_HU.dic") 

# spell check Hungarian word 'ablak' (window) => true
#
puts "Is 'ablak' correct? #{sp.spellcheck('ablak')}"

# get suggestions for mispelled word 'paprika'
#   => ["kaprica", "patrica", "paprika", "papcica",
#       "papráca", "papruca", "paprima", "paprikáz",
#       "paprikása", "paprikás", "Papradnó"
#      ]
#
puts "Suggestions for 'paprica': " + sp.suggest("paprica").inspect

Note you might run this example with -Ke ruby option if you want to see accented letters instead of backslash prefixed utf codes.

FEEDBACK

Any help or report are warmly appreciated. Please visit the project's homepage at https://github.com/segabor/Hunspell and open an issue.

hunspell's People

Contributors

oyeanuj avatar pkerling avatar reneklacan avatar segabor avatar vincentisambart avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

hunspell's Issues

Can't 'gem install hunspell' ruby 2.7.2

Hi, I have an error in my hunspell install and I can't fix the problem with documentation or other github issues.

Error log :

Building native extensions. This could take a while...
ERROR:  Error installing hunspell:
	ERROR: Failed to build gem native extension.

    current directory: .rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/hunspell-1.1.0
.rbenv/versions/2.7.2/bin/ruby -I .rbenv/versions/2.7.2/lib/ruby/2.7.0 -r ./siteconf20230823-34145-7c4mps.rb extconf.rb
checking for Hunspell_create() in -lhunspell-1.7... no
checking for Hunspell_create() in -lhunspell-1.6... no
checking for Hunspell_create() in -lhunspell-1.5... no
checking for Hunspell_create() in -lhunspell-1.4... no
checking for Hunspell_create() in -lhunspell-1.3... no
Missing hunspell library
Supported versions: hunspell-1.7 hunspell-1.6 hunspell-1.5 hunspell-1.4 hunspell-1.3
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
	--with-opt-dir
	--without-opt-dir
	--with-opt-include
	--without-opt-include=${opt-dir}/include
	--with-opt-lib
	--without-opt-lib=${opt-dir}/lib
	--with-make-prog
	--without-make-prog
	--srcdir=.
	--curdir
	--ruby=.rbenv/versions/2.7.2/bin/$(RUBY_BASE_NAME)
	--with-hunspell-1.7-dir
	--without-hunspell-1.7-dir
	--with-hunspell-1.7-include
	--without-hunspell-1.7-include=${hunspell-1.7-dir}/include
	--with-hunspell-1.7-lib
	--without-hunspell-1.7-lib=${hunspell-1.7-dir}/lib
	--with-hunspell-1.6-dir
	--without-hunspell-1.6-dir
	--with-hunspell-1.6-include
	--without-hunspell-1.6-include=${hunspell-1.6-dir}/include
	--with-hunspell-1.6-lib
	--without-hunspell-1.6-lib=${hunspell-1.6-dir}/lib
	--with-hunspell-1.5-dir
	--without-hunspell-1.5-dir
	--with-hunspell-1.5-include
	--without-hunspell-1.5-include=${hunspell-1.5-dir}/include
	--with-hunspell-1.5-lib
	--without-hunspell-1.5-lib=${hunspell-1.5-dir}/lib
	--with-hunspell-1.4-dir
	--without-hunspell-1.4-dir
	--with-hunspell-1.4-include
	--without-hunspell-1.4-include=${hunspell-1.4-dir}/include
	--with-hunspell-1.4-lib
	--without-hunspell-1.4-lib=${hunspell-1.4-dir}/lib
	--with-hunspell-1.3-dir
	--without-hunspell-1.3-dir
	--with-hunspell-1.3-include
	--without-hunspell-1.3-include=${hunspell-1.3-dir}/include
	--with-hunspell-1.3-lib
	--without-hunspell-1.3-lib=${hunspell-1.3-dir}/lib
	--with-hunspell-1.7lib
	--without-hunspell-1.7lib
	--with-hunspell-1.6lib
	--without-hunspell-1.6lib
	--with-hunspell-1.5lib
	--without-hunspell-1.5lib
	--with-hunspell-1.4lib
	--without-hunspell-1.4lib
	--with-hunspell-1.3lib
	--without-hunspell-1.3lib

To see why this extension failed to compile, please check the mkmf.log which can be found here:

I'm currently on OSX Ventura 13, ruby version 2.7.2, hunspell lib 1.7.2
Trying to install gem hunspell 1.1.0

If you have an idea on how to fix it, it will be greatly appreciated.

Found the solution : You need to specify path like
sudo gem install hunspell -- --with-opt-dir=/opt/homebrew/opt/hunspell

Suggestion strings being encoded incorrectly

Try the following:

sp = Hunspell.new('en_ZA.aff', 'en_ZA.dic')
s = sp.suggest("Skjhd")[0]
# => "Ski\xE2\x80\x99d"
s.encoding
# => #<Encoding:ASCII-8BIT>
s.encode("utf-8")
# => Encoding::UndefinedConversionError: "\xE2" from ASCII-8BIT to UTF-8

(I'm using a South African English dictionary from here.)

What seems to be happening is that the string is incorrectly encoded as ASCII, when it is in fact UTF-8. Since the UTF code points are not valid ASCII, it throws an error when attempting to convert them from ASCII (supposedly) to UTF.

If I force the encoding, the string renders correctly:

s.force_encoding("utf-8")
# => "Ski’d"

Release 1.0

The project is 10 years old. Let's celebrate it with the first mature release.

Install failing on Ubuntu 14.04 LTS v1606

Much like #2, my installs on Ubuntu (on Semaphore specifically) are failing like so:

Semaphore: ~/myproject $ gem install hunspell
Building native extensions.  This could take a while...
ERROR:  Error installing hunspell:
        ERROR: Failed to build gem native extension.

    /home/runner/.rbenv/versions/2.2.4/bin/ruby -r ./siteconf20160624-9856-12dlc21.rb extconf.rb
checking for Hunspell_create() in -lhunspell-1.2... no
creating Makefile

make "DESTDIR=" clean

make "DESTDIR="
compiling hunspell.c
hunspell.c:26:31: fatal error: hunspell/hunspell.h: No such file or directory
 #include "hunspell/hunspell.h"
                               ^
compilation terminated.
make: *** [hunspell.o] Error 1

make failed, exit code 2

Gem files will remain installed in /home/runner/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/hunspell-0.1.2 for inspection.
Results logged to /home/runner/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/extensions/x86_64-linux/2.2.0-static/hunspell-0.1.2/gem_make.out

As suggested in the other issue, I tried sudo apt-get install hunspell first, and that works just fine, but the gem install still fails.

English Dictionary not supporting

I was trying using "dict-en.oxt & english.aff"(English affix and dictionaries.) to get English language support with Hunspell, it is showing blank array for suggestions with no errors.

Please suggest me, how can I use Hunspell for International English Language support.
There is no installation problem I hope, as it is working properly with "Hungarian affix and dictionary"

Usage with a paragraph of text?

Hi @segabor, firstly, thank you for creating this library. I was curious if there was any example of using it with a paragraph of text? Or is it only meant to be used one word at a time and get suggestions for that word?

Is there a performant way to feed in a paragraph, and get a hash of the problem-word, its offset, and its suggestions?

Thank you!

Install failing on Os X

I am getting the following problem when trying to install the hunspell gem on El Capitan.

~$ gem install hunspell
Building native extensions.  This could take a while...
ERROR:  Error installing hunspell:
    ERROR: Failed to build gem native extension.

    /usr/local/var/rbenv/versions/2.2.3/bin/ruby -r ./siteconf20151019-48887-8na0ke.rb extconf.rb
checking for Hunspell_create() in -lhunspell-1.2... yes
creating Makefile

make "DESTDIR=" clean

make "DESTDIR="
compiling hunspell.c
hunspell.c:26:10: fatal error: 'hunspell/hunspell.h' file not found
#include "hunspell/hunspell.h"
         ^
1 error generated.
make: *** [hunspell.o] Error 1

make failed, exit code 2

Gem files will remain installed in /usr/local/var/rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/hunspell-0.1.2 for inspection.
Results logged to /usr/local/var/rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-15/2.2.0-static/hunspell-0.1.2/gem_make.out

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.