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

[Suggestion]: Improvements on currency parser & rules. #1037

Open
MarketingPip opened this issue Sep 8, 2023 · 1 comment
Open

[Suggestion]: Improvements on currency parser & rules. #1037

MarketingPip opened this issue Sep 8, 2023 · 1 comment

Comments

@MarketingPip
Copy link
Contributor

MarketingPip commented Sep 8, 2023

The currency parser seems to need some work. Things like ("Five cents") or ("5 dollars") just return "5"...

Plus we should be adding rules for all things like "(one|five|ten) (dollar|dollars) bill".

That said - throwing this here! (Thinking this should be the new .get() ) etc...

function extractCurrencys(str) {
   let doc = nlp(str).money().json();
  let currencies = []
  
 for(let item in doc){
   let currency = doc[item]
   const unit = currency?.number?.unit;  // we need to replace units with only (dollars/cents, exchanges like USD etc...)
    const text = currency?.text;
   if(unit && text){
     currencies.push({text,unit})
   }
   
 }
  return currencies
}

console.log(extractCurrencys("$1 dollar to $2 dollar")) 

If you want to hack on this alone - you're more than welcome. Or you want to work on it together. More than fine.

@MarketingPip
Copy link
Contributor Author

Leaving this here for self - WIP:

function extractCurrencys(str) {
   let doc = nlp(str).money().json();
  let currencies = []
  
 for(let item in doc){
   let currency = doc[item]
   let unit = currency?.number?.unit;  // we need to replace units with only (dollars/cents, exchanges like USD etc...)
    const text = currency?.text;
   
   if(unit && !nlp(currency.number.unit).has("#Currency")){
     unit = null;
   }
   
   if(unit && text){
     currencies.push({text,unit})
   }
   
    if(!unit && text){
     currencies.push({text,unit:null})
   }
   
 }
  return currencies
}

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

No branches or pull requests

1 participant