savoirfairelinux / num2words

Modules to convert numbers to words. 42 --> forty-two
GNU Lesser General Public License v2.1
814 stars 488 forks source link

grammatical gender #221

Open r1fl opened 5 years ago

r1fl commented 5 years ago

first of all, awesome project! i couldnt believe it when i saw the amount of languages you support!

--

in hebrew, as in some other languages that have grammatical gender, the word expressing the number can differ based on the context of the sentence because of grammatical gender.

e.g. "1 boy" translates to "ילד אחד" while "one girl" translates to "ילדה אחת". the "אחד" \ "אחת" is the number's word.

although i am not sure if this problem is to be cared for, as not all languages have grammatical gender, adding an optional gender="masc\fem" (for masculine and feminine) parameter. to declare the context of the sentence, could be a solution.

if needed, I could do the implementation of Hebrew.

https://en.wikipedia.org/wiki/Grammatical_number#Adjectives_and_determiners mentions French, German, Italian, Spanish, Portuguese in regards to this.

zenogantner commented 5 years ago

Good point. For some languages, there are even more things to consider.

For example in German, in addition to gender, the case (nominative, genitive, dative, accusative) also influences the form of the cardinal number: "1 boy" can be "ein Junge", "eines Jungen", "einem Jungen" or "einen Jungen" ...

And, for ordinal numbers, it makes a difference whether an article is used or not: 1st boy can be "erster Junge" or "der erste Junge" ... plus cases and gender ...

erozqba commented 5 years ago

@r1fl @zenogantner all contributions are welcome! It's not the first time someone suggests this feature. Please create a PR of the implementation for Hebrew and Germany. I suggest that you also take into account the command line functionality when implementing this optional gender parameter.

zenogantner commented 5 years ago

I did some thinking -- for ordinals everything could be achieved by attaching additional letters to the end of the string. For cardinals, only "1" is affected for German.

So the implementation would be quite simple.

I would suggest the following additional arguments (with possible values for German, defaults are None unless highlighted in bold face):

Will do some more thinking, and maybe include French, Italian, Spanish, Portuguese in addition to German...

cassiotbatista commented 5 years ago

@zenogantner For Brazilian Portuguese, only ordinal numbers differ in gender (and a few cardinal (I can only think of dois -> duas), but it's not as much as the ordinal ones). You just need to changed one single letter at the end of each word converted: o to a. E.g.:

./num2words 111 -l pt_BR -t ordinal
centésimo décimo primeiro

A conversion for female gender would therefore produce "centésima décima primeira".

I'm actually tempted to create a pull request but I'll wait for someone to first implement the gender flag/parameter to be passed as command line arg :smiley:

zenogantner commented 5 years ago

I do not have the time/energy this weekend, let's see whether I can make time at some point. If anybody else does it, great!

eyaler commented 1 year ago

@r1fl This PR bring hebrew gender (as well as many more features) https://github.com/savoirfairelinux/num2words/pull/490