如何在spacy中执行拼写检查。如果可能的话,需要找出错误的单词和建议的数量

2024-04-26 11:09:37 发布

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

如何在spacy中执行拼写检查。如果可能的话,需要找到单词的数量和建议。我试过了this page

print('spell check doc_new')
print('-----------------')
print('contextual_spellCheck')
print(doc_new._.contextual_spellCheck)
print('performed_spellCheck')
print(doc_new._.performed_spellCheck)
print('score_spellCheck')
print(doc_new._.score_spellCheck)
print('outcome_spellCheck')
print(doc_new._.outcome_spellCheck)
print(nlp.pipe_names)
-----------------------
Output
contextual_spellCheck
True
performed_spellCheck
True
score_spellCheck
{bok: [('home', 0.25162), ('life', 0.10225), ('job', 0.0533), ('friend', 0.02805), ('place', 0.01896), ('world', 0.01788), ('apartment', 0.01757), ('family', 0.01643), ('house', 0.01583), ('boss', 0.01192)], universty: [('full', 0.24508), ('last', 0.14188), ('first', 0.11419), ('middle', 0.09706), ('real', 0.07817), ('given', 0.04026), ('birth', 0.03326), ('code', 0.0086), ('stage', 0.00846), ('maiden', 0.00798)], acc: [('David', 0.0059), ('Sam', 0.0052), ('Alex', 0.00496), ('James', 0.0047), ('I', 0.00424), ('Paul', 0.00419), ('Jack', 0.00384), ('John', 0.00381), ('Peter', 0.00347), ('Mark', 0.00344)]}
func
{bok: 'job', universty: 'first', acc: 'Jack'}
outcome_spellCheck
This is my new job. My first name is Jack.
['tok2vec', 'tagger', 'parser', 'ner', 'attribute_ruler', 'lemmatizer', 'contextual spellchecker'

表现不同

任何其他选择


Tags: truenewdocjobfirstaccscoreprint
1条回答
网友
1楼 · 发布于 2024-04-26 11:09:37

您可以使用doc._.suggestions_spellCheck

import spacy
import contextualSpellCheck

nlp = spacy.load('en_core_web_sm')
contextualSpellCheck.add_to_pipe(nlp)
doc = nlp('This is my neww job. My firsrt neme is Jack.')

print(len(doc._.suggestions_spellCheck)) # => Number of errors: 3
print(doc._.suggestions_spellCheck)      # => {neww: 'new', firsrt: 'best', neme: 'name'}
print(doc._.outcome_spellCheck)          # => This is my new job. My best name is Jack.

相关问题 更多 >