File size: 586 Bytes
fe02c49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"""
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}")