4

I am trying to play around with the natural module in Node.JS. I wrote a simple program that takes an input from the browser and uses the Bayes' Classifier to classify it. However, at run time, I get the following error:

/home/hadoop/cloud_major/testing/node_modules/natural/node_modules/apparatus/lib/apparatus/classifier/bayes_classifier.js:95
 classifier.__proto__ = BayesClassifier.prototype;
                      ^
TypeError: Cannot set property '__proto__' of undefined
at Function.restore (/home/hadoop/cloud_major/testing/node_modules/natural/node_modules/apparatus/lib/apparatus/classifier/bayes_classifier.js:95:27)
at restore (/home/hadoop/cloud_major/testing/node_modules/natural/lib/natural/classifiers/bayes_classifier.js:37:54)
at /home/hadoop/cloud_major/testing/node_modules/natural/lib/natural/classifiers/bayes_classifier.js:44:23
at /home/hadoop/cloud_major/testing/node_modules/natural/lib/natural/classifiers/classifier.js:114:13
at fs.readFile (fs.js:176:14)
at Object.oncomplete (fs.js:297:15)

Now, for research, I went through the following thread by someone who had a similar problem in another Node.JS module: https://github.com/andris9/mailcomposer/issues/6 I followed the solution of uninstalling and reinstalling natural, with no help. I also found: http://tommytcchan.blogspot.in/2012_07_01_archive.html I used npm ls to get:

├─┬ natural@0.1.17
│ ├─┬ apparatus@0.0.6
│ │ └── sylvester@0.0.21
│ └── underscore@1.4.2

Then, I went through: Find the version of an installed npm package and got the following output:

├─┬ natural@0.1.17
│ ├─┬ apparatus@0.0.6
│ │ └── sylvester@0.0.21
│ └── underscore@1.4.2

i.e. I think that local version of the installed packages matches the dependencies required.Has anyone else used this package, and managed to debug this error?

Many thanks in advance!

Community
  • 1
  • 1
shikharraje
  • 127
  • 1
  • 17
  • I didn't realize there were any ml/nlp packages for node. If I get a chance I'll look at it. The best NLP tools are written in java and python though, so I'd strongly consider using those. – nflacco Oct 19 '12 at 18:42
  • I can't reproduce this problem on the latest versions. Have you tried upgrading? natural@0.1.18; apparatus@0.0.7; sylvester@0.0.21; underscore@1.4.3. If that doesn't do it, could you perhaps add your code to your question to assist debugging? – mjk Dec 24 '12 at 17:26

1 Answers1

0

Just a guess, but I think that it is due to improper initialization.

TypeError: Cannot set property '__proto__' of undefined

I get similar errors when I try to use properties of objects that I forget to initialize first. Guessing from the error you may not have defined or initialized classifier, making it undefined. you You can't set or use properties on undefined.

Here are a similar posts :

  1. JavaScript - cannot set property of undefined and
  2. Cannot Set Property ... of undefined --- bizarre
Community
  • 1
  • 1
user568109
  • 47,225
  • 17
  • 99
  • 123