2012-10-15 51 views
4

我試圖在Node.JS中使用自然模塊。我編寫了一個簡單的程序,它從瀏覽器獲取輸入並使用貝葉斯分類器對其進行分類。然而,在運行時,我得到以下錯誤:在node.js中使用「自然」模塊

/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) 

現在,對於研究中,我通過別人以下螺紋誰曾在另一Node.js的模塊類似的問題去: https://github.com/andris9/mailcomposer/issues/6 我跟着解決方案卸載並重新安裝自然,沒有任何幫助。 我還發現:http://tommytcchan.blogspot.in/2012_07_01_archive.html我用NPM LS獲得:

├─┬ [email protected] 
│ ├─┬ [email protected] 
│ │ └── [email protected] 
│ └── [email protected] 

然後,我經歷了:Find the version of an installed npm package,得到了以下的輸出:

├─┬ [email protected] 
│ ├─┬ [email protected] 
│ │ └── [email protected] 
│ └── [email protected] 

即我認爲安裝的軟件包的本地版本匹配所需的依賴關係。是否有其他人使用過此包,並設法調試此錯誤?

非常感謝提前!

+0

我不知道有任何毫升/ NLP包節點。如果我有機會,我會看看它。最好的NLP工具是用java和python編寫的,所以我強烈考慮使用這些工具。 – nflacco

+0

我無法在最新版本上重現此問題。你有沒有嘗試升級? [email protected]; [email protected]; [email protected]; [email protected]。如果沒有這樣做,你可能會添加你的代碼到你的問題來協助調試嗎? – mjk

回答

0

只是一個猜測,但我認爲這是由於不正確的初始化。

TypeError: Cannot set property '__proto__' of undefined 

當我嘗試使用忘記首先初始化的對象的屬性時,出現類似錯誤。從錯誤中猜出您可能尚未定義或初始化classifier,使其成爲undefined。您無法在undefined上設置或使用屬性。

這裏有一個類似的帖子:

  1. JavaScript - cannot set property of undefined
  2. Cannot Set Property ... of undefined --- bizarre