Comments (27)
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.
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.
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.
How can I help?
I know Javascript and have some understanding of NLP.
from natural.
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.
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.
I know Javascript and a little about NLP too. Could I contribute? Is there a plan or to-do list now?
from natural.
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.
@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.
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.
Uh, @amitamb , are you still here? I have been waiting for you for a long time...
from natural.
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.
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.
I didn't know about browserify.
We can try building a library out of existing libs using it.
from natural.
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.
I'm very interested in a client side version of this ...
from natural.
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.
@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.
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.
@jabelman it sounds like you just need to npm install WNdb
before running Browserify.
from natural.
NOTE: this should all be doable with browserify, webpack, or anything similar. Probably OK to close this.
from natural.
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.
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.
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.
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.
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.
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)
- Unneeded `tsc` dependency HOT 4
- SentenceTokenizer works badly with numbered lists HOT 1
- Build errors trying to use natural with create react app (CRA) react v 18.2.0, natural v6.2.0 HOT 2
- Save data in Mongodb HOT 10
- Bayes Classifier Restore Issue
- Release updated type declarations HOT 1
- Trying to import natural in TypeScript yields a linter error
- Missing typings for LevenshteinDistanceSearch as well as for DamerauLevenshteinDistanceSearch HOT 2
- Sanity check - client side only possible? HOT 2
- Version 6.5.0 introduces a breaking change for sentence tokenizing HOT 2
- Error when using natural from deno using esm.sh HOT 1
- Enhancement: Stricter Typing for tag Field in BrillPOSTaggedWord Interface HOT 1
- Error in `natural.JaroWinklerDistance()` when missing optional `options` parameter
- natural.AggressiveTokenizerRu() doesn't filter out non-cyrillic characters HOT 1
- Bulk mode that is mindful of event loop HOT 2
- Check for Eszett symbol ß in German tokenizer HOT 1
- Noob Question. Challenge to devs? Help?
- Typo in docs HOT 1
- Load model with BayesClassifier and PorterStemmerEs HOT 2
- Cannot read properties of undefined (reading 'on') HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from natural.