raspell-1.3/ 0000755 0001750 0001750 00000000000 12256647036 012410 5 ustar boutil boutil raspell-1.3/README.rdoc 0000644 0001750 0001750 00000004247 12256647036 014225 0 ustar boutil boutil
raspell
An interface binding for the Aspell spelling checker.
== License
Copyright 2007-2010 Cloudburst, LLC. Licensed under the GPL 2.0. See included LICENSE file. Portions copyright 2005 Matthias Veit, Biro Eszter and used with permission.
The public certificate for the gem is here[http://rubyforge.org/frs/download.php/25331/evan_weaver-original-public_cert.pem].
If you use this software, please {make a donation}[http://blog.evanweaver.com/donate/], or {recommend Evan}[http://www.workingwithrails.com/person/7739-evan-weaver] at Working with Rails.
== Requirements
Raspell requires Aspell version 0.6 (http://www.aspell.net) and at least one Aspell dictionary.
Mac:
sudo port install aspell aspell-dict-en
Ubuntu:
sudo apt-get install aspell libaspell-dev aspell-en
== Installation
Mac:
sudo gem install raspell -- --with-opt-dir=/opt/local
Ubuntu:
sudo gem install raspell
== Usage
Aspell lets you check words and suggest corrections. For example:
require 'rubygems'
require 'raspell'
speller = Aspell.new("en_US")
speller.suggestion_mode = Aspell::NORMAL
string = "my haert wil go on"
string.gsub(/[\w\']+/) do |word|
if !speller.check(word)
# word is wrong
puts "Possible correction for #{word}:"
puts speller.suggest(word).first
end
end
This outputs:
Possible correction for haert:
heart
Possible correction for wil:
Will
Note that suggest returns an array of suggestions even for words that are correctly spelled.
== Options
The most useful options are suggestion_mode, and the passthrough option ignore_case. Passthrough options have to be set as so:
speller.set_option("ignore-case", "true")
See http://aspell.net/man-html/The-Options.html for a list of the passthrough options.
== Reporting problems
The support forum is here[http://rubyforge.org/forum/forum.php?forum_id=13988].
Patches and contributions are very welcome. Please note that contributors are required to assign copyright for their additions to Cloudburst, LLC.
== Futher resources
* http://blog.evanweaver.com/articles/2007/03/10/add-gud-spelning-to-ur-railz-app-or-wharever
raspell-1.3/Manifest 0000644 0001750 0001750 00000000203 12256647036 014074 0 ustar boutil boutil CHANGELOG
LICENSE
Manifest
README.rdoc
Rakefile
ext/extconf.rb
ext/raspell.c
ext/raspell.h
lib/raspell_stub.rb
test/simple_test.rb
raspell-1.3/raspell.gemspec 0000644 0001750 0001750 00000002446 12256647036 015425 0 ustar boutil boutil # -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
s.name = "raspell"
s.version = "1.3"
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
s.authors = [""]
s.cert_chain = ["/Users/eweaver/p/configuration/gem_certificates/evan_weaver-original-public_cert.pem"]
s.date = "2011-12-03"
s.description = "An interface binding for the Aspell spelling checker."
s.email = ""
s.extensions = ["ext/extconf.rb"]
s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README.rdoc", "lib/raspell_stub.rb"]
s.files = ["CHANGELOG", "LICENSE", "Manifest", "README.rdoc", "Rakefile", "ext/extconf.rb", "ext/raspell.c", "ext/raspell.h", "lib/raspell_stub.rb", "test/simple_test.rb", "raspell.gemspec"]
s.homepage = "http://fauna.github.com/fauna/raspell/"
s.require_paths = ["lib", "ext"]
s.rubyforge_project = "fauna"
s.rubygems_version = "1.8.10"
s.signing_key = "/Users/eweaver/p/configuration/gem_certificates/evan_weaver-original-private_key.pem"
s.summary = "An interface binding for the Aspell spelling checker."
s.test_files = ["test/simple_test.rb"]
if s.respond_to? :specification_version then
s.specification_version = 3
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
else
end
else
end
end
raspell-1.3/metadata.yml 0000644 0001750 0001750 00000004652 12256647036 014722 0 ustar boutil boutil --- !ruby/object:Gem::Specification
name: raspell
version: !ruby/object:Gem::Version
version: '1.3'
prerelease:
platform: ruby
authors:
- ''
autorequire:
bindir: bin
cert_chain:
- ! '-----BEGIN CERTIFICATE-----
MIIDLjCCAhagAwIBAgIBADANBgkqhkiG9w0BAQUFADA9MQ0wCwYDVQQDDARldmFu
MRgwFgYKCZImiZPyLGQBGRYIY2xvdWRidXIxEjAQBgoJkiaJk/IsZAEZFgJzdDAe
Fw0wNzA5MTYxMDMzMDBaFw0wODA5MTUxMDMzMDBaMD0xDTALBgNVBAMMBGV2YW4x
GDAWBgoJkiaJk/IsZAEZFghjbG91ZGJ1cjESMBAGCgmSJomT8ixkARkWAnN0MIIB
IjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA5C0Io89nyApnr+PvbNFge9Vs
yRWAlGBUEMahpXp28VrrfXZT0rAW7JBo4PlCE3jl4nE4dzE6gAdItSycjTosrw7A
Ir5+xoyl4Vb35adv56TIQQXvNz+BzlqnkAY5JN0CSBRTQb6mxS3hFyD/h4qgDosj
R2RFVzHqSxCS8xq4Ny8uzOwOi+Xyu4w67fI5JvnPvMxqrlR1eaIQHmxnf76RzC46
QO5QhufjAYGGXd960XzbQsQyTDUYJzrvT7AdOfiyZzKQykKt8dEpDn+QPjFTnGnT
QmgJBX5WJN0lHF2l1sbv3gh4Kn1tZu+kTUqeXY6ShAoDTyvZRiFqQdwh8w2lTQID
AQABozkwNzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQU+WqJz3xQ
XSea1hRvvHWcIMgeeC4wDQYJKoZIhvcNAQEFBQADggEBAGLZ75jfOEW8Nsl26CTt
JFrWxQTcQT/UljeefVE3xYr7lc9oQjbqO3FOyued3qW7TaNEtZfSHoYeUSMYbpw1
XAwocIPuSRFDGM4B+hgQGVDx8PMGiJKom4qLXjO40UZsR7QyN/u869Vj45LURm6h
MBcPeqCASI+WNprj9+uZa2kmHiitrFqqfMBNlm5IFbn9XeYSta9AHVvs5QQqV2m5
hIPfLqCyxsn/YgOGvo6iwyQTWyTswamaAC3HRWZxIS1sfn/Ssqa7E7oQMkv5FAXr
x5rKePfXINf8XTJczkl9OBEYdE9aNdJsJpXD0asLgGVwBICS5Bjohp6mizJcDC1+
yZ0=
-----END CERTIFICATE-----
'
date: 2011-12-03 00:00:00.000000000 Z
dependencies: []
description: An interface binding for the Aspell spelling checker.
email: ''
executables: []
extensions:
- ext/extconf.rb
extra_rdoc_files:
- CHANGELOG
- LICENSE
- README.rdoc
- lib/raspell_stub.rb
files:
- CHANGELOG
- LICENSE
- Manifest
- README.rdoc
- Rakefile
- ext/extconf.rb
- ext/raspell.c
- ext/raspell.h
- lib/raspell_stub.rb
- test/simple_test.rb
- raspell.gemspec
homepage: http://fauna.github.com/fauna/raspell/
licenses: []
post_install_message:
rdoc_options: []
require_paths:
- lib
- ext
required_ruby_version: !ruby/object:Gem::Requirement
none: false
requirements:
- - ! '>='
- !ruby/object:Gem::Version
version: '0'
required_rubygems_version: !ruby/object:Gem::Requirement
none: false
requirements:
- - ! '>='
- !ruby/object:Gem::Version
version: '1.2'
requirements: []
rubyforge_project: fauna
rubygems_version: 1.8.10
signing_key:
specification_version: 3
summary: An interface binding for the Aspell spelling checker.
test_files:
- test/simple_test.rb
raspell-1.3/test/ 0000755 0001750 0001750 00000000000 12256647036 013367 5 ustar boutil boutil raspell-1.3/test/simple_test.rb 0000644 0001750 0001750 00000002041 12256647036 016241 0 ustar boutil boutil $:.unshift(File.dirname(__FILE__) + "/../lib/")
require 'test/unit'
require "raspell"
class TestSpell < Test::Unit::TestCase
def setup
@aspell = Aspell.new
@text = ["Hiere is somthing wrong on the planett. And it was not the Apollo."]
end
def test_correct_lines
assert_equal([" is wrong on the . And it was not the Apollo."],
@aspell.correct_lines(@text) { |word| "" })
end
def test_list_mispelled
misspelled = @aspell.list_misspelled(@text).sort
assert_equal(3, misspelled.length)
end
def test_suggest
suggestions = @aspell.suggest("spel")
assert_equal [],
["spell", "spiel", "spew", "Opel", "spec", "sped"] - suggestions
end
def test_check
assert_equal(false, @aspell.check("spel"))
assert(@aspell.check("spell"))
end
def test_argument_checking
assert_raises TypeError do
@aspell.list_misspelled "Not an array"
end
assert_raises TypeError do
@aspell.list_misspelled [123]
end
end
end
raspell-1.3/LICENSE 0000644 0001750 0001750 00000042502 12256647036 013420 0 ustar boutil boutil GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
== Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
== GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
== NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
== END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
Copyright (C)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.
raspell-1.3/ext/ 0000755 0001750 0001750 00000000000 12256647036 013210 5 ustar boutil boutil raspell-1.3/ext/extconf.rb 0000644 0001750 0001750 00000000253 12256647036 015203 0 ustar boutil boutil require "mkmf"
dir_config("opt", "/opt/local/include", "/opt/local/lib")
have_header("ruby.h")
have_header("aspell.h")
have_library("aspell")
create_makefile("raspell")
raspell-1.3/ext/raspell.c 0000644 0001750 0001750 00000062533 12256647036 015027 0 ustar boutil boutil
#include "raspell.h"
extern void Init_dictinfo();
extern void Init_aspell();
void Init_raspell() {
cAspellError = rb_define_class("AspellError", rb_eStandardError);
Init_dictinfo();
Init_aspell();
}
static AspellDictInfo* get_info(VALUE info) {
AspellDictInfo *result;
Data_Get_Struct(info, AspellDictInfo, result);
return result;
}
static VALUE dictinfo_s_new(int argc, VALUE *argv, VALUE klass) {
rb_raise(rb_eException, "not instantiable");
}
static VALUE dictinfo_name(VALUE self) {
return rb_str_new2(get_info(self)->name);
}
static VALUE dictinfo_code(VALUE self) {
return rb_str_new2(get_info(self)->code);
}
static VALUE dictinfo_jargon(VALUE self) {
return rb_str_new2(get_info(self)->jargon);
}
static VALUE dictinfo_size(VALUE self) {
return INT2FIX(get_info(self)->size);
}
static VALUE dictinfo_size_str(VALUE self) {
return rb_str_new2(get_info(self)->size_str);
}
void Init_dictinfo() {
//CLASS DEFINITION=========================================================
cDictInfo = rb_define_class("AspellDictInfo", rb_cObject);
//CLASS METHODS============================================================
rb_define_singleton_method(cDictInfo, "new", dictinfo_s_new, 0);
//METHODS =================================================================
rb_define_method(cDictInfo, "name", dictinfo_name, 0);
rb_define_method(cDictInfo, "code", dictinfo_code, 0);
rb_define_method(cDictInfo, "jargon", dictinfo_jargon, 0);
rb_define_method(cDictInfo, "size", dictinfo_size, 0);
rb_define_method(cDictInfo, "size_str", dictinfo_size_str, 0);
}
extern VALUE rb_cFile;
/**
* This method is called from the garbage collector during finalization.
* @param p pointer to spellchecker-object.
*/
static void aspell_free(void *p) {
delete_aspell_speller(p);
}
/**
* Check for an error - raise exception if so.
* @param speller the spellchecker-object.
* @return void
* @exception Exception if there was an error.
*/
static void check_for_error(AspellSpeller * speller) {
if (aspell_speller_error(speller) != 0) {
rb_raise(cAspellError, aspell_speller_error_message(speller));
}
}
/**
* Set a specific option, that is known by aspell.
* @param config the config object of a specific spellchecker.
* @param key the option to set (eg: lang).
* @param value the value of the option to set (eg: "us_US").
* @exception Exception if key not known, or value undefined.
*/
static void set_option(AspellConfig *config, char *key, char *value) {
//printf("set option: %s = %s\n", key, value);
if (aspell_config_replace(config, key, value) == 0) {
rb_raise(cAspellError, aspell_config_error_message(config));
}
//check config:
if (aspell_config_error(config) != 0) {
rb_raise(cAspellError, aspell_config_error_message(config));
}
}
static void set_options(AspellConfig *config, VALUE hash) {
VALUE options = rb_funcall(hash, rb_intern("keys"), 0);
int count=RARRAY_LEN(options);
int c = 0;
//set all values
while(c"de", "jargon"=>"berlin"})
*
* For a list of config options, see aspell manual.
* @param options hash of options
*/
static VALUE aspell_s_new1(VALUE klass, VALUE options) {
//aspell values
AspellCanHaveError * ret;
AspellSpeller * speller;
AspellConfig * config;
//create new config
config = new_aspell_config();
//set options
set_options(config, options);
//create speller:
ret = new_aspell_speller(config);
delete_aspell_config(config);
if (aspell_error(ret) != 0) {
const char *tmp = strdup(aspell_error_message(ret));
delete_aspell_can_have_error(ret);
rb_raise(cAspellError, tmp);
}
speller = to_aspell_speller(ret);
//wrap pointer
return Data_Wrap_Struct(klass, 0, aspell_free, speller);
}
/**
* List all available dictionaries.
* @param class object
* @return array of AspellDictInfo objects.
*/
static VALUE aspell_s_list_dicts(VALUE klass) {
AspellConfig * config;
AspellDictInfoList * dlist;
AspellDictInfoEnumeration * dels;
const AspellDictInfo * entry;
VALUE result = rb_ary_new();
//get a list of dictionaries
config = new_aspell_config();
dlist = get_aspell_dict_info_list(config);
delete_aspell_config(config);
//iterate over list - fill ruby array
dels = aspell_dict_info_list_elements(dlist);
while ( (entry = aspell_dict_info_enumeration_next(dels)) != 0) {
rb_ary_push(result, Data_Wrap_Struct(cDictInfo, 0, 0, (AspellDictInfo *)entry));
}
delete_aspell_dict_info_enumeration(dels);
return result;
}
/**
* @see set_option.
*/
static VALUE aspell_set_option(VALUE self, VALUE option, VALUE value) {
AspellSpeller *speller = get_speller(self);
set_option(aspell_speller_config(speller), StringValuePtr(option), StringValuePtr(value));
return self;
}
/**
* Delete an option.
* @param option optionstring to remove from the options.
*/
static VALUE aspell_remove_option(VALUE self, VALUE option) {
AspellSpeller *speller = get_speller(self);
aspell_config_remove(aspell_speller_config(speller), StringValuePtr(option));
return self;
}
/**
* To set the mode, words are suggested.
* @param one of Aspell::[ULTRA|FAST|NORMAL|BADSPELLERS]
*/
static VALUE aspell_set_suggestion_mode(VALUE self, VALUE value) {
AspellSpeller *speller = get_speller(self);
set_option(aspell_speller_config(speller), "sug-mode", StringValuePtr(value));
return self;
}
/**
* Returns the personal wordlist as array of strings.
* @return array of strings
*/
static VALUE aspell_personal_wordlist(VALUE self) {
AspellSpeller *speller = get_speller(self);
return get_list(aspell_speller_personal_word_list(speller));
}
/**
* Returns the session wordlist as array of strings.
* @return array of strings
*/
static VALUE aspell_session_wordlist(VALUE self) {
AspellSpeller *speller = get_speller(self);
return get_list(aspell_speller_session_word_list(speller));
}
/**
* Returns the main wordlist as array of strings.
* @return array of strings
*/
static VALUE aspell_main_wordlist(VALUE self) {
AspellSpeller *speller = get_speller(self);
return get_list(aspell_speller_main_word_list(speller));
}
/**
* Synchronize all wordlists with the current session.
*/
static VALUE aspell_save_all_wordlists(VALUE self) {
AspellSpeller *speller = get_speller(self);
aspell_speller_save_all_word_lists(speller);
check_for_error(speller);
return self;
}
/**
* Remove all words inside session.
*/
static VALUE aspell_clear_session(VALUE self) {
AspellSpeller *speller = get_speller(self);
aspell_speller_clear_session(speller);
check_for_error(speller);
return self;
}
/**
* Suggest words for the given misspelled word.
* @param word the misspelled word.
* @return array of strings.
*/
static VALUE aspell_suggest(VALUE self, VALUE word) {
AspellSpeller *speller = get_speller(self);
return get_list(aspell_speller_suggest(speller, StringValuePtr(word), -1));
}
/**
* Add a given word to the list of known words inside my private dictionary.
* You have to call aspell_save_all_wordlists to make sure the list gets persistent.
* @param word the word to add.
*/
static VALUE aspell_add_to_personal(VALUE self, VALUE word) {
AspellSpeller *speller = get_speller(self);
aspell_speller_add_to_personal(speller, StringValuePtr(word), -1);
check_for_error(speller);
return self;
}
/**
* Add a given word to the list of known words just for the lifetime of this object.
* @param word the word to add.
*/
static VALUE aspell_add_to_session(VALUE self, VALUE word) {
AspellSpeller *speller = get_speller(self);
aspell_speller_add_to_session(speller, StringValuePtr(word), -1);
check_for_error(speller);
return self;
}
/**
* Retrieve the value of a specific option.
* The options are listed inside
* Aspell::[DictionaryOptions|CheckerOptions|FilterOptions|RunTogetherOptions|MiscOptions|UtilityOptions]
* @param word the option as string.
*/
static VALUE aspell_conf_retrieve(VALUE self, VALUE key) {
AspellSpeller *speller = get_speller(self);
AspellConfig *config = aspell_speller_config(speller);
VALUE result = rb_str_new2(aspell_config_retrieve(config, StringValuePtr(key)));
if (aspell_config_error(config) != 0) {
rb_raise(cAspellError, aspell_config_error_message(config));
}
return result;
}
/**
* Retrieve the value of a specific option as list.
* @param word the option as string.
*/
static VALUE aspell_conf_retrieve_list(VALUE self, VALUE key) {
AspellSpeller *speller = get_speller(self);
AspellConfig *config = aspell_speller_config(speller);
AspellStringList * list = new_aspell_string_list();
AspellMutableContainer * container = aspell_string_list_to_mutable_container(list);
AspellStringEnumeration * els;
VALUE result = rb_ary_new();
const char *option_value;
//retrieve list
aspell_config_retrieve_list(config, StringValuePtr(key), container);
//check for error
if (aspell_config_error(config) != 0) {
char *tmp = strdup(aspell_config_error_message(config));
delete_aspell_string_list(list);
rb_raise( cAspellError, tmp);
}
//iterate over list
els = aspell_string_list_elements(list);
while ( (option_value = aspell_string_enumeration_next(els)) != 0) {
//push the option value to result
rb_ary_push(result, rb_str_new2(option_value));
}
//free list
delete_aspell_string_enumeration(els);
delete_aspell_string_list(list);
return result;
}
/**
* Simply dump config.
* Not very useful at all.
*/
static VALUE aspell_dump_config(VALUE self) {
AspellSpeller *speller = get_speller(self);
AspellConfig *config = aspell_speller_config(speller);
AspellKeyInfoEnumeration * key_list = aspell_config_possible_elements( config, 0 );
const AspellKeyInfo * entry;
while ( (entry = aspell_key_info_enumeration_next(key_list) ) ) {
printf("%20s: %s\n", entry->name, aspell_config_retrieve(config, entry->name) );
}
delete_aspell_key_info_enumeration(key_list);
return self;
}
/**
* Check a given word for correctness.
* @param word the word to check
* @return true if the word is correct, otherwise false.
*/
static VALUE aspell_check(VALUE self, VALUE word) {
AspellSpeller *speller = get_speller(self);
VALUE result = Qfalse;
int code = aspell_speller_check(speller, StringValuePtr(word), -1);
if (code == 1)
result = Qtrue;
else if (code == 0)
result = Qfalse;
else
rb_raise( cAspellError, aspell_speller_error_message(speller));
return result;
}
/**
* This method will check an array of strings for misspelled words.
* This method needs a block to work proper. Each misspelled word is yielded,
* a correct word as result from the block is assumed.
* Common use:
*
* a = Aspell.new(...)
* text = ...
* a.correct_lines(text) { |badword|
* puts "Error: #{badword}\n"
* puts a.suggest(badword).join(" | ")
* gets #the input is returned as right word
* }
*
* @param ary the array of strings to check.
* @result an array holding all lines with corrected words.
*/
static VALUE aspell_correct_lines(VALUE self, VALUE ary) {
VALUE result = ary;
if (rb_block_given_p()) {
//create checker
AspellSpeller *speller = get_speller(self);
AspellDocumentChecker * checker = get_checker(speller);
AspellToken token;
//some tmp values
VALUE vline, sline;
VALUE word, rword;
char *line;
int count=RARRAY_LEN(ary);
int c=0;
//create new result array
result = rb_ary_new();
//iterate over array
while(c do nothing
if(rword == Qnil) continue;
//check for string
if (TYPE(rword) != T_STRING) rb_raise(cAspellError, "Need a String to substitute");
//chomp the string
rb_funcall(rword, rb_intern("chomp!"), 0);
//empty string -> do nothing
if(strlen(StringValuePtr(rword)) == 0) continue;
//remember word for later suggestion
aspell_speller_store_replacement(speller, StringValuePtr(word), -1, StringValuePtr(rword), -1);
//substitute the word by replacement
rb_funcall(sline, rb_intern("[]="), 3, INT2FIX(token.offset+offset), INT2FIX(token.len), rword);
//adjust offset
offset += strlen(StringValuePtr(rword))-strlen(StringValuePtr(word));
//printf("replace >%s< with >%s< (offset now %d)\n", StringValuePtr(word), StringValuePtr(rword), offset);
}
//push the substituted line to result
rb_ary_push(result, sline);
c++;
}
//free checker
delete_aspell_document_checker(checker);
} else {
rb_raise(cAspellError, "No block given. How to correct?");
}
return result;
}
/**
* Remember a correction.
* This affects the suggestion of other words to fit this correction.
* @param badword the bad spelled word as string.
* @param badword the correction of the bad spelled word as string.
* @result self
*/
static VALUE aspell_store_replacement(VALUE self, VALUE badword, VALUE rightword) {
AspellSpeller *speller = get_speller(self);
aspell_speller_store_replacement(speller, StringValuePtr(badword), -1, StringValuePtr(rightword), -1);
return self;
}
/**
* Simple utility function to correct a file.
* The file gets read, content will be checked and write back.
* Please note: This method will change the file! - no backup and of course: no warranty!
* @param filename the name of the file as String.
* @exception Exception due to lack of read/write permissions.
*/
static VALUE aspell_correct_file(VALUE self, VALUE filename) {
if (rb_block_given_p()) {
VALUE content = rb_funcall(rb_cFile, rb_intern("readlines"), 1, filename);
VALUE newcontent = aspell_correct_lines(self, content);
VALUE file = rb_file_open(StringValuePtr(filename), "w+");
rb_funcall(file, rb_intern("write"), 1, newcontent);
rb_funcall(file, rb_intern("close"), 0);
} else {
rb_raise(cAspellError, "No block given. How to correct?");
}
return self;
}
/**
* Return a list of all misspelled words inside a given array of strings.
* @param ary an array of strings to check for.
* @return array of strings: words that are misspelled.
*/
static VALUE aspell_list_misspelled(VALUE self, VALUE ary) {
Check_Type(ary, T_ARRAY);
VALUE result = rb_hash_new();
//create checker
AspellSpeller *speller = get_speller(self);
AspellDocumentChecker * checker = get_checker(speller);
AspellToken token;
VALUE word, vline;
int count=RARRAY_LEN(ary);
int c=0;
//iterate over array
while(c