【问题标题】:Replace tags in place of words - spacy用标签代替单词 - spacy
【发布时间】:2018-09-05 20:11:41
【问题描述】:

我正在尝试用他们的标签替换句子。我想用标签替换单词并形成一个句子。

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

【问题讨论】:

    标签: python nltk spacy


    【解决方案1】:

    你可以使用str.join

    例如:

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

    【讨论】:

    • 谢谢拉克什。如果你也能看到我的句子结构问题。 stackoverflow.com/questions/49460078/…
    • 如果它解决了您的问题,请接受。如果我能解决你的问题,我正在查看问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多