检测文本中的英文单词

时间:2016-05-29 11:03:02

标签: java python mysql dictionary data-cleaning

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

Name: sdfsdfsdfsd
Location: asdfdgdfjkgdsfjs
Education: Science & Literature 

目前它存储在MySQL和Solr中 是否有任何库可以在这些字段中查找英语单词,以便我可以消除垃圾值?我相信它需要一个字典, / usr / share / dict / 中的默认unix字典似乎足够用于此用例。

1 个答案:

答案 0 :(得分:0)

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'))
相关问题