【发布时间】:2016-10-27 18:12:03
【问题描述】:
我正在进行情绪分析,我想在否定和标点符号之间的每个单词中添加 NOT。我正在执行以下代码:
import re
fin=open("aboveE1.txt",'r', encoding='UTF-8')
transformed = re.sub(r'\b(?:never|no|nothing|nowhere|noone|none|not|havent|hasnt|hadnt|cant|couldnt|shouldnt|wont|wouldnt|dont|doesnt|didnt|isnt|arent|aint)\b[\w\s]+[^\w\s]',
lambda match: re.sub(r'(\s+)(\w+)', r'\1NEG_\2', match.group(0)),
fin,
flags=re.IGNORECASE)
Traceback(最近一次调用最后一次): 第 14 行,在 标志=re.IGNORECASE) 第 182 行,在 sub return _compile(pattern, flags).sub(repl, string, count) TypeError:预期的字符串或类似字节的对象
我不知道如何修复错误。你能帮帮我吗?
【问题讨论】:
标签: python