Giter VIP home page Giter VIP logo

Comments (27)

keplersj avatar keplersj commented on August 28, 2024 3

Sorry for the update from 5-years in the future, but I found a solution for my derivative of this problem with Webpack (through Gatsby).

To solve this I set webpack to resolve fs to webpack's memory-fs (which works in browser) and null out webworker-threads. This has allowed natural to work in browser for me.

Here is a sample gatsby-node.js config which accomplishes this:

exports.modifyWebpackConfig = ({ config, stage }) => {
  config.merge({
    resolve: {
      alias: {
        fs: "memory-fs"
      }
    }
  });

  config.loader("null", {
    test: /webworker-threads/,
    loader: "null-loader"
  });

  return config;
};

EDIT: As well I think if #368 gets resolved I would only have to substitute fs for natural to work with webpack.

from natural.

wooorm avatar wooorm commented on August 28, 2024 1

Browserify’ing works, as long as WNdb and lapack are also installed. It’s pretty big though at 609 KB, which can be minified to 257kb using UglifyJS v2.3.6, but still.

I haven’t however tested if things work (just an idea, maybe add PhantomJS tests, or testling, to build steps?)

from natural.

chrisumbel avatar chrisumbel commented on August 28, 2024

i've been considering it for several of the algorithms. pretty much everything outside of WordNet should be OK and it very well may happen. any interest in helping with that?

from natural.

amitamb avatar amitamb commented on August 28, 2024

How can I help?

I know Javascript and have some understanding of NLP.

from natural.

chrisumbel avatar chrisumbel commented on August 28, 2024

i need a little to digest the recent contributions and I'll try to get a plan together. there seems to be plenty of demand for it so it's worth doing. i'll be back in touch about it next week.

from natural.

amitamb avatar amitamb commented on August 28, 2024

Let me know if you want some help. I haven't contributed to any OS project so I think this is good opportunity to do the same.

from natural.

yhslai avatar yhslai commented on August 28, 2024

I know Javascript and a little about NLP too. Could I contribute? Is there a plan or to-do list now?

from natural.

chrisumbel avatar chrisumbel commented on August 28, 2024

Sorry to disappear on you all. I'm coming back from a bit of a break.

Yes, this is still something I'm looking to get off the ground. Could one of you guys maybe volunteer to take the lead on getting a pure JavaScript implementation planned out and under way?

In my mind I was thinking most features that don't involve IO are perfect candidates.

Could the node version perhaps just become a superset of a pure JavaScript version?

from natural.

amitamb avatar amitamb commented on August 28, 2024

@raincole Let me know if you are planning to do this task.

Otherwise, I will try to lay out plan for it in this week. I will let you know if I have any issues.

from natural.

yhslai avatar yhslai commented on August 28, 2024

Sorry I were too busy so haven't started yet. It couldn't be better if you are able to set a plan. :)

from natural.

yhslai avatar yhslai commented on August 28, 2024

Uh, @amitamb , are you still here? I have been waiting for you for a long time...

from natural.

amitamb avatar amitamb commented on August 28, 2024

Well, I went through the source and thought of some ways to build client side Natural lib.

One way would be to create separate repo. while combining different files mostly manually.
Other would be to provide a script that user will execute with options on which Natural Language components user needs. Then that utility will extract the relevant code from different JS files and put it together in one.

Can you think of some other approach? Do you have some experience building client lib from different components?

https://github.com/mythz/jquip and libs like that probably have to do that.

I got busy immediately after checking out Natural and forgot about it in the meantime.

from natural.

yhslai avatar yhslai commented on August 28, 2024

My first thought was to provide a script based on browserify. With it, users can extract needed modules and compile them into client code. (I used browerify only. May there is a better choice)

It's hard to maintain copy-paste-recombine code so I want to share the code base.

from natural.

amitamb avatar amitamb commented on August 28, 2024

I didn't know about browserify.

We can try building a library out of existing libs using it.

from natural.

amitamb avatar amitamb commented on August 28, 2024

After long delay, I have created a separate project for this

https://github.com/amitamb/NaturalJS

Please let me know what you think.

I used browserify for creating it. Although, I got some errors while integrating Classifiers and Wordnet, others are successfully ported.

Looking forward to hear what you think.

from natural.

tansaku avatar tansaku commented on August 28, 2024

I'm very interested in a client side version of this ...

from natural.

jefffriesen avatar jefffriesen commented on August 28, 2024

I'm using this in Chrome without a problem using browserify. I'm running the output of the webspeech input element through it to navigate and fill out forms.

It was fairly straightforward to set up.
In the console:
browserify -r natural > bundle.js

In index.html:
<script type="text/javascript" src="bundle.js"></script>
<script src="app.js"></script>

In app.js:

var natural = require('natural');
var tokenizer = new natural.WordTokenizer();
var nounInflector = new natural.NounInflector();

jQuery(document).ready(function($) {

   tokenizeSentence = function(sentence) { 
    var tokenArray = tokenizer.tokenize(sentence);
    console.log(tokenArray);
  }

});

from natural.

jabelman avatar jabelman commented on August 28, 2024

@momoblackblack Hey I am having an issue with browserifying this module and it seems to be caused by wordnet. Did you have to go in and remove something? The console spits this out at me: Error: module "WNdb" not found from "/Users/me/Desktop/myapp/node_modules/natural/lib/natural/wordnet/wordnet.js"

from natural.

yathit avatar yathit commented on August 28, 2024

I am porting interesting feature from this library to client side using my IndexedDB database library https://github.com/yathit/ydn-db-text The repo is start with fullproof, but will gradually merge with natural.

One key feature of ydn-db-text is easy to used and memory efficient.

Some examples can be found here: http://dev.yathit.com/index/demos.html

Thanks for your excellent work.

from natural.

grahamlyons avatar grahamlyons commented on August 28, 2024

@jabelman it sounds like you just need to npm install WNdb before running Browserify.

from natural.

wilmoore avatar wilmoore commented on August 28, 2024

NOTE: this should all be doable with browserify, webpack, or anything similar. Probably OK to close this.

from natural.

kkoch986 avatar kkoch986 commented on August 28, 2024

I'm fine with closing it as long as someone can vouch that it works, i haven't had a chance to actually try it out myself.

EDIT: Theres talk of browserify above but it didn't seem like anyone had any real results.

from natural.

wilmoore avatar wilmoore commented on August 28, 2024

The size issue might be resolved by breaking natural up into multiple modules which can be browserified (similar to lodash). There would still be an aggregated package that includes all modules for those that want it.

from natural.

kkoch986 avatar kkoch986 commented on August 28, 2024

Ok great, glad to know its all working, maybe when i get the new site up and running we can have a client-side-building tool or something. In the meantime, take a look at this file fo info on how to include each module separately.

I'm gonna close the issue for now since it seems pretty resolved to me. Thanks everyone!

from natural.

kkoch986 avatar kkoch986 commented on August 28, 2024

Also, if you do try including separately the modules, let me know how it goes. I would be curious as to the size benefits obtained in doing so.

from natural.

newvicklee avatar newvicklee commented on August 28, 2024

Found a workaround in case anyone is wondering. I've only tested this with the Tokenizer module at the moment.
Go to /node_modules/natural/lib/natural/index.js and comment out all modules except the tokenizer ones (or whichever ones you want to use). There are some modules that just won't work on the client side (those that use node specific functions like fs and readFileSync).
Install browserify and bundle up your client side JS code that uses NaturalNode. With only the tokenizer module, it comes out to under 200kB.

from natural.

dspdog avatar dspdog commented on August 28, 2024

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

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

from natural.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.