Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

activesupport: "police".singularize returns "polouse"

#594

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.

Reported by hqnguyen83 · July 10th, 2008 @ 05:18 PM

State: invalid
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Rick
    Rick
    • 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 :)

    July 10th, 2008 @ 05:28 PM

  2. hqnguyen83
    hqnguyen83

    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.

    July 10th, 2008 @ 05:43 PM

  3. Clemens Kofler
    Clemens Kofler

    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.

    July 10th, 2008 @ 06:05 PM

  4. hqnguyen83
    hqnguyen83

    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".

    July 10th, 2008 @ 07:59 PM

  5. Brian Armstrong
    Brian Armstrong

    I think hqnguyen83 has a valid point here.

    June 29th, 2009 @ 10:01 PM