创建一个端点,该端点基于多个基于NaturalJS的ML模型来响应分类数组。我有两个问题:
err和console.log:
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也请查看代码端点,
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()函数下面:(但这似乎很好)
function readDirectory(directory) {
console.log(directory)
const tree = dirTree(directory);
var paths = [];
tree.children.forEach(child => {
paths.push('./'+child.path);
})
return paths;
}发布于 2021-01-08 14:22:36
发生此问题是因为第二个文件包含内部格式问题(未验证JSON)
https://stackoverflow.com/questions/65628810
复制相似问题