首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >classifier.__proto__ = LogisticRegressionClassifier.prototype

classifier.__proto__ = LogisticRegressionClassifier.prototype
EN

Stack Overflow用户
提问于 2021-01-08 12:19:17
回答 1查看 21关注 0票数 0

创建一个端点,该端点基于多个基于NaturalJS的ML模型来响应分类数组。我有两个问题:

  1. 如何解决这个错误,
  2. 如何强制它同步。

err和console.log:

代码语言:javascript
复制
Example app listening at http://localhost:3000
./src/data/
[ './src/data/trained.json', './src/data/untrained.json' ]
./src/data/trained.json
./src/data/untrained.json
[]
/Users/xyz/Desktop/Classifier/classifai-master/node_modules/apparatus/lib/apparatus/classifier/logistic_regression_classifier.js:178
    classifier.__proto__ = LogisticRegressionClassifier.prototype;
                         ^

TypeError: Cannot set property '__proto__' of undefined
    at Function.restore (/Users/xyz/Desktop/Classifier/classifai-master/node_modules/apparatus/lib/apparatus/classifier/logistic_regression_classifier.js:178:26)
    at restore (/Users/xyz/Desktop/Classifier/classifai-master/node_modules/natural/lib/natural/classifiers/logistic_regression_classifier.js:36:67)
    at /Users/xyz/Desktop/Classifier/classifai-master/node_modules/natural/lib/natural/classifiers/logistic_regression_classifier.js:47:27
    at /Users/xyz/Desktop/Classifier/classifai-master/node_modules/natural/lib/natural/classifiers/classifier.js:436:13
    at FSReqCallback.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:63:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! compoclassi@1.0.0 start: `node ./src/server.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the compoclassi@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/zyx/.npm/_logs/2021-01-08T12_02_36_696Z-debug.log

也请查看代码端点,

代码语言:javascript
复制
app.post('/suggest', urlencodedParser, (req, res) => {
    if (req.body.description) {
        var classifications = [];
        const modelsPaths = readDirectory('./src/data/')
        console.log(modelsPaths)
        
        modelsPaths.forEach(modelsPath => {
            console.log(modelsPath)
            natural.LogisticRegressionClassifier.load(modelsPath, null, function (err, classifier) {
                if (err) {
                    console.log(err)
                } else {
                    var classification = {};
                    classification['path'] = modelsPath;
                    classification['classification'] = classifier.classify(req.body.description);
                    classifications.push(classification);
                    console.log(classifications)
                }
            })
        })
        console.log(classifications)
    } else {
        res.render('./pages/main')
    }
})

在readDirectory()函数下面:(但这似乎很好)

代码语言:javascript
复制
function readDirectory(directory) {
    console.log(directory)
    const tree = dirTree(directory);
    var paths = [];
    tree.children.forEach(child => {
      paths.push('./'+child.path);
    })

    return paths;
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-01-08 14:22:36

发生此问题是因为第二个文件包含内部格式问题(未验证JSON)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65628810

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档