我正在尝试用他们的标签替换句子。我希望标签能够将单词和形式替换为句子。
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
答案 0 :(得分:2)
您可以使用str.join
<强>实施例强>
print(" ".join([token.dep_ for token in doc])) #List comprehension