TypeError:无法读取属性' removestopWords'不确定的

发布于 2025-02-04 01:18:41 字数 2070 浏览 2 评论 0原文

我正在使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

山人契 2025-02-11 01:18:41

看起来“停止字”没有默认导出。您可以将导入语句更改为:

import * as stopword from 'stopword'

或不stopWord模块:

import { removeStopwords } from 'stopword'

stopword docs

It looks like 'stopword' does not have a default export. You could to change your import statement to:

import * as stopword from 'stopword'

Or without the stopword module:

import { removeStopwords } from 'stopword'

Stopword docs

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文