Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Humanized string to number #348

Open
mgibas opened this issue Nov 3, 2014 · 11 comments
Open

Humanized string to number #348

mgibas opened this issue Nov 3, 2014 · 11 comments
Labels

Comments

@mgibas
Copy link

mgibas commented Nov 3, 2014

Is there any chance to convert humanized string to int like this:

var value = "first".ToNumber() // value = 1;
var value = "second".ToNumber() // value = 2;
var value = "17th".ToNumber() // value = 17;

?

@hazzik
Copy link
Member

hazzik commented Nov 3, 2014

No

@MehdiK
Copy link
Member

MehdiK commented Nov 4, 2014

This is not currently possible but could be a useful feature. Thanks for the suggestion.

@MehdiK MehdiK changed the title [Question] Humanized string to number [Humanized string to number Nov 4, 2014
@MehdiK MehdiK changed the title [Humanized string to number Humanized string to number Nov 4, 2014
@MehdiK MehdiK added the jump in label Nov 4, 2014
@hazzik
Copy link
Member

hazzik commented Nov 4, 2014

I don't think that this is possible at all as Humanizer definitely not an
NLP library.

@MehdiK
Copy link
Member

MehdiK commented Nov 7, 2014

This isn't quite NLP. It's not very easy but it should be doable with a set of predefined rules, much like how the ToWords or Ordinalize work.

@mgibas
Copy link
Author

mgibas commented Nov 7, 2014

I implemented that already...kind of :)
In a time pressure my temporary solution looks like this (please don't judge I know its wrong :) ):

public static int ToNumber(this string @this)
{
      for (int i = 0; i < 1000000; i++)
      {
        if (i.ToOrdinalWords(new CultureInfo("en-US")).ToLower() == @this.ToLower())
          return i;
      }

      throw new ArgumentException(string.Format("Invalid quantifier provided: '{0}'", @this));
 }

I just hope that there is much cleaner solution for it :)

@MehdiK
Copy link
Member

MehdiK commented Nov 7, 2014

LOL. That's not what I had in mind.

I suggest you at least cache the entries so you don't have to calculate
them on each call.
On 07/11/2014 11:15 PM, "Maciej" [email protected] wrote:

I implemented that already...kind of :)
In a time pressure my temporary solution looks like this (please don't
judge I know its wrong :) ):

public static int ToNumber(this string @this)
{
for (int i = 0; i < 1000000; i++)
{
if (i.ToOrdinalWords(new CultureInfo("en-US")).ToLower() == @this.ToLower())
return i;
}

  throw new ArgumentException(string.Format("Invalid quantifier provided: '{0}'", @this));

}


Reply to this email directly or view it on GitHub
#348 (comment).

@jzebedee
Copy link

This is a problem that's been tackled before. I don't think it would be very difficult to add for English. What are some issues with supporting other cultures?

@MehdiK
Copy link
Member

MehdiK commented Nov 21, 2014

I agree @jzebedee. It's better to have a feature that can be done for all languages; that said, I honestly don't mind if there are features that are only supported in a couple of languages as long as English support is in there.

davidceto1 added a commit to davidceto1/Humanizer that referenced this issue Aug 15, 2018
@cptcrunchy
Copy link

Could we model a solution similar to what Numsense has done already?

var englishNumeral = Numeral.English.ToNumeral(42);
// englishNumeral is "forty-two"

@clairernovotny
Copy link
Member

If Numsense is doing this already, is there a further need to incorporate that into Humanizer? Why not just use Numsense directly?

@Trinitek
Copy link

The Numsense repository has recently been archived by its owner. See ploeh/Numsense#39.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants