Spaces:
Running
Running
""" | |
File: model_spacy.py | |
Description: | |
Load a spaCy model (will be used to split a text into sentences) | |
Author: Didier Guillevic | |
Date: 2024-03-30 | |
""" | |
import spacy | |
model_xx_name = 'xx_sent_ud_sm' | |
nlp_xx = spacy.load(model_xx_name) | |
if __name__ == "__main__": | |
text = """ | |
This is a very long text. Actually, not that long but still made of a few sentences. | |
""" | |
sentences = [sent.text.strip() for sent in nlp(text).sents if sent.text.strip()] | |
print(f"Nb of sentences: {len(sentences)}") | |
for i, sent in enumerate(sentences): | |
print(f"{i:2}: {sent}") |