-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSentence_Detection.py
63 lines (43 loc) · 1.45 KB
/
Sentence_Detection.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""
Assignment No 1
Name - Abhishek Kusalkar
Batch - B2
Roll No - 35
Assignment Title : Text pre-processing using NLP operation : perform Tokenization Stop word removal, Punctuation removal,using Spacy or NLTK Library
"""
# Import the necessary libraries
import spacy
# Import the necessary libraries
nlp=spacy.load("en_core_web_sm")
from collections import Counter
# Define a text containing a poem or a set of sentences
about_text = (
"Your smile makes me smile,"
"Your laugh makes me laugh,"
"Your eyes are enchanting,"
"You make my thoughts seem daft."
"Since the day I first laid eyes on you,"
"My feelings grew and grew."
"In that first conversation my knees clicked and clacked,"
"And those butterflies flipped and flapped."
"And as I spill these simple rhymes,"
"My mind goes over time and time,"
"I have a crush, a little teenage crush"
"I don't know what to do, about this lovely little crush"
)
# Process the text using the spaCy model
about_doc = nlp(about_text)
# Split the text into individual sentences
sentences = list(about_doc.sents)
# Print the number of sentences in the text
len(sentences)
# Iterate through each sentence and print the first 5 characters of each sentence
for sentence in sentences:
print(f"{sentence[:5]}...")
# OUTPUT -
"""
Your smile makes me smile...
Since the day I first...
In that first conversation my...
And as I spill these...
"""