我正试图用德语句子来确定主语。对于英语,我曾经这样做过:
import spacy
nlp = spacy.load('en')
sent = "I shot an elephant"
doc=nlp(sent)
sub_toks = [tok for tok in doc if (tok.dep_ == "nsubj") ]
print(sub_toks) 但它不适用于nlp = spacy.load('de_core_news_sm')和使用德语句子。它返回一个空列表。
我试着看这里,即使它们有词类而不是主语、宾语等,但它也返回空列表。这在德语中可能吗?
发布于 2022-01-13 13:00:13
试试这个片段:
模块中的句子给出了德语句子的例子。
import spacy
from spacy.lang.de.examples import sentences
nlp = spacy.load("de_core_news_sm")
doc = nlp(sentences[0])
print(doc.text)
for token in doc:
print(token.text, token.pos_, token.dep_)https://stackoverflow.com/questions/70696987
复制相似问题