有什么办法可以将'pos_tag'的值放入python nltk的字典中的列表中?

牙齿

我有一个python字典,包含值列表。当我尝试pos_tag列表中的值时,显示错误。有什么办法可以解决?

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:字符串索引超出范围

维克多·史翠比维

您可以使用列表,只是不能有一个空项目。请参阅错误日志:

File "C:\Users\wstribizew\AppData\Local\Programs\Python\Python36-32\lib\site-packages\nltk\tag\perceptron.py", line 240, in normalize
    elif word[0].isdigit():

elif word[0].isdigit()perceptron.py中没有检查字符串长度,因为通常nltk.pos_tag这样做nltk.word_tokenize是在标记字符串时不输出空项目。

这是工作片段:

import nltk
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 = list(filter(None, RuleSet[key])) # Get rid of empty items
    Tagged = nltk.pos_tag(value)
    print(Tagged)

输出:

[('drafts', 'NNS'), ('duly', 'RB'), ('signed', 'VBD'), ('beneficiary', 'JJ'), ('drawn', 'NN'), ('issuing', 'VBG'), ('bank', 'NN'), ('quoting', 'VBG'), ('lc', 'NN')]
[('date', 'NN')]
[('signed', 'VBN'), ('commerical', 'JJ'), ('invoices', 'NNS'), ('quadruplicate', 'VBP'), ('gross', 'JJ'), ('cifvalue', 'NN'), ('goods', 'NNS')]

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章