Python等价于wordpress sanitize\u tex

2024-06-11 12:17:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要相当于wordpress清理文本的Python

标题:

'mygubbi raises $25 mn seed funding from bigbasket co founder others'

wordpress提供

"mygubbi-raises-2-5-mn-seed-funding-bigbasket-co-founder-others"

Python slugify提供

"mygubbi-raises-2-5-mn-seed-funding-from-bigbasket-co-founder-others"

我用过python slugify python库。你知道吗

我是不是应该去掉像from,in,to这样的词。我在哪能找到那些停止语?你知道吗


Tags: infrom文本标题wordpressseedraisesco
2条回答

有一个名为nltk的python模块。这就为你提供了一种可能。你知道吗

http://www.bogotobogo.com/python/NLTK/tokenization_tagging_NLTK.php

只需在这个网站上向下滚动一点,找到标题“删除停止词”。下面有一些使用此模块执行此操作的示例。你知道吗

python-slugify库有一个stopwords参数,可以与nltk一起使用,如下所示:

from slugify import slugify
from nltk.corpus import stopwords

text = 'mygubbi raises $25 mn seed funding from bigbasket co founder others'
print slugify(text, stopwords=stopwords.words('english'))

这将打印:

mygubbi-raises-25-mn-seed-funding-bigbasket-co-founder-others

安装nltk之后,您可以安装其他语料库,其中一个是stopwords。要执行此操作,请按如下方式运行其内置下载实用程序:

import nltk

nltk.download()

NLTK download helper

选择Corpora,向下滚动到stopwords,然后单击Download按钮。你知道吗

相关问题 更多 >