plural

Converting plural to singular in a text file with Python

两盒软妹~` 提交于 2019-11-30 03:25:26
问题 I have txt files that look like this: word, 23 Words, 2 test, 1 tests, 4 And I want them to look like this: word, 23 word, 2 test, 1 test, 4 I want to be able to take a txt file in Python and convert plural words to singular. Here's my code: import nltk f = raw_input("Please enter a filename: ") def openfile(f): with open(f,'r') as a: a = a.read() a = a.lower() return a def stem(a): p = nltk.PorterStemmer() [p.stem(word) for word in a] return a def returnfile(f, a): with open(f,'w') as d: d =

Javascript pluralize a string

本小妞迷上赌 提交于 2019-11-29 23:51:30
In PHP, I use Kuwamoto's class to pluralize nouns in my strings. I didn't find something as good as this script in javascript except for some plugins. So, it would be great to have a javascript function based on Kuwamoto's class. http://kuwamoto.org/2007/12/17/improved-pluralizing-in-php-actionscript-and-ror/ Simple version (ES6): const maybePluralize = (count, noun, suffix = 's') => `${count} ${noun}${count !== 1 ? suffix : ''}`; Usage: maybePluralize(0, 'turtle'); // 0 turtles maybePluralize(1, 'turtle'); // 1 turtle maybePluralize(2, 'turtle'); // 2 turtles maybePluralize(3, 'fox', 'es'); /

How to pluralize “There is/are N object/objects”?

流过昼夜 提交于 2019-11-29 11:08:52
问题 Pluralizing a single word is simple: pluralize(@total_users, "user") But what if I want to print "There is/are N user/users": There are 0 users There is 1 user There are 2 users , i.e., how to pluralize a sentence ? 回答1: You can add a custom inflection for it. By default, Rails will add an inflections.rb to config/initializers . There you can add: ActiveSupport::Inflector.inflections do |inflect| inflect.irregular "is", "are" end You will then be able to use pluralize(@total_users, "is") to

i18n Pluralization

橙三吉。 提交于 2019-11-28 15:00:00
I want to be able to translate pluralized strings in i18n in rails. A string can be : You have 2 kids or You have 1 kid I know that I can use pluralize helper method, but I want to embed this in i18n translations so that I don't have to mess up with my views at any point in the future. I read that :count is somehow used in translations for plural, but I can't find any real resources on how it gets implemented. Notice that I know that I can pass a variable in a translation string. I also tried something like : <%= t 'misc.kids', :kids_num => pluralize(1, 'kid') %> Which works fine, but has a

Enum Naming Convention - Plural

老子叫甜甜 提交于 2019-11-28 03:02:43
I'm asking this question despite having read similar but not exactly what I want at C# naming convention for enum and matching property I found I have a tendency to name enums in plural and then 'use' them as singular, example: public enum EntityTypes { Type1, Type2 } public class SomeClass { /* some codes */ public EntityTypes EntityType {get; set;} } Of course it works and this is my style, but can anyone find potential problem with such convention? I do have an "ugly" naming with the word "Status" though: public enum OrderStatuses { Pending, Fulfilled, Error, Blah, Blah } public class

Internationalising sentences with two plural words

廉价感情. 提交于 2019-11-27 23:58:06
Using gettext how should a sentence with multiple numeric variables be made translatable? ngettext only takes one number as the plural parameter. The permutations that should be allowed in the below sentence are "adult and child", "adults and child", "adult and children" and "adults and children". "from #AVAILABILITYFROM to #AVAILABILITYTO for #NUMADULTS adult and #NUMCHILDREN child" Grammar can be very complex in some other languages than English and you should be aware that is practical impossible to generate correct complex sentences using your approach. Remember that multiple variables and

Plural definition is ignored for zero quantity

梦想与她 提交于 2019-11-27 22:42:01
I use plurals to compile a quantity string for an Android application. I follow exactly what one can find in the tutorials: res.getQuantityString( R.plurals.number_of_comments, commentsCount, commentsCount); Here is the definition of the plurals: <?xml version="1.0" encoding="utf-8"?> <resources> <plurals name="number_of_comments"> <item quantity="zero">No comments</item> <item quantity="one">One comment</item> <item quantity="other">%d comments</item> </plurals> </resources> Interesting enough, the output string is odd to what I definied: commentsCount = 0 => "0 comments" commentsCount = 1 =>

Enum Naming Convention - Plural

最后都变了- 提交于 2019-11-27 05:01:29
问题 I'm asking this question despite having read similar but not exactly what I want at C# naming convention for enum and matching property I found I have a tendency to name enums in plural and then 'use' them as singular, example: public enum EntityTypes { Type1, Type2 } public class SomeClass { /* some codes */ public EntityTypes EntityType {get; set;} } Of course it works and this is my style, but can anyone find potential problem with such convention? I do have an "ugly" naming with the word

Internationalising sentences with two plural words

ぃ、小莉子 提交于 2019-11-26 23:23:30
问题 Using gettext how should a sentence with multiple numeric variables be made translatable? ngettext only takes one number as the plural parameter. The permutations that should be allowed in the below sentence are "adult and child", "adults and child", "adult and children" and "adults and children". "from #AVAILABILITYFROM to #AVAILABILITYTO for #NUMADULTS adult and #NUMCHILDREN child" 回答1: Grammar can be very complex in some other languages than English and you should be aware that is

Plural definition is ignored for zero quantity

与世无争的帅哥 提交于 2019-11-26 23:12:16
问题 I use plurals to compile a quantity string for an Android application. I follow exactly what one can find in the tutorials: res.getQuantityString( R.plurals.number_of_comments, commentsCount, commentsCount); Here is the definition of the plurals: <?xml version="1.0" encoding="utf-8"?> <resources> <plurals name="number_of_comments"> <item quantity="zero">No comments</item> <item quantity="one">One comment</item> <item quantity="other">%d comments</item> </plurals> </resources> Interesting