我不知道有什么副手,但肯定可以做到。例如,使用TextBlob,您可以尝试使用词性提出一个功能。显然,您需要的不仅仅是这个小 sn-p,比如检查主语/动词一致性的函数,但它是一种方法的示例,希望它是值得深思的。
from textblob import TextBlob
from textblob.taggers import NLTKTagger
from textblob import Word
def lil_subj_replacer(phrase,input_subj,input_prp):
nltk_tagger = NLTKTagger()
blob = TextBlob(phrase,pos_tagger=nltk_tagger)
subject = True
for i,keyval in enumerate(blob.pos_tags):
key = keyval[0]
value = keyval[1]
if (value == 'PRP'):
if subject:
blob.words[i] = input_subj
subject = False
else:
blob.words[i] = input_prp
blob.words[i+1] = Word(blob.words[i+1]).lemmatize('v')
return ' '.join(blob.words)
my_phrase = 'You should go down the hall, as you reach the corner you are done.'
print(my_phrase)
print(lil_subj_replacer(phrase=my_phrase,input_subj='Your brother',input_prp='he'))
原文:You should go down the hall, as you reach the corner you are done.
没有词形还原:Your brother should go down the hall as he reach the corner he are done
词形化动词:Your brother should go down the hall as he reach the corner he be done
编辑:添加了 lemmaz 的示例,因为你提到了它。