gpt4 book ai didi

Python 类型错误 : 'NoneType' object has no attribute '__getitem__

转载 作者:太空宇宙 更新时间:2023-11-04 09:11:25 25 4
gpt4 key购买 nike

正在开展一个项目,使用 Collins Head Rules 从句子中获取词条。

这是我得到的错误:

File "C:\Users\PC\Desktop\Python27\PyProject\src\Feature\FeatureExtractor.py", line 225, in collinsHeadExtractor
if raw['whWord']=='whWord-what':
TypeError: 'NoneType' object has no attribute '__getitem__'

这是产生错误的代码部分:

def whoPattern(question):
p1 = re.compile("^[w|W]ho (is|are|was|were)( the)*( \`\`)*( [A-Z][a-z]+)+( \'\')* \?$")
if p1.match(question):
return "HUM:desc"
p2 = re.compile("^[w|W]ho (is|was) .*")
if p2.match(question):
return "Hum:ind"
if training:
file = DBStore.trainingRoot+"\\headword_question"+colName+".txt"
else:
file = DBStore.testingRoot+"\\headword_question"+colName+".txt"
f = open(file,'r')
p = re.compile(r"(?P<head>.+)::(?P<question>.+)")
i = 0
rawQuestions = DBStore.getDB()['raw'+colName]
p2 = re.compile('\.')
headWord = []
for line in f:
print iWor
i = i + 1
match = p.match(line)
print match.group('question')
head = p2.sub('',match.group('head'))
question = match.group('question')
raw = rawQuestions.find_one({'question':question})
if raw['whWord']=='whWord-what':
pattern = whatPattern(question)
elif raw['whWord']=='whWord-who':
pattern = whoPattern(question)
else:
pattern = None
if head.isupper() and (pattern == "DESC:def_1" or pattern == 'DESC:def_2'):
pattern = "ABBR:exp"
if head == 'null':
headWord = [None,pattern]
elif pattern is None:
headWord = [head,pattern]
else:
headWord = [None,pattern]
rawQuestions.update({'question':question},{"$set":{"head":headWord}},safe=True,multi=True)

任何解决这个问题的帮助都会很棒。谢谢!

最佳答案

这意味着 rawQuestions.find_one({'question':question}) 返回了 None

关于Python 类型错误 : 'NoneType' object has no attribute '__getitem__,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14571932/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com