As she leaves the kitchen, his voice follows her.
#output
As she left the kitchen, his voice followed her.
问题
没有办法从现在时转变为过去时态。 我已经检查了以下类似的问题,但它们仅引入了转变的方式 过去时态以表达时态。使用NLTK和WordNet;如何将简单的时态动词转换为当前,过去或过去的分词形式?
我试图做什么 我能够使用
text = "As she left the kitchen, his voice followed her."
doc_dep = nlp(text)
for i in range(len(doc_dep)):
token = doc_dep[i]
#print(token.text, token.lemma_, token.pos_, token.tag_, token.dep_)
if token.pos_== 'VERB':
print(token.text)
print(token.lemma_)
text = text.replace(token.text, token.lemma_)
print(text)
#output
'As she leave the kitchen, his voice follow her.'
pyinflect
创建的spacy
pip install pyinflect
import spacy
import pyinflect
nlp = spacy.load("en_core_web_sm")
text = "As she leave the kitchen, his voice follows her."
doc_dep = nlp(text)
for i in range(len(doc_dep)):
token = doc_dep[i]
if token.tag_ in ['VBP', 'VBZ']:
print(token.text, token.lemma_, token.pos_, token.tag_)
text = text.replace(token.text, token._.inflect("VBD"))
print(text)
As she left the kitchen, his voice followed her.
注:我正在使用Spacy3.据我所知,Spacy对这种类型的转换没有任何内置功能,但是您可以在绘制映射时/过去时态以及没有适当的对'ED'后缀的延伸范围内使用以下弱动词的``Ed ed''后缀:
verb_map = {'leave': 'left'}
def make_past(token):
return verb_map.get(token.text, token.lemma_ + 'ed')
spacy.tokens.Token.set_extension('make_past', getter=make_past, force=True)
text = "As she leave the kitchen, his voice follows her."
doc_dep = nlp(text)
for i in range(len(doc_dep)):
token = doc_dep[i]
if token.tag_ in ['VBP', 'VBZ']:
print(token.text, token.lemma_, token.pos_, token.tag_)
text = text.replace(token.text, token._.make_past)
print(text)
输出:
leave leave VERB VBP
follows follow VERB VBZ
As she left the kitchen, his voice followed her.