javascript - 使用 python 或 javascript 从文本中提取难懂的英语单词以进行词汇构建
问题描述
我想从在线英语文本中提取难词,例如从古腾堡使用 python 或 javascript 构建词汇。我不会得到简单的单词,而是独特的词汇,比如 regal , aocryphal ..etc。
如何确保在拆分文本时只得到唯一的词汇而不是简单的单词。
解决方案
我将“非常用词”定义为没有出现在前 10000 个最常用英语单词中的词。
10 k 最常见的词是任意边界,但正如github repo 中所述:
根据牛津英语语料库的分析,最常见的 7000 个英语词元约占使用量的 90%,因此一个 10000 个单词的训练语料库对于实际的训练应用来说绰绰有余。
import requests
english_most_common_10k = 'https://raw.githubusercontent.com/first20hours/google-10000-english/master/google-10000-english-usa-no-swears.txt'
# Get the file of 10 k most common words from TXT file in a github repo
response = requests.get(english_most_common_10k)
data = response.text
set_of_common_words = {x for x in data.split('\n')}
# Once we have the set of common words, we can just check.
# The check is in average case O(1) operation,
# but you can use for example some sort of search three with O(log(n)) complexity
while True:
word = input()
if word in set_of_common_words:
print(f'The word "{word}" is common')
else:
print(f'The word "{word}" is difficult')
推荐阅读
- sql - 从 .NET Core webapp 操作 Azure 中的 SQL 数据库时,如何解决“用户登录失败”的问题?
- angular - 如何在 angular 4 的 agm 中鼠标悬停时显示 infoWindow
- postgresql - Docker 容器在启动 Postgres DB 后立即停止
- java - 我应该在哪里初始化我的 Apache commons pool2 以便可以从其他类访问它
- javascript - 亚马逊 AWS 网络服务器跨域请求
- google-app-engine - 无法连接云端 SQL [SQLSTATE[HY000] [2002] 无此文件或目录]
- c - 小核心代码更改时如何减少大型项目中的c编译时间
- python - 在models/manager.py 中升级到django 1.11.12 错误contribute_to_class
- bash - 如何更干净地实现“grep | sed | awk”脚本合并行对?
- c# - 实体框架使用指令放置背后是否有原因?