TypeError:无法读取属性' removestopWords'不确定的
我正在使用potwords和typeScript进行项目,并且正在收到以下错误 我试图通过删除!string.trim()并替换string.trim()来调试,我收到的输出为
0 0
还试图给固定播种一种类型的任何类型,也可以给予固定(str:string | undefined),但没有成功。.
// @ts-ignore
import aposToLexForm from "apos-to-lex-form";
import { WordTokenizer } from "natural";
// @ts-ignore
import SpellCorrector from 'spelling-corrector';
import stopword from "stopword";
const tokenizer = new WordTokenizer();
const spellCorrector = new SpellCorrector();
spellCorrector.loadDictionary();
function getSentiment(str: string): -1 | 0 | 1 {
if (!str.trim()) {
return 0;
}
const lexed = aposToLexForm(str).toLowerCase().replace(/[^a-zA-Z\s]+/g, "");
const tokenized = tokenizer.tokenize(lexed);
const fixedSpelling = tokenized.map((word) => spellCorrector.correct(word));
const stopWordsRemoved = stopword.removeStopwords(fixedSpelling);
console.log(stopWordsRemoved);
return 0;
}
console.log(getSentiment('This is awesome!'))
console.log(getSentiment('Logging is super duper cool!'))
被收到错误 -
TypeError: Cannot read property 'removeStopwords' of undefined
at getSentiment (/home/karlito/projects/twitter/src/app.ts:23:39)
at Object.<anonymous> (/home/karlito/projects/twitter/src/app.ts:31:13)
at Module._compile (node:internal/modules/cjs/loader:1109:14)
at Module._compile (/home/karlito/projects/twitter/node_modules/source-map-support/source-map-support.js:568:25)
at Module.m._compile (/tmp/ts-node-dev-hook-30469514417241084.js:69:33)
at Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
at require.extensions..jsx.require.extensions..js (/tmp/ts-node-dev-hook-30469514417241084.js:114:20)
at require.extensions.<computed> (/tmp/ts-node-dev-hook-30469514417241084.js:71:20)
at Object.nodeDevHook [as .ts] (/home/karlito/projects/twitter/node_modules/ts-node-dev/lib/hook.js:63:13)
at Module.load (node:internal/modules/cjs/loader:989:32)
[ERROR] 18:44:36 TypeError: Cannot read property 'removeStopwords' of undefined
I am working on a project using stopwords and typescript and I am receiving the below error
I have attempted to debug by removing the !string.trim() and replacing with string.trim() and I receive an output of
0
0
Also have attempted to give fixedSpelling a type of any and also the getSentiment(str:string | undefined) but no success..
// @ts-ignore
import aposToLexForm from "apos-to-lex-form";
import { WordTokenizer } from "natural";
// @ts-ignore
import SpellCorrector from 'spelling-corrector';
import stopword from "stopword";
const tokenizer = new WordTokenizer();
const spellCorrector = new SpellCorrector();
spellCorrector.loadDictionary();
function getSentiment(str: string): -1 | 0 | 1 {
if (!str.trim()) {
return 0;
}
const lexed = aposToLexForm(str).toLowerCase().replace(/[^a-zA-Z\s]+/g, "");
const tokenized = tokenizer.tokenize(lexed);
const fixedSpelling = tokenized.map((word) => spellCorrector.correct(word));
const stopWordsRemoved = stopword.removeStopwords(fixedSpelling);
console.log(stopWordsRemoved);
return 0;
}
console.log(getSentiment('This is awesome!'))
console.log(getSentiment('Logging is super duper cool!'))
error being received -
TypeError: Cannot read property 'removeStopwords' of undefined
at getSentiment (/home/karlito/projects/twitter/src/app.ts:23:39)
at Object.<anonymous> (/home/karlito/projects/twitter/src/app.ts:31:13)
at Module._compile (node:internal/modules/cjs/loader:1109:14)
at Module._compile (/home/karlito/projects/twitter/node_modules/source-map-support/source-map-support.js:568:25)
at Module.m._compile (/tmp/ts-node-dev-hook-30469514417241084.js:69:33)
at Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
at require.extensions..jsx.require.extensions..js (/tmp/ts-node-dev-hook-30469514417241084.js:114:20)
at require.extensions.<computed> (/tmp/ts-node-dev-hook-30469514417241084.js:71:20)
at Object.nodeDevHook [as .ts] (/home/karlito/projects/twitter/node_modules/ts-node-dev/lib/hook.js:63:13)
at Module.load (node:internal/modules/cjs/loader:989:32)
[ERROR] 18:44:36 TypeError: Cannot read property 'removeStopwords' of undefined
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来“停止字”没有默认导出。您可以将导入语句更改为:
或不
stopWord
模块:stopword docs
It looks like 'stopword' does not have a default export. You could to change your import statement to:
Or without the
stopword
module:Stopword docs