This project is archived and is in readonly mode.

#594 ✓invalid
hqnguyen83

activesupport: "police".singularize returns "polouse"

Reported by hqnguyen83 | July 10th, 2008 @ 05:18 PM | in 2.x

Linux, Ruby 1.8.5, activesupport 2.1.0

activesupport: "police".singularize returns "polouse"

The bug is at line 33 in inflections.rb for active support:

inflect.singular(/([m|l])ice$/i, '\1ouse')

should actually be

inflect.singular(/^([m|l])ice$/i, '\1ouse')

otherwise the pattern matches "police" and converts it to "polouse".

I hope this is the right place to post this.

Comments and changes to this ticket

  • Rick

    Rick July 10th, 2008 @ 05:28 PM

    • State changed from “new” to “invalid”

    Why are you calling singularize on a singular word? The inflector doesn't even attempt to guess what form a given word is. If you can come up with a brilliant fix for this that doesn't bloat the code or slow things down tremendously, be my guest :)

  • hqnguyen83

    hqnguyen83 July 10th, 2008 @ 05:43 PM

    It's not a singular word.

    "Hundreds of police deployed to curb J'lem anti-gay pride parade riots"

    This is the first result in google for "hundreds of police" (you can find more, I'm sure). "police" is often used as a plural word, especially in news articles.

    I'm also not quite sure how the suggested change would bloat the code. inflections.rb is a file that contains special cases for the inflector, and all I'm saying is that the regular expression that was supposed to catch "lice" and turn it into "louse" overmatches and catches "police" and turns it into "polouse". The change is a single character.

  • Clemens Kofler

    Clemens Kofler July 10th, 2008 @ 06:05 PM

    Mere curiosity: Why would you put something in an inflector method that shouldn't be pluralized/singularized anyway?

    However, you can fix this by just making it uncountable like e.g. water.

  • hqnguyen83

    hqnguyen83 July 10th, 2008 @ 07:59 PM

    I'm trying to extract entities from text, and when I run across a phrase like "hundreds of *noun*", I assume noun is in plural form, and "hundreds of police", without any trailing noun such as officer or man, is actually quite common, and in these cases, police really is plural.

    But enough of that I guess, since there seems to be disagreement over whether or not police is plural, singular, or neither. Consider the word blouse...activesupport will return "blice" for "blouse".pluralize. My point is, the lice/louse, mice/mouse pairing is the exception, rather than the rule, but that isn't how it is implemented. Right now it overmatches and applies these changes to any string that ends with "louse" or "lice".

  • Brian Armstrong

    Brian Armstrong June 29th, 2009 @ 10:01 PM

    I think hqnguyen83 has a valid point here.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages