我尝试使用spaCy进行错别字纠正,为此我需要知道一个单词在词汇表中是否存在。如果不存在,则需要将该单词拆成两部分,直到所有部分都存在为止。例如,“ofthe”不存在,“of”和“the”存在。所以我首先需要知道一个单词是否存在于词汇表中。问题就在这里。我尝试:
for token in nlp("apple"):
print(token.lemma_, token.lemma, token.is_oov, "apple" in nlp.vocab)
apple 8566208034543834098 True True
for token in nlp("andshy"):
print(token.lemma_, token.lemma, token.is_oov, "andshy" in nlp.vocab)
andshy 4682930577439079723 True True
很明显这是毫无意义的,在这两种情况下,“is_oov”均为True,而它在词汇表中。我正在寻找像这样简单的东西
"andshy" in nlp.vocab = False, "andshy".is_oov = True
"apple" in nlp.vocab = True, "apple".is_oov = False
在下一步中,还需要进行一些单词矫正的处理方法。我可以使用拼写检查库,但那与spaCy词汇表不一致。
这个问题似乎是一个经常性的问题,欢迎提供任何建议(代码)。
谢谢,
AHe