Browse files

some fixes for DBIx::Class::Schema::Loader

  • Loading branch information...
1 parent a1e84d8 commit a3cd9ed9cbfc147755057a48fcb1b4cd93de5c23 @rkitover committed Mar 16, 2010
Showing with 54 additions and 19 deletions.
  1. +3 −0 Changes
  2. +13 −7 lib/Lingua/EN/Inflect/Phrase.pm
  3. +5 −12 t/basic.t
  4. +20 −0 t/lib/TestPhrase.pm
  5. +13 −0 t/schema-loader.t
View
3 Changes
@@ -1,4 +1,7 @@
Revision history for Lingua-EN-Inflect-Phrase
+0.02 2010-03-16 16:28:39
+ - some improvements and fixes for DBIx::Class::Schema::Loader
+
0.01 2010-03-16 15:16:16
- first release
View
20 lib/Lingua/EN/Inflect/Phrase.pm
@@ -12,7 +12,7 @@ Lingua::EN::Inflect::Phrase - Inflect short English Phrases
=cut
-our $VERSION = '0.01';
+our $VERSION = '0.02';
=head1 SYNOPSIS
@@ -50,7 +50,7 @@ Attempts to pluralizes a phrase unless already plural.
=cut
-my $NOUN = qr{(\S+)/NN(S)?};
+my $NOUN = qr{(\S+)/(NN|CD)};
my $tagger;
@@ -73,17 +73,23 @@ sub _inflect {
my $tagged = $tagger->get_readable($phrase);
-# noun before a preposition/conjunction
- if (my ($noun, $is_plural) = $tagged =~ m{$NOUN .*? /(?:CC|IN)}x) {
+# last noun before a preposition/conjunction
+ if (my ($noun) = $tagged =~ m{$NOUN (?!.*/(?:NN|CD|JJ).*/(?:CC|IN)) .* /(?:CC|IN)}x) {
+ my $is_plural = Lingua::EN::Inflect::Number::number($noun) ne 's';
my $inflected_noun = _inflect_noun($noun, $is_plural, $want_plural, $method);
- $phrase =~ s/$noun/$inflected_noun/ if $inflected_noun;
+ substr($tagged, $-[1], ($+[1] - $-[1])) = $inflected_noun if $inflected_noun;
+
+ ($phrase = $tagged) =~ s{/[A-Z]+}{}g;
}
# last noun
- elsif (($noun, $is_plural) = $tagged =~ m{$NOUN (?!.*/(?:NN|JJ))}x) {
+ elsif (($noun) = $tagged =~ m{$NOUN (?!.*/(?:NN|CD|JJ))}x) {
+ my $is_plural = Lingua::EN::Inflect::Number::number($noun) ne 's';
my $inflected_noun = _inflect_noun($noun, $is_plural, $want_plural, $method);
- $phrase =~ s/$noun/$inflected_noun/ if $inflected_noun;
+ substr($tagged, $-[1], ($+[1] - $-[1])) = $inflected_noun if $inflected_noun;
+
+ ($phrase = $tagged) =~ s{/[A-Z]+}{}g;
}
# fallback
else {
View
17 t/basic.t
@@ -1,9 +1,8 @@
use strict;
use warnings;
use Test::More;
-use Lingua::EN::Inflect::Phrase qw/to_PL to_S/;
-
-sub test_phrase;
+use lib 't/lib';
+use TestPhrase 'test_phrase';
# noun conjunction noun
test_phrase 'green egg and ham', 'green eggs and ham';
@@ -20,6 +19,9 @@ test_phrase 'prisoner of war', 'prisoners of war';
test_phrase 'book binding', 'book bindings';
test_phrase 'cable tie', 'cable ties';
+# noun x2
+test_phrase 'book book', 'book books';
+
# noun verb
test_phrase 'station visited', 'stations visited';
@@ -31,13 +33,4 @@ test_phrase 'green', 'greens';
done_testing;
-sub test_phrase {
- my ($singular, $plural) = @_;
-
- is to_PL($singular), $plural, "'$singular' pluralizes to '$plural'";
- is to_S($plural), $singular, "'$plural' singularizes to '$singular'";
- is to_PL($plural), $plural, "'$plural' unchanged when pluralized";
- is to_S($singular), $singular, "'$singular' unchanged when singularized";
-}
-
# vim:et sts=2 sw=2 tw=0:
View
20 t/lib/TestPhrase.pm
@@ -0,0 +1,20 @@
+package TestPhrase;
+use strict;
+use warnings;
+use Exporter 'import';
+use Test::More;
+use Lingua::EN::Inflect::Phrase qw/to_PL to_S/;
+
+our @EXPORT_OK = 'test_phrase';
+
+sub test_phrase {
+ my ($singular, $plural) = @_;
+
+ is to_PL($singular), $plural, "'$singular' pluralizes to '$plural'";
+ is to_S($plural), $singular, "'$plural' singularizes to '$singular'";
+ is to_PL($plural), $plural, "'$plural' unchanged when pluralized";
+ is to_S($singular), $singular, "'$singular' unchanged when singularized";
+}
+
+1;
+# vim:et sts=2 sw=2 tw=0:
View
13 t/schema-loader.t
@@ -0,0 +1,13 @@
+use strict;
+use warnings;
+use Test::More;
+use lib 't/lib';
+use TestPhrase 'test_phrase';
+
+# some tests for odd cases in DBIx::Class::Schema::Loader
+
+test_phrase 'loader test25 from', 'loader test25s from';
+
+done_testing;
+
+# vim:et sts=2 sw=2 tw=0:

0 comments on commit a3cd9ed

Please sign in to comment.