我有一个python字典,它包含了一系列的值。当我试图标记列表中的值时,显示错误。有什么办法解决吗
RuleSet = {1: ['drafts', 'duly', 'signed', 'beneficiary', 'drawn', 'issuing', 'bank', 'quoting', 'lc', ''], 2: ['date', ''], 3: ['signed', 'commerical', 'invoices', 'quadruplicate', 'gross', 'cifvalue', 'goods', '']}
for key in RuleSet:
value = RuleSet[key]
Tagged = nltk.pos_tag(value)
print(Tagged)
IndexError: string index out of range
你可以使用列表,你只是不能有一个空的项目在那里。请参阅错误日志:
在perceptron.py中的
elif word[0].isdigit()
中没有检查字符串长度,因为通常nltk.pos_tag
是在nltk.word_tokenize
之后完成的,在对字符串进行标记化时,它不会输出空项以下是工作片段:
输出:
相关问题 更多 >
编程相关推荐