What do you think this module/function should be called? Right now, I'm using chump but I'm also considering champ, chimp and chmop...
=head1 NAME
chump - like "chomp" but also checks your spelling
=head1 SYNOPSIS
use 5.010;
use chump lang => 'en';
while (<>)
{
chump;
say $_;
last unless $_;
}
=head1 DESCRIPTION
The chump package exports a function C<chump> which acts just like the
Perl built-in C<chomp> (i.e. removes a trailing new line character) bu
+t
also corrects any spelling mistakes in the string.
=head2 Functions
=over
=item * C<< chump($string) >>
Modifies C<$string> in-place, removing a trailing new line character i
+f
there is one, and correcting any spelling mistakes.
=back
=head2 Import Options
Any options passed on the "use" line are passed on to Text::Aspell.
Options are lexically scoped, and scopes are not cumulative.
{
use chump lang => 'fr', mode => 'email';
my $line = <>;
chump $line; # check spelling in French.
{
use chump lang => 'en';
my $line2 = <>;
chump $line2; # check spelling in English
# but not in email mode.
}
my $line3 = <>;
chump $line3; # in French and email mode again.
}
=head2 Unimport
Do not unimport the module.
=cut
package chump;
use JSON qw//;
use Text::Aspell;
use strict 'subs', 'vars';
sub import
{
my $class = shift;
my $caller = caller;
*{"$caller\::chump"} = \&chump;
if (@_)
{
$^H{+__PACKAGE__} = _serialize_options(@_);
}
}
sub unimport
{
warn "You think you no chump?\n";
}
sub _serialize_options
{
JSON::to_json({ @_ });
}
sub _deserialize_options
{
return unless $_[0];
my $r = JSON::from_json($_[0]);
%{ $r || {} };
}
sub chump (_)
{
my $spell = Text::Aspell->new;
my @caller = caller(0);
my %opts = _deserialize_options($caller[10]{+__PACKAGE__});
foreach my $key (keys %opts)
{
$spell->set_option($key, $opts{$key});
}
my @parts = split /([[:alpha:]]+)/, $_[0];
my $count;
for my $i (0 .. $#parts)
{
if ($parts[$i] =~ /^[[:alpha:]]+$/)
{
next if $spell->check($parts[$i]);
my ($guess) = $spell->suggest($parts[$i]);
$guess = '?' x (length $parts[$i]) unless defined $guess;
$parts[$i] = $guess;
$count++;
}
}
$_[0] = join q{}, @parts;
return $count + chomp $_[0];
}
__PACKAGE__
Re: RFC: Best name for this module?
by moritz (Cardinal) on Feb 27, 2012 at 13:15 UTC
|
Is this meant as a joke? If yes, Acme::Chump.
If not, I'd consider to just do the spelling correction, and name it Text::Spelling::AutoCorrect.
| [reply] [d/l] [select] |
|
|
| [reply] |
Re: RFC: Best name for this module?
by davido (Cardinal) on Feb 27, 2012 at 13:42 UTC
|
I wouldn't conflate the two purposes. The spell-corrector on its own might have some value, but adding chomp functionality to it diminishes its generality. Also, what is the use case for a return value consisting of the number of words corrected plus the number of characters that chomp removed?
The spell-corrector itself is a big leap of faith. I find that spell-checkers frequently guess incorrectly, particularly in documents that contain a mixture of prose and code or other technical text. While it might be great for the simple case, it's hard to imagine what that simple case would be.
| [reply] |
Re: RFC: Best name for this module?
by bitingduck (Deacon) on Feb 27, 2012 at 16:42 UTC
|
I would expect "chmop" to change permissions, and "chimp" to randomize spelling, or at least insert some Shakespeare. | [reply] |
|
|
Let's name it "ook" instead of "chimp "then, to avoid the confusion.
| [reply] |
Re: RFC: Best name for this module?
by JavaFan (Canon) on Feb 27, 2012 at 15:01 UTC
|
I don't care how you name it, I wouldn't use it.Now, if there was a call that combined chomping, spelling correction, reversing, opening a file, and sleeping into one, now that would be useful. | [reply] |
Re: RFC: Best name for this module?
by Anonymous Monk on Feb 27, 2012 at 21:45 UTC
|
"Combination hookah and coffee maker." Does it also make Julienne fries? | [reply] |
Re: RFC: Best name for this module?
by Anonymous Monk on Feb 28, 2012 at 02:45 UTC
|
The function name should be chuck as in spell-chucker | [reply] |
Re: RFC: Best name for this module?
by locked_user sundialsvc4 (Abbot) on Feb 28, 2012 at 20:51 UTC
|
Y’know, I quite honestly think that you ought to reconsider this module, before releasing anything, because it appears to me to be a wedge of two rather unrelated concepts. (Do they, in fact, “fit” together? .. if so, how?) I just do not now have a warm, fuzzy feeling about this module in the sense that I would actually use it or want to use it. Since it goes without saying that you do want to produce a genuinely useful contribution to the Community, perhaps this bit of “advance market-research” might be useful. I simply think that perhaps you should “smoke it over a little bit more... first.” I think it needs a little more time on the stove.
| |
Re: RFC: Best name for this module?
by pvaldes (Chaplain) on Mar 06, 2012 at 22:23 UTC
|
Definitely, I would not choose chimp
The 'i' and 'o' keys are next in many keyboards, so you could end typing chimp when you want use chomp and ending with a similar function (but not what you want) without a single warning (or a wrong warning pointing to a missing module) or type chomp instead chimp and concluding that the module isn't working for some reason. I find this error prone and difficult to debug.
| [reply] |
Re: RFC: Best name for this module?
by Xiong (Hermit) on Mar 06, 2012 at 18:27 UTC
|
I upvoted your post because I'm glad you asked for comment before working on this module. Like others in this thread, I don't see the value of the combined effects. There are a number of spell-check-related modules; I'm not sure how this improves over the Text::Aspell it uses. Sorry.
I'm not the guy you kill, I'm the guy you buy. —Michael Clayton
| [reply] |
|
|
| [reply] |
|
|