替换标签代替单词 - spacy



我正在尝试用标签替换句子。我希望标签替换单词并形式为句子。

from __future__ import unicode_literals
import spacy,en_core_web_sm
import textacy
nlp = en_core_web_sm.load()
sentence = 'The cat sat on the mat. the dog sleeps.'
doc = nlp(sentence)
for token in doc:
print(token.dep_)

输出。

det
nsubj
ROOT
prep
det
pobj
punct
det
nsubj
ROOT
punct

预期输出:

det nsubj ROOT prep det pobj det punct det nsubj ROOT punct

您可以使用str.join

ex:

print(" ".join([token.dep_ for token in doc]))   #List comprehension 

最新更新