javascript - 使用 python 或 javascript 从文本中提取困难的英语单词以构建词汇

标签 javascript python text

我想从在线英语文本中获取困难的单词,例如使用 python 或 javascript 来构建词汇表的 gutenberg。我不习惯使用简单的单词,但使用独特的词汇,如“帝王”、“伪经”等。

如何确保在分割文本时我只得到独特的词汇而不是简单的单词。

最佳答案

我将“非常见单词”定义为未出现在前 10000 个最常见英语单词中的单词。

这 10 k 个最常见的单词是任意边界,但如 the github repo 中所述。 :

According to analysis of the Oxford English Corpus, the 7,000 most common English lemmas account for approximately 90% of usage, so a 10,000 word training corpus is more than sufficient for practical training applications.

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

关于javascript - 使用 python 或 javascript 从文本中提取困难的英语单词以构建词汇,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54710198/

相关文章:

javascript - 如何将文本转换为 Float 并在新的 div 中打印帐户的结果

javascript - 回调 - 未定义

css - 一点透明度,更好的阅读体验?

css - 图像上的响应式文本叠加

c - 读取输入的txt文件并用c格式化

javascript - JavaScript 中的同源策略

javascript - 存储在 FileList 中的图像未在 React 中显示

python - 如何迭代地将随机值添加到 Pandas Dataframe 中的许多行?

python 请求

python - 如何使用 Node.js 和 Dialogflow