Re: [RDBO] how to pluralize properly with Rose::DB::Object::Loader?

2007-12-24 Thread Ted Zlatanov
On Fri, 21 Dec 2007 20:53:55 -0500 John Siracusa [EMAIL PROTECTED] wrote: 

JS On 12/21/07 8:39 PM, Adam Prime wrote:
 sub init_convention_manager {
 my $self = shift;
 
 my $cm = $self-SUPER::init_convention_manager(@_);
 
 $cm-singular_to_plural_function(\Lingua::EN::Inflect::Number::to_PL);
 $cm-plural_to_singular_function(\Lingua::EN::Inflect::Number::to_S);
 return $cm;
 }

JS Also, FWIW, remember that the arguably better and more straightforward way
JS to do this is to make your own ConventionManager subclass and simply
JS override the singular_to_plural() and plural_to_singular() methods.  (Then
JS set the default convention_manager_class() name in your Metadata subclass,
JS yada.)

JS The technique shown above (and also used as an example in the docs) is
JS basically just a way to avoid making a subclass if you just want to override
JS the singular/plural methods.  But in the long run, making a proper
JS ConventionManager subclass is probably the best bet.

For my particular situation, maybe.  As a general solution, a proper
plural_to_singular function would be the right solution, and would save
everyone's time, not just mine.

Maybe Rose::DB::Object::Loader could have an interactive mode where it
asks you what's the singular/plural of each table name.  This could be
implemented in the ConventionManager or at the RDBO::Loader level.

Ted

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object


Re: [RDBO] how to pluralize properly with Rose::DB::Object::Loader?

2007-12-24 Thread Ted Zlatanov
On Fri, 21 Dec 2007 20:39:18 -0500 Adam Prime [EMAIL PROTECTED] wrote: 

AP I'm not sure if this will help, but i had a similar sort of problem with 
AP a table called 'Category'.  this is my loader (which works).  I can't 
AP remember where this is originally sourced from unfortunately (but i 
AP would suspect the list archives)

AP this is my DB::Metadata.pm

AP package EatLocal::DB::Metadata;

AP use Rose::DB::Object::Metadata;
AP our @ISA = qw(Rose::DB::Object::Metadata);

AP use Lingua::EN::Inflect::Number;

AP sub init_convention_manager {
AP  my $self = shift;

AP  my $cm = $self-SUPER::init_convention_manager(@_);

AP  $cm-singular_to_plural_function(\Lingua::EN::Inflect::Number::to_PL);
AP  $cm-plural_to_singular_function(\Lingua::EN::Inflect::Number::to_S);
AP  return $cm;
AP }

AP 1;

This should definitely go in the docs, thanks for pointing me to the
right module!  I looked on CPAN for 'singular', FWIW, but didn't find
this one.

Here's my current plural_to_singular setup:

 $cm-plural_to_singular_function(sub
  {
   my $word = shift @_;
   return $word if $word eq 'fortis'; # the one 
exception
   return 
Lingua::EN::Inflect::Number::to_S($word);
  });

Thanks
Ted

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object


Re: [RDBO] how to pluralize properly with Rose::DB::Object::Loader?

2007-12-21 Thread Hans Dieter Pearcey
On Fri, Dec 21, 2007 at 02:56:07PM -0600, Ted Zlatanov wrote:
 I couldn't find an example in the docs of how to set up
 Rose::DB::Object::Loader with a properly pluralizing convention manager.
 I tried the following, but I keep getting a class called Currencie
 from a table called currencies for example.  I must be missing
 something.

  # Set the new singular-to-plural function
  $cm-singular_to_plural_function(\Lingua::EN::Inflect::PL);

you want to change plural_to_singular_function (currencies - Currency), not
the other way around.

hdp.

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object


Re: [RDBO] how to pluralize properly with Rose::DB::Object::Loader?

2007-12-21 Thread John Siracusa
On 12/21/07 4:21 PM, Ted Zlatanov wrote:
 On Fri, 21 Dec 2007 15:59:58 -0500 Hans Dieter Pearcey [EMAIL PROTECTED] 
 wrote:
 HDP On Fri, Dec 21, 2007 at 02:56:07PM -0600, Ted Zlatanov wrote:
 I couldn't find an example in the docs of how to set up
 Rose::DB::Object::Loader with a properly pluralizing convention manager.

Your setup looks right to me, but...

 I tried the following, but I keep getting a class called Currencie
 from a table called currencies for example.  I must be missing
 something.

...apparently what you really need is a properly *singularizing* convention
manager.  Since your tables are plural and you want singular classes, you
need some code that converts English plurals to singular.  But...

 Unfortunately Lingua::EN::Inflect only goes from singular to plural.

...so there you have it.

 Any advice or am I stuck making my own word lists?

It shouldn't be too hard to make a reasonable plural-to-singular subroutine
that handles all of your cases and maybe a few more :)

-John



-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object


Re: [RDBO] how to pluralize properly with Rose::DB::Object::Loader?

2007-12-21 Thread Adam Prime
Ted Zlatanov wrote:
 I couldn't find an example in the docs of how to set up
 Rose::DB::Object::Loader with a properly pluralizing convention manager.
 I tried the following, but I keep getting a class called Currencie
 from a table called currencies for example.  I must be missing
 something.

I'm not sure if this will help, but i had a similar sort of problem with 
a table called 'Category'.  this is my loader (which works).  I can't 
remember where this is originally sourced from unfortunately (but i 
would suspect the list archives)

this is my DB::Metadata.pm

package EatLocal::DB::Metadata;

use Rose::DB::Object::Metadata;
our @ISA = qw(Rose::DB::Object::Metadata);

use Lingua::EN::Inflect::Number;

sub init_convention_manager {
 my $self = shift;

 my $cm = $self-SUPER::init_convention_manager(@_);

 $cm-singular_to_plural_function(\Lingua::EN::Inflect::Number::to_PL);
 $cm-plural_to_singular_function(\Lingua::EN::Inflect::Number::to_S);
 return $cm;
}

1;

Adam

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object