使用spaCy分割文本可以通過以下步驟實現:
pip install spacy
python -m spacy download en_core_web_sm
import spacy
nlp = spacy.load('en_core_web_sm')
text = "This is a sample text. SpaCy can split this text into sentences."
doc = nlp(text)
sentences = [sent.text for sent in doc.sents]
print(sentences)
輸出結果將是分割后的句子列表:
['This is a sample text.', 'SpaCy can split this text into sentences.']
通過以上步驟,你可以使用spaCy庫來對文本進行分割并提取句子。