使用单词建议Python进行语法/拼写检查

2024-06-25 22:50:30 发布

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

我正在进行一个NLP项目,该项目用自然语言分析规范。 我正在使用NLTK工具箱和autocorrect进行标记、词性标记和拼写错误检查。但我最近遇到了一个问题。 所以这个例子是“Then it terns left”,而用户的意思是“Then it turns left”

NLTK工具箱中的POS标记器将“terns”识别为形容词。但是由于这个句子本身在语法上是不正确的,并且NLTK解析器仍然局限于正确的句子,所以我不会责怪它。由于“tern”是一个正确的英语单词,autocorrect函数也不会捕捉错误。 当我用Grammarly这样的语法工具来测试句子时,它给我的建议是:terns这个词似乎不适合这个上下文,建议我用“turns”代替它。在

我怎样才能解决这个问题? “然后把这个句子变成左边的建议。”

我现在的想法是先检查一下语法。例如,也许说“it”和“left”之间的单词应该是一个动词。然后根据我们需要动词这一事实给出了建议。NLTK解析器并不能真正判断是哪个词导致了问题。我也试过语法检查和语言检查(它们是一样的)。对我来说太慢了。在

关于如何解决这个问题有什么建议吗?在


Tags: 项目标记解析器语法it工具箱动词left
1条回答
网友
1楼 · 发布于 2024-06-25 22:50:30

你在这里描述的是一个困难的问题,但是它可以通过检查单词的一致性来解决,或者换句话说,通过检查单词在其他环境中使用的上下文来解决。如果这个词在主语句中的用法有意义,你就可以根据上下文做出有根据的猜测。下面是一个例子,来自nltk docs,使用mobydick作为搜索空间。在

>>> text1.concordance("monstrous")
Displaying 11 of 11 matches:
ong the former , one was of a most monstrous size . ... This came towards us ,
ON OF THE PSALMS . " Touching that monstrous bulk of the whale or ork we have r
ll over with a heathenish array of monstrous clubs and spears . Some were thick
d as you gazed , and wondered what monstrous cannibal and savage could ever hav
that has survived the flood ; most monstrous and most mountainous ! That Himmal
they might scout at Moby Dick as a monstrous fable , or still worse and more de
th of Radney .'" CHAPTER 55 Of the monstrous Pictures of Whales . I shall ere l
ing Scenes . In connexion with the monstrous pictures of whales , I am strongly
ere to enter upon those still more monstrous stories of them which are to be fo
ght have been rummaged out of this monstrous cabinet there is no telling . But
of Whale - Bones ; for Whales of a monstrous size are oftentimes cast up dead u
>>>

此外,如果您还没有使用Stanford POS标记器而不是默认的NTLK标记器,它可以以牺牲性能为代价生成更好的结果。在

相关问题 更多 >