【问题标题】:Python equivalent to wordpress sanitize_textPython 相当于 wordpress sanitize_text
【发布时间】:2016-06-23 10:59:30
【问题描述】:

我需要相当于 wordpress sanitize_text 的 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 之类的词。我在哪里可以找到这些停用词?

【问题讨论】:

    标签: python django wordpress slug stop-words


    【解决方案1】:

    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()
    

    选择Corpora,向下滚动到stopwords,然后点击Download按钮。

    【讨论】:

      【解决方案2】:

      有一个名为 nltk 的 python 模块。这为您提供了完全做到这一点的可能性。

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

      只需在此网站上向下滚动一点,即可找到标题“删除停用词”。有一些示例说明如何使用此模块执行此操作。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-10-29
        • 2011-06-25
        • 2021-10-13
        • 2019-01-08
        • 2014-03-06
        • 2012-12-03
        • 2011-05-29
        • 2011-12-12
        相关资源
        最近更新 更多