axa-group / nlp.js

An NLP library for building bots, with entity extraction, sentiment analysis, automatic language identify, and so more
MIT License
6.27k stars 620 forks source link

node-nlp-rn not fully supporting rn? #989

Open Macilias opened 3 years ago

Macilias commented 3 years ago

Describe the bug I'm trying to follow your example for react-native, and after importing import { NlpManager } from 'node-nlp-rn'; from the rn package and calling the train method on the manager (after adding the documents and answers as in the example) I get the following warning:

 WARN  Possible Unhandled Promise Rejection (id: 0):
TypeError: process.hrtime is not a function. (In 'process.hrtime()', 'process.hrtime' is undefined)

Secondly: While I still get the answer form manager.process I wonder how to obtain the types for the package to satisfy:

Could not find a declaration file for module 'node-nlp-rn'. '...node_modules/node-nlp-rn/lib/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/node-nlp-rn` if it exists or add a new declaration (.d.ts) file containing `declare module 'node-nlp-rn';`

Is there a type package planned or am I missing something? Thanks!

To Reproduce Steps to reproduce the behavior:

  1. Go to https://www.npmjs.com/package/node-nlp-rn
  2. Try to run in the current React-Native environment

Expected behavior I would expect no warnings

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

zachrussell12 commented 2 years ago

I was able to fix this problem, sort of.

I went to the JS file where this error was occurring, I believe it’s in node-nlp-rn/lib/classifiers/neural-network.js, and made some changes. Comment out:

const hrstart = process.hrtime();

and replace it with

const hrstart = performance.now();

Then you’ll need to go down a few lines and comment out the hrend, and replace it with:

const hrend = process.now() - hrstart;

It’s not as precise, but it’ll let it run on RN.