2

Is there a library that can preform the following transformations?

"5 servings" => {num: 5, name: "servings"}
"five blocks" => {num: 5, name: "blocks"}
"five and a half teasopons of sugar" => {num: 5.5, name: "teaspoons of sugar"}
"four hundred milligrams of iron" => {num: 400, name: "milligrams of iron"}

It would be even better if the unit could be seperated out to.

2

There is a JavaScript library called nlp_compromise.

nlp_compromise is a cool way to use natural language in javascript.

This is an open source library and its source code is available here. According to your question, this library can detect a number, unit, and noun. Here are below examples that I taken from nlp_compromise documentation:

nlp_compromise = {
  value :{
    number: Number,      //fifty kilometers -> 50
    unit: String,        //fifty km -> km
    unit_name: String,   //fifty km -> kilometer
    measurement: String, //fifty km -> distance
  }
};

You also can get noun from a sentence. Please, take a look full API documentation here.

  • It does not accept fractions or decimals – 2426021684 May 15 '16 at 16:45
  • Also fails to parse 50 grams – 2426021684 May 15 '16 at 22:13
  • Yes, it is. This library is actively being developed right now. You can create an issue for that as your feature request. – meisyal Jul 19 '17 at 4:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.