【发布时间】:2017-09-28 06:43:58
【问题描述】:
我正在用 python 的 TextBlob 包敲我的头,
- 从段落中识别句子
- 从句子中识别单词
- 为这些词等确定 POS(词性)标签...
如果我没记错的话,在我发现一个可能的问题之前,一切都很顺利。下面用示例代码sn-p解释。
from textblob import TextBlob
sample = '''This is greater than that by 5%.''' #Sample Sentence
blob = TextBlob(sample) #Passing it to TextBlob package.
Words = blob.words #Splitting the Sentence into words.
Tags = blob.tags #Determining POS tag for each words in the sentence
print(Tags)
[('This', 'DT'), ('is', 'VBZ'), ('greater', 'JJR'), ('than', 'IN'), ('that', 'DT'), ('by', 'IN'), ('5', 'CD'), ('%', 'NN')]
print(Words)
['This', 'is', 'greater', 'than', 'that', 'by', '5']
如上所示,blob.tags 函数将 '%' 符号视为一个单独的单词,并确定 POS 标签。
而 blob.words 函数甚至不会单独或与前一个单词一起打印 '%' 符号。
我正在使用这两个函数的输出创建一个数据框。因此,由于长度不匹配问题,它没有被创建。
这是我的问题。 这可能是 TextBlob 包中的问题吗? 有没有办法在单词列表中识别“%”?
【问题讨论】: