【问题标题】:Detect english words in text检测文本中的英文单词
【发布时间】:2016-09-27 07:19:06
【问题描述】:

我有一个已抓取的数据集,但也包含其中包含大量垃圾的条目。

Name: sdfsdfsdfsd
Location: asdfdgdfjkgdsfjs
Education: Science & Literature 

目前它存储在 MySQL 和 Solr 中。
是否有任何图书馆可以在这些字段中查找英文单词,以便我可以消除垃圾值?我相信它需要一个字典,并且 /usr/share/dict/ 中的默认 unix 字典对于这个用例来说似乎已经足够了。

【问题讨论】:

    标签: java python mysql dictionary data-cleaning


    【解决方案1】:
    with open('/usr/share/dict/words') as f:
        words = set(word.lower() for word in f.read().split()
                    # Really short words aren't much of an indication
                    if len(word) > 3)
    
    def is_english(text):
        return bool(words.intersection(text.lower().split()))
        # or
        return any(word in words for word in text.lower().split())
    
    print(is_english('usfdbg dsuyfbg cat'))
    print(is_english('Science & Literature'))
    

    【讨论】:

    • 这意味着 O(n^2) 复杂性,因为我必须扫描整个列表以查找数据集中的每一行。
    • @YashveerRana 不,集合的重点是每个项目的恒定时间查找。 is_englishO(n) 其中 ntext 中的字数,没有比这更好的办法了。
    猜你喜欢
    • 2019-07-01
    • 1970-01-01
    • 2014-12-30
    • 1970-01-01
    • 1970-01-01
    • 2020-10-10
    • 1970-01-01
    • 2011-11-25
    • 1970-01-01
    相关资源
    最近更新 更多