NaturalNode / natural

general natural language facilities for node
MIT License
10.62k stars 860 forks source link

Better error messages when .train() hasn't been called on BayesClassifier #71

Closed tlack closed 10 years ago

tlack commented 12 years ago

If one forgets to call .train() on their classifier, here is the error you get from .classify():

> b.classify('dogs');
TypeError: Cannot read property 'label' of undefined
at [object Object].classify (/home/tlack/apps/classifier/node_modules/natural/node_modules/apparatus/lib/apparatus/classifier/classifier.js:37:51)
at [object Object].classify     (/home/tlack/apps/classifier/node_modules/natural/lib/natural/classifiers/classifier.js:84:28)

This is a pretty common mistake; it might be nice to throw an exception in this case instead of just bombing out.

jdubie commented 11 years ago

+1

chrisumbel commented 11 years ago

I'll see about getting this taken care of over the weekend.

adamramadhan commented 11 years ago

ah i see i think this fixed the issue https://github.com/NaturalNode/natural/issues/94

kkoch986 commented 10 years ago

so this issue is actually in the apparatus code (line 37) It happens when getClassifications returns an empty array (should only be when the classifier hasn't been trained).

I see two possible ways to improve this:

  1. Just return null if no classifications come back. Or,
  2. Throw an exception if no classifications come back, alerting you to the fact that the classifier has likely not been trained.

Personally, I'm leaning towards 2.

kkoch986 commented 10 years ago

So I've fixed this over in the apparatus code It should now throw an exception if the classifier is not trained.