在tex中检测英语单词

2024-05-29 10:26:56 发布

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

我有一个数据集,它被爬网,但也包含了很多垃圾条目。在

Name: sdfsdfsdfsd
Location: asdfdgdfjkgdsfjs
Education: Science & Literature 

目前存储在MySQL和Solr中。
有没有什么库可以在这些字段中查找英文单词,这样我就可以消除垃圾值了?我相信它需要一个字典,/usr/share/dict/中的默认unix字典对于这个用例来说已经足够了。在


Tags: 数据nameshare字典usrmysql条目location
1条回答
网友
1楼 · 发布于 2024-05-29 10:26:56
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'))

相关问题 更多 >

    热门问题