0

I don't do any special setup other than the standard initialization of the PluralizationService.

PluralizationService ps = PluralizationService.CreateService(CultureInfo.GetCultureInfo("en-us"));

    // they may have said pigS, so we will singularize it
    if (ps.IsPlural(temp_word))
        temp_word = ps.Singularize(temp_word);```

My program allows players in my game to search for animals. When they search for goats or sheep or pigs the system works fine. the ps.Singularize function works correctly in all cases. (object classes are pig not pigs, sheep, and goat not goats.)

The fun starts when someone searches for horses. The ps.Singularize function returns hors. Is there some sort of rule I forgot to initialize or something or is this a straight-up bug.

I really don't want to have to special case each singularization failure.

Lei Yang
  • 3,970
  • 6
  • 38
  • 59
Level 42
  • 400
  • 2
  • 7
  • 2
    Looks like it's just not very good. https://stackoverflow.com/questions/41448588/pluralizationservices-changing-status-to-statu – AKX Jul 15 '21 at 13:27
  • Bear in mind the namespace of the type. It's vast majority of usage is for supplying *default* guesses for plurals/singulars, in a situation where *the developer can override it if it gets the guess wrong*. – Damien_The_Unbeliever Jul 15 '21 at 13:29
  • You could try if https://www.nuget.org/packages/Pluralize.NET.Core/ works better instead. PS despite the "Core" package name, the page says it's compatible with [.NET Standard 2.0](https://learn.microsoft.com/en-us/dotnet/standard/net-standard). – Peter B Jul 15 '21 at 13:35

1 Answers1

1

Thank you all for your tips and insights. I think I have found the answer, (although I would have preferred that function just work with common English words.) The solution is here:

A word about ICustomPluralizationMapping We can however, create our own singular and plural words. For that reason, we need the help of "ICustomPluralizationMapping" interface. It represents a collection of the singular and plural forms of words.

It has only one method

void AddWord(string singular, string plural) The method adds singular and plural forms of a word to the System.Data.Entity.Design.PluralizationServices.ICustomPluralizationMapping object. https://www.dotnetfunda.com/articles/show/2260/let-us-learn-pluralizationservices-of-net-40

So I can add any words that otherwise messup to the dictionary and not ugly-up my code with a bunch of special cases.

Level 42
  • 400
  • 2
  • 7