我正在 python 上进行数据清理练习,我正在清理的文本包含我想删除的意大利语单词。我一直在网上搜索是否可以使用像 nltk 这样的工具包在 Python 上执行此操作。
例如给出一些文本:
"Io andiamo to the beach with my amico."
我想留下:
"to the beach with my"
有谁知道如何做到这一点?
任何帮助将非常感激。
您可以使用words
来自 NLTK 的语料库:
import nltk
words = set(nltk.corpus.words.words())
sent = "Io andiamo to the beach with my amico."
" ".join(w for w in nltk.wordpunct_tokenize(sent) \
if w.lower() in words or not w.isalpha())
# 'Io to the beach with my'
很遗憾,Io恰好是一个英文单词。一般来说,可能很难确定一个单词是否是英语。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)