Python库查找段落中的有效英语单词
我有一个段落列表,我想检查这些单词是否是有效的英语单词。有时,由于一些外部问题,我可能在这些段落中找不到有效的英语单词。我知道像pyenchant和nltk这样的库都有一套字典,可以提供一定程度的准确性,但这两个库都没有什么缺点。我想知道是否有其他库或程序可以尽可能准确地为我提供所需内容。这在很大程度上取决于你所说的有效英语单词是什么意思。ECG、Thor或Loki是有效的英语单词吗?如果有效词的定义不同,则可能需要创建自己的语言模型。 无论如何,除了使用pyEnchant或nltk之外,我建议使用fasttext库。它有多个预先构建的词向量模型,你可以检查你的段落中是否有罕见或词汇量不足的词。您需要检查的是,这个特定的“无效”单词的单词嵌入表示对应于低数字(或零)其他单词。 您可以直接从python使用fasttextPython库查找段落中的有效英语单词,python,nlp,nltk,stanford-nlp,pyenchant,Python,Nlp,Nltk,Stanford Nlp,Pyenchant,我有一个段落列表,我想检查这些单词是否是有效的英语单词。有时,由于一些外部问题,我可能在这些段落中找不到有效的英语单词。我知道像pyenchant和nltk这样的库都有一套字典,可以提供一定程度的准确性,但这两个库都没有什么缺点。我想知道是否有其他库或程序可以尽可能准确地为我提供所需内容。这在很大程度上取决于你所说的有效英语单词是什么意思。ECG、Thor或Loki是有效的英语单词吗?如果有效词的定义不同,则可能需要创建自己的语言模型。 无论如何,除了使用pyEnchant或nltk之外,我建议
pip install fasstext
或者您可以使用gensim库(它也将为您提供一些额外的算法,例如Word2Vec,它对您的案例也很有用)
还是为了康达
conda install -c conda-forge gensim
假设您使用gensim并使用预先训练过的fasttext模型:
from gensim.models import FastText
from gensim.test.utils import datapath
cap_path = datapath("fasttext-model.bin")
fb_model = load_facebook_model(cap_path)
现在,您可以执行多个任务来实现您的目标:
1.检查词汇表
'mybizarreword' in fb_model.wv.vocab
对于稀有单词,您将获得较低的分数,通过设置阈值,您将确定哪个单词“无效”Linux和Mac OS X有一个可以直接使用的单词列表,否则您可以下载一个英语单词列表。 您可以按如下方式使用它:
d = {}
fname = "/usr/share/dict/words"
with open(fname) as f:
content = f.readlines()
for w in content:
d[w.strip()] = True
p ="""I have a list of paragraphs, I would like to check if these words are valid English words or not. Sometimes, due to some external issues, i might not get valid English words in these paragraphs. I am aware of libraries like pyenchant and nltk which have a set of dictionaries and provide accuracy of some level but both of these have few drawbacks. I wonder if there exists another library or procedure that can provide me with what I am looking for with at-most accuracy possible."""
lw = []
for w in p.split():
if len(w) < 4:
continue
if d.get(w, False):
lw.append(w)
print(len(lw))
print(lw)
#43
#['have', 'list', 'would', 'like', 'check', 'these', 'words', 'valid', 'English', 'words', 'some', 'external', 'might', 'valid', 'English', 'words', 'these', 'aware', 'libraries', 'like', 'which', 'have', 'dictionaries', 'provide', 'accuracy', 'some', 'level', 'both', 'these', 'have', 'wonder', 'there', 'exists', 'another', 'library', 'procedure', 'that', 'provide', 'with', 'what', 'looking', 'with', 'accuracy']
d={}
fname=“/usr/share/dict/words”
将open(fname)作为f:
content=f.readlines()
对于内容中的w:
d[w.strip()]=True
p=“”“我有一个段落列表,我想检查这些单词是否是有效的英语单词。有时,由于一些外部问题,我可能在这些段落中找不到有效的英语单词。我知道像pyenchant和nltk这样的库都有一套字典,可以提供一定程度的准确性,但这两个库都没有什么缺点。我想知道是否存在另一个库或程序可以尽可能准确地为我提供我正在寻找的内容
lw=[]
对于p.split()中的w:
如果len(w)<4:
持续
如果d.get(w,False):
lw.追加(w)
印刷品(透镜(lw))
打印(lw)
#43
#['have','list','will','like','check','this','words','valid','external','may','valid','English','words','saw','aware','libraries','like','which','have','dictionary','provide','accurrency','some','level that','have','have','wonder ther exists',',“那”、“提供”、“有”、“什么”、“看”、“有”、“准确”]
哪些是您的缺点,比如说pyenchant
?可能重复的
fb_model.wv.most_similar("man")
d = {}
fname = "/usr/share/dict/words"
with open(fname) as f:
content = f.readlines()
for w in content:
d[w.strip()] = True
p ="""I have a list of paragraphs, I would like to check if these words are valid English words or not. Sometimes, due to some external issues, i might not get valid English words in these paragraphs. I am aware of libraries like pyenchant and nltk which have a set of dictionaries and provide accuracy of some level but both of these have few drawbacks. I wonder if there exists another library or procedure that can provide me with what I am looking for with at-most accuracy possible."""
lw = []
for w in p.split():
if len(w) < 4:
continue
if d.get(w, False):
lw.append(w)
print(len(lw))
print(lw)
#43
#['have', 'list', 'would', 'like', 'check', 'these', 'words', 'valid', 'English', 'words', 'some', 'external', 'might', 'valid', 'English', 'words', 'these', 'aware', 'libraries', 'like', 'which', 'have', 'dictionaries', 'provide', 'accuracy', 'some', 'level', 'both', 'these', 'have', 'wonder', 'there', 'exists', 'another', 'library', 'procedure', 'that', 'provide', 'with', 'what', 'looking', 'with', 'accuracy']