python - 如何使用 python 对单词进行良好的标记化
问题描述
我在 python 中有一个函数,它使用分词器将一个句子分成单词。问题是当我运行这个函数时,返回的输出是一个没有空格的单词。
- 实际句子:
'是爱 Picture2Life.com !!!Y 所有有趣的应用程序都适用于 iPhone 而不是黑莓??!!'
- 结果:
'islovinpicturelifecomyallfunappsrforiphoneandnotblackberry'
结果一定是这样的: is love picture 2 life 。com....
代码:
ppt = '''...!@#$%^&*()....{}’‘ “” “[]|._-`/?:;"'\,~12345678876543'''
#tekonize helper function
def text_process(raw_text):
'''
parameters:
=========
raw_text: text as input
functions:
==========
- remove all punctuation
- remove all stop words
- return a list of the cleaned text
'''
#check characters to see if they are in punctuation
nopunc = [char for char in list(raw_text) if char not in ppt]
# join the characters again to form the string
nopunc = "".join(nopunc)
#now just remove ant stopwords
words = [word for word in nopunc.lower().split() if word.lower() not in stopwords.words("english")]
return words
ddt= data.text[2:3].apply(text_process)
print("example: {}".format(ddt))
解决方案
推荐阅读
- android - 在 Android Studio 中使用 Volley 和一个 Json 文件,该文件具有指向另一个 Json 文件的链接,我想从中获取数据
- visual-studio-code - VSCode 远程服务器卡在初始化服务器上
- postgresql - Sequelize 错误 42804。将需要重写或转换表达式
- javascript - 从右键菜单中的jquery关闭选项卡
- amazon-web-services - 使用 AWS Amplify 创建 SNS 终端节点。怎么做?
- sharepoint - 如何以编程方式获取租户中当前用户的“最近访问的共享点站点”?
- google-tag-manager - 如何从标签谷歌标签管理器获取谷歌标签 ID
- html - 如何使用 HTML 渲染图像,使用 Flutter 创建 iOS-App 的 CSS?
- azure - 为什么不同的 Microsoft Graph API 返回不同的数据
- javascript - jquery 验证无法正常工作