替换标签代替单词 - spacy

时间:2018-03-27 12:10:15

标签: python nltk 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

1 个答案:

答案 0 :(得分:2)

您可以使用str.join

<强>实施例

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