我尝试开发一个lambda表达式分类。以下是我目前的代码
import nltk
list2=nltk.word_tokenize("I win it")
list1 = ['gain', 'archive', 'win', 'success']
set1 = set(list1)
result = []
for item, nextitem in zip(list2, list2[1:]):
if item in set1:
result.append(nextitem)
print result
new_result =nltk.pos_tag(result)
words, tags = zip(*new_result)
def classify(s, rls):
for (f, emotion) in rls:
if f(s):
return emotion
return "neutral"
rules = [(lambda x: x[result != []] & [['PRP' in(tags)]], "happy"),
(lambda x: x[result != []] & [['PRP' not in(tags)]], "neutral"),]
print classify("I successfully done my exam", rules)
但它会产生以下错误。你知道吗
rules = [(lambda x: x[result != []] & [['PRP' in(tags)]], "happy"),
TypeError: unsupported operand type(s) for &: 'str' and 'list'
如何修复此错误。请帮帮我!你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐