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

Browserify compatibility? #189

Closed
ahamid opened this issue Sep 30, 2014 · 4 comments
Closed

Browserify compatibility? #189

ahamid opened this issue Sep 30, 2014 · 4 comments

Comments

@ahamid
Copy link

ahamid commented Sep 30, 2014

Hello, natural looks like a great library and I am investigating using it in the browser, via Browserify.
I noticed a couple of things:

    $ gulp browserify
    module "WNdb" not found from "./node_modules/natural/lib/natural/wordnet/wordnet.js"
    ...
    module "lapack" not found from "./node_modules/natural/node_modules/sylvester/lib/node-sylvester/matrix.js"

WNdb module consists of a (large ~10mb) blob of data, while lapack which is a native library, is being pulled in by sylvester.

My understanding is that WNdb is optional in natural and lapack is optional in sylvester (it uses detection to fallback on pure JS routines). It appears that the problem may be with Browserify attempting to eagerly retrieve these dynamic dependencies. I will pursue a remedy within Browserify and log this issue in case I find a workaround, but I am wondering in parallel whether first class browser/Browserify will be a goal for natural.

@ahamid
Copy link
Author

ahamid commented Sep 30, 2014

I believe I managed to solve this and at least tokenization appears to be working.
Leaving the breadcrumbs for others, this is simply a matter of using Browserify exclusions to exclude the 'WNdb' and 'lapack' nested dependencies:

var bundler = browserify(opts);
bundler.exclude('WNdb');
bundler.exclude('lapack');

Naturally WordNet will not be available, and presumably sylvester will fall back to pure JS routines.

@ahamid ahamid closed this as completed Sep 30, 2014
@kkoch986
Copy link
Member

Great, thanks for figuring that out! there was some discussion in #25 about the size of the library. Maybe this will help out some of them.

@tsjeyasarathi
Copy link

I tried suggestions in #25 but in vain. browserify creates a library but fs dependencies causes issues. Can someone help with the client side version of natural with classifier ?

@dspdog
Copy link

dspdog commented Dec 4, 2020

here is a client side version with most of the exports ~400kb before minifying; can use with var natural = require('natural');

https://gist.github.com/dspdog/105faa58bd8493c81f0b51bcc6046555

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

4 participants