【发布时间】:2020-04-24 01:21:22
【问题描述】:
我正在尝试编写代码,该代码传递已标记化并过滤掉停用词的文本,然后对其进行词干和标记。但是,我不确定我应该按什么顺序进行词干和标记。这是我目前拥有的:
#### Stemming
ps = PorterStemmer() # PorterStemmer imported from nltk.stem
stemText = []
for word in swFiltText: # Tagged text w/o stop words
stemText.append(ps.stem(word))
#### POS Tagging
def tagging():
tagTot = []
try:
for i in stemText:
words = nltk.word_tokenize(i) # I need to tokenize again (idk why?)
tagged = nltk.pos_tag(words)
tagTot = tagTot + tagged # Combine tagged words into list
except Exception as e:
print(str(e))
return tagTot
tagText = tagging()
乍一看,这很好用。但是,因为我先进行了词干提取,pos_tag 经常错误地标注单词。例如,它把“hous”标记为形容词,而原来的词实际上是名词“house”。但是当我在标记后尝试进行词干时,它给了我一个关于 pos_tag 如何无法处理“元组”的错误 - 我猜这与词干分析器将单词列表格式化为 @987654324 的方式有关@等
我应该使用不同的词干分析器/标记器吗?还是我的代码有错误?
提前致谢!
【问题讨论】:
标签: python nlp nltk tagging stemming