Skip to content

Commit

Permalink
import Lingua-EN-Numbers 0.02 from CPAN
Browse files Browse the repository at this point in the history
git-cpan-module:   Lingua-EN-Numbers
git-cpan-version:  0.02
git-cpan-authorid: SBURKE
git-cpan-file:     authors/id/S/SB/SBURKE/Lingua-EN-Numbers-0.02.tar.gz
  • Loading branch information
Sean M. Burke authored and schwern committed Dec 12, 2009
1 parent b3bcf43 commit d6880f4
Show file tree
Hide file tree
Showing 13 changed files with 285 additions and 143 deletions.
27 changes: 27 additions & 0 deletions ChangeLog
@@ -0,0 +1,27 @@
Revision history for this dist... // Time-stamp: "2005-01-01 17:08:39 AST"

2005-01-01 Sean M. Burke sburke@cpan.org
* Release 0.02 -- bugfix

* Taking over maintenance from

* Fixed various bugs to do with 0.

* Corrected "Fourty" to "Forty"

* Added some tests, generally rearraged the dist.

* Known problems:
Why Is Everything Titlecased?
British people don't use billiard, etc., anymore
Pointless use of OO
"Four Hundred Zero"

* TODO: Rewrite from scratch


1999-05-16 - Stephen Pandich steve@pandich.com

* Release 0.01

* original version
6 changes: 0 additions & 6 deletions Changes

This file was deleted.

28 changes: 0 additions & 28 deletions INSTALL

This file was deleted.

15 changes: 9 additions & 6 deletions MANIFEST
@@ -1,7 +1,10 @@
README
INSTALL
Changes
MANIFEST
ChangeLog
lib/Lingua/EN/Numbers.pm
Makefile.PL
test.pl
Numbers.pm
MANIFEST
MANIFEST.SKIP
README
t/01_about_verbose.t
t/10_old_stuff.t
t/20_main_integers.t
META.yml Module meta-data (added by MakeMaker)
7 changes: 7 additions & 0 deletions MANIFEST.SKIP
@@ -0,0 +1,7 @@
^MANIFEST\.bak$
Makefile(\.old)?$
\.rej$
CVS
blib
~

10 changes: 10 additions & 0 deletions META.yml
@@ -0,0 +1,10 @@
# http://module-build.sourceforge.net/META-spec.html
#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
name: Lingua-EN-Numbers
version: 0.02
version_from: lib/Lingua/EN/Numbers.pm
installdirs: site
requires:

distribution_type: module
generated_by: ExtUtils::MakeMaker version 6.17
20 changes: 11 additions & 9 deletions Makefile.PL
@@ -1,14 +1,16 @@
# This perl script makes the Makefile
# This -*-perl-*- script writes the Makefile for installing this distribution.
#
# See "perldoc perlmodinstall" or "perldoc ExtUtils::MakeMaker" for
# info on how to control how the installation goes.
#
# Time-stamp: "2005-01-01 16:45:20 AST"

require 5.004;
use strict;
use ExtUtils::MakeMaker;
BEGIN { require 5.004 }

WriteMakefile(
'NAME' => 'Lingua::EN::Numbers',
'VERSION_FROM' => "Numbers.pm",
'ABSTRACT' => 'Converts numbers into their text equivalents.',
'AUTHOR' => 'Stephen Pandich (pandich@yahoo.com)',
'PM' => {
'Numbers.pm' => '${INST_LIBDIR}/Numbers.pm'
}
'NAME' => 'Lingua::EN::Numbers',
'VERSION_FROM' => 'lib/Lingua/EN/Numbers.pm', # finds $VERSION
'dist' => { COMPRESS => 'gzip -6f', SUFFIX => 'gz', },
);
30 changes: 1 addition & 29 deletions README
@@ -1,30 +1,2 @@
This is Lingua::EN::Numbers, a module for converting numbers into
their text equivalents.

As I am an American, I had to wing the British aspects of this
module: any suggestions by natives would make me say:

"Thanks a Milliard!!!"


!!! EARLY ALPHA WARNING !!!

This package is hot-off-the-keyboard and has not be tested in any
significant fashion. Please contact me with all comments, suggestions,
and bug reports. This is EARLY ALPHA software.


See the INSTALL file for installation notes.


AUTHOR

Stephen Pandich
pandich@yahoo.com


-------------------------------------------------------------
Copyright (c) 1999 Stephen Pandich. All rights reserved.

This package is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
their text equivalents, like turning 42 into "forty-two".
118 changes: 80 additions & 38 deletions Numbers.pm → lib/Lingua/EN/Numbers.pm
@@ -1,36 +1,25 @@

package Lingua::EN::Numbers;
require 5.004;
require 5.004; # Time-stamp: "2005-01-01 17:11:06 AST"

require Exporter;
@ISA = qw(Exporter);

use Carp;
use strict qw(vars);
use vars qw(
@EXPORT
@EXPORT_OK
$VERSION
$MODE
%INPUT_GROUP_DELIMITER
%INPUT_DECIMAL_DELIMITER
%OUTPUT_BLOCK_DELIMITER
%OUTPUT_GROUP_DELIMITER
%OUTPUT_NUMBER_DELIMITER
%OUTPUT_DECIMAL_DELIMITER
%NUMBER_NAMES
%SIGN_NAMES
$TRUE
$FALSE
$SIGN_POSITIVE
$SIGN_NEGATIVE
@EXPORT @EXPORT_OK $VERSION
$MODE
%INPUT_GROUP_DELIMITER %INPUT_DECIMAL_DELIMITER %OUTPUT_BLOCK_DELIMITER
%OUTPUT_GROUP_DELIMITER %OUTPUT_NUMBER_DELIMITER
%OUTPUT_DECIMAL_DELIMITER %NUMBER_NAMES %SIGN_NAMES
$TRUE $FALSE $SIGN_POSITIVE $SIGN_NEGATIVE
);

BEGIN { *DEBUG = sub () {0} unless defined &DEBUG } # setup a DEBUG constant

BEGIN {
$VERSION = '0.01';
$VERSION = '0.02';

# Exporter Stuff
@EXPORT = qw();
Expand Down Expand Up @@ -114,7 +103,7 @@ BEGIN {
19 => 'Nineteen',
20 => 'Twenty',
30 => 'Thirty',
40 => 'Fourty',
40 => 'Forty',
50 => 'Fifty',
60 => 'Sixty',
70 => 'Seventy',
Expand Down Expand Up @@ -203,7 +192,7 @@ BEGIN {
#################################################################
sub import {
my ($module, $tag) = @_;
if (($tag eq "American") || ($tag eq "British")) {
if ($tag and ($tag eq "American") || ($tag eq "British")) {
$MODE = $tag;
}
else {
Expand Down Expand Up @@ -248,16 +237,25 @@ sub string_to_number {
# Strip out delimiters
$numberString =~ s/\Q$INPUT_GROUP_DELIMITER{$MODE}\E//g;

DEBUG > 3 and print " Parsing numberstring [$numberString]\n";

my $sign = $SIGN_POSITIVE;
if ($numberString =~ /^-/) {
$numberString =~ s/^-//;
$sign = $SIGN_NEGATIVE;
if ($numberString =~ s/^-//) {
$sign = $SIGN_NEGATIVE if $numberString =~ m/[1-9]/;
# (but drop the sign on -0, -0.000, -.00000, etc)
}
$numberString =~ s/^0+//g;

if( $numberString =~ m/^0+$/s ) { $numberString = '0' }
elsif( $numberString =~
m/^0+\Q$INPUT_DECIMAL_DELIMITER{$MODE}\E/s ) { } # allow a predecimal zero
else {
# Otherwise, strip any leading zeroes
$numberString =~ s/^0+//g;
}

my $number = '';
my $decimal = '';
if ($numberString =~ /(^.+)\Q$INPUT_DECIMAL_DELIMITER{$MODE}\E(.+$)/) {
if ($numberString =~ /^(.*)\Q$INPUT_DECIMAL_DELIMITER{$MODE}\E(.+$)/) {
($number, $decimal) = ($1, $2);
} else {
$number = $numberString;
Expand Down Expand Up @@ -365,24 +363,40 @@ sub do_get_string {

my @blockStrings;
my $number = $self->{'string_data'}{$block};

DEBUG > 4 and print " Components: ", join(" ", map("$_",
sort {$b <=> $a } keys %$number)), "\n";

foreach my $component(sort {$b <=> $a } keys %$number) {
my $magnitude = $$number{$component}{'magnitude'};
my $magnitude = $$number{$component}{'magnitude'} || '';
my $factor = $$number{$component}{'factor'};

my @strings;
map { push @strings, join($OUTPUT_NUMBER_DELIMITER{$MODE}, @$_) } @$factor;
next unless $factor and @$factor;
my @strings = map join($OUTPUT_NUMBER_DELIMITER{$MODE}, @$_), @$factor;

DEBUG > 5 and print " Strings: [@strings] Magnitude[$magnitude] Factor[@{$$factor[0]}]\n";

my $string = join($OUTPUT_GROUP_DELIMITER{$MODE}, @strings) . ' ' . $magnitude;
push @blockStrings, $string;
}

DEBUG > 4 and print " Blockstrings[", map("<$_>", @blockStrings), "]\n";

my $blockString = join($OUTPUT_BLOCK_DELIMITER{$MODE}, @blockStrings);
my $blockString = join($OUTPUT_BLOCK_DELIMITER{$MODE}, @blockStrings)
|| $NUMBER_NAMES{$MODE}{0};
$blockString .= ' ';

DEBUG > 4 and print " Blockstring[$blockString]\n";

return $blockString;
}


sub parse {
my ($self, $numberString) = @_;

DEBUG > 2 and print " Got number string to parse: [",
defined($numberString) ? $numberString : 'undef', "]\n";

if (! defined $self || ! $self) {
return $FALSE;
}
Expand All @@ -393,9 +407,11 @@ sub parse {
$self->{'numeric_data'}{'decimal'} = $decimal;
$self->{'numeric_data'}{'sign'} = $sign;

if (defined $number && $number) {
$self->{'string_data'}{'number'} = &parse_number($number);
$self->{'string_data'}{'sign'} = $SIGN_NAMES{$MODE}{$sign};
DEBUG > 2 and print " Got num[$number] dec[$decimal] sign[$sign]\n";

if (defined $number) {
$self->{'string_data'}{'number'} = &parse_number($number);
$self->{'string_data'}{'sign'} = $SIGN_NAMES{$MODE}{$sign};
}

if (defined $decimal && $decimal) {
Expand All @@ -417,13 +433,17 @@ sub get_string {
if ($self->{'string_data'}{'decimal'}) {
push @strings, $self->do_get_string('decimal');
}

shift @strings if @strings > 1 and $strings[0] eq $NUMBER_NAMES{$MODE}{0};
# don't need the zero on "zero point five"

my $string = join($OUTPUT_DECIMAL_DELIMITER{$MODE}, @strings);
if ($self->{'string_data'}{'sign'}) {
$string = $self->{'string_data'}{'sign'} . " $string";
}

$string =~ s/\s+$//;
$string =~ s/\s+/ /g;
return $string;
}

Expand Down Expand Up @@ -457,6 +477,9 @@ Lingua::EN::Numbers - Converts numeric values into their English string equivale
print "N = " . $n->get_string . "\n";
prints:
N = Negative One Thousand, Two-Hundred Eighty-One
=head1 REQUIRES
Expand Down Expand Up @@ -600,10 +623,29 @@ A constant indicating the the current number is negative.
=back
=head1 COPYRIGHT
Copyright (c) 2005, Sean M. Burke
Copyright (c) 1999, Stephen Pandich.
This library is free software; you can redistribute it and/or modify
it only under the terms of version 2 of the GNU General Public License
(L<perlgpl>).
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.
(But if you have any problems with this library, I ask that you let
me know.)
=head1 AUTHOR
Stephen Pandich, pandich@yahoo.com
Original author: Stephen Pandich, pandich@yahoo.com
Current maintainer: Sean M. Burke, sburke@cpan.org
=cut

0 comments on commit d6880f4

Please sign in to comment.