spaCy - Doc.sents 屬性



顧名思義,此 doc 屬性用於遍歷特定文件中的句子。如果已停用解析器,則sents 迭代器不可用。

示例 1

參考下面給出的 Doc.sents 屬性示例 −

import spacy
nlp_model = spacy.load("en_core_web_sm")
doc = nlp_model("The website is Tutorialspoint.com. It is having best technical tutorials.")
sents = list(doc.sents)
len(sents)

輸出

您將獲得以下輸出 −

2

示例 2

下面給出了 Doc.sents 屬性的另一個示例 −

[a.root.text for a in sents]

輸出

['is', 'having']
spacy_doc_class_contextmanager_and_property.htm
廣告
© . All rights reserved.