m0_69387289 2023-03-29 21:16 采纳率: 50%
浏览 8

代码出现TypeError: 'module' object is not callable应该怎样修改呢

代码出现TypeError: 'module' object is not callable应该怎样修改呢

import pandas as pd
import jieba.posseg as pseg
from synonyms import synonyms
import zhon.hanzi
from nltk.corpus import stopwords
punc = zhon.hanzi.punctuation  #要去除的中文标点符号
baidu_stopwords = stopwords.words('chinese') #导入停用词表
#读入文件
with open(r'D:\文本储存\9999991111.txt',encoding="gb18030") as fp:
    text = fp.read()
       
ls = pseg.cut(text) #使用jieba.posseg分词,可以得到每个词的词性

# 去掉长度为1或非名词的词,包括标点
newls = []
for word, flag in ls:
    if len(word) > 1 and flag.startswith('n'): 
        # flag.startswith('n') 表示词性以'n'开头即为名词
        newls.append(word)
#统计词频
ds = pd.Series(newls).value_counts()

#合并同义词,并保留同义词中词频高的词
syn_dict = {}
new_ds = ds.copy()   #复制一份原始的Series.
for idx, freq in ds.items():
    syn_res =synonyms(idx)
    if syn_res:
        syn_freq = max([ds.get(syn_word, 0) for syn_word in syn_res]) #获取同义词中出现频率最高的词
        syn_dict[idx] = syn_freq
        new_ds.drop(syn_res, errors='ignore', inplace=True)  #去除同义词
new_ds.rename(syn_dict, inplace=True)

#再次统计词频
new_ds = new_ds.value_counts()

#去除停用词
for i in baidu_stopwords:
    try:      #处理找不到元素i时pop()方法可能出现的错误
        new_ds.pop(i)  
    except:
        continue #没有i这个词,跳过本次,继续下一个词

pd.set_option('display.max_rows', None)#显示全部行
pd.set_option('display.max_columns', None)#显示全部列

print(new_ds[:300])



   提示是 syn_res =synonyms(idx) 出错 为啥呢
  • 写回答

1条回答 默认 最新

  • threenewbee 2023-03-29 21:58
    关注

    synonyms是模块,不是函数,所以没法调用

    评论

报告相同问题?

问题事件

  • 创建了问题 3月29日

悬赏问题

  • ¥15 Qt4代码实现下面的界面
  • ¥15 prism提示我reinstall prism 如何解决
  • ¥15 asp.core 权限控制怎么做,需要控制到每个方法
  • ¥20 while循环中OLED显示中断中的数据不正确
  • ¥15 这个视频里的stm32f4代码是怎么写的
  • ¥15 JNA调用DLL报堆栈溢出错误(0xC00000FD)
  • ¥15 请教SGeMs软件的使用
  • ¥15 自己用vb.net编写了一个dll文件,如何只给授权的用户使用这个dll文件进行打包编译,未授权用户不能进行打包编译操作?
  • ¥50 深度学习运行代码直接中断
  • ¥20 需要完整的共散射点成像代码