Stop words
#! /usr/bin/env python3
import nltk
# Open File > Settings > Project from the PyCharm menu.
# Select your current project.
# Click the Python Interpreter tab within your project tab.
# Click the small + symbol to add a new library to the project.
# Now type in the library to be installed, in your example "nltk" without quotes, and click Install Package.
# Wait for the installation to terminate and close all popup windows.
nltk.download('stopwords')
from nltk.corpus import stopwords
en_stopwords = stopwords.words('english')
print('Stopwords in English')
print(en_stopwords)
print()
sentence_1 = 'It was too far to go to the shop and he did not want her to walk'
sentence_1_lower = sentence_1.lower()
sentence_1_lower_no_stopwords = ' '.join( [ word for word in sentence_1_lower.split() if word not in en_stopwords ] )
print("Full Sentence: ", sentence_1)
print("Full Sentence Lower: ", sentence_1_lower)
print("Stopword Sentence: ", sentence_1_lower_no_stopwords)
# remove stop words
en_stopwords.remove('did')
en_stopwords.remove('not')
en_stopwords.append('go')
sentence_1_lower_no_stopwords_custom = ' '.join( [ word for word in sentence_1_lower.split() if word not in en_stopwords ] )
print("Stopword Sentence Custom: ", sentence_1_lower_no_stopwords_custom)
Stopwords in English
[‘a’, ‘about’, ‘above’, ‘after’, ‘again’, ‘against’, ‘ain’, ‘all’, ‘am’, ‘an’, ‘and’, ‘any’, ‘are’, ‘aren’, “aren’t”, ‘as’, ‘at’, ‘be’, ‘because’, ‘been’, ‘before’, ‘being’, ‘below’, ‘between’, ‘both’, ‘but’, ‘by’, ‘can’, ‘couldn’, “couldn’t”, ‘d’, ‘did’, ‘didn’, “didn’t”, ‘do’, ‘does’, ‘doesn’, “doesn’t”, ‘doing’, ‘don’, “don’t”, ‘down’, ‘during’, ‘each’, ‘few’, ‘for’, ‘from’, ‘further’, ‘had’, ‘hadn’, “hadn’t”, ‘has’, ‘hasn’, “hasn’t”, ‘have’, ‘haven’, “haven’t”, ‘having’, ‘he’, “he’d”, “he’ll”, ‘her’, ‘here’, ‘hers’, ‘herself’, “he’s”, ‘him’, ‘himself’, ‘his’, ‘how’, ‘i’, “i’d”, ‘if’, “i’ll”, “i’m”, ‘in’, ‘into’, ‘is’, ‘isn’, “isn’t”, ‘it’, “it’d”, “it’ll”, “it’s”, ‘its’, ‘itself’, “i’ve”, ‘just’, ‘ll’, ‘m’, ‘ma’, ‘me’, ‘mightn’, “mightn’t”, ‘more’, ‘most’, ‘mustn’, “mustn’t”, ‘my’, ‘myself’, ‘needn’, “needn’t”, ‘no’, ‘nor’, ‘not’, ‘now’, ‘o’, ‘of’, ‘off’, ‘on’, ‘once’, ‘only’, ‘or’, ‘other’, ‘our’, ‘ours’, ‘ourselves’, ‘out’, ‘over’, ‘own’, ‘re’, ‘s’, ‘same’, ‘shan’, “shan’t”, ‘she’, “she’d”, “she’ll”, “she’s”, ‘should’, ‘shouldn’, “shouldn’t”, “should’ve”, ‘so’, ‘some’, ‘such’, ‘t’, ‘than’, ‘that’, “that’ll”, ‘the’, ‘their’, ‘theirs’, ‘them’, ‘themselves’, ‘then’, ‘there’, ‘these’, ‘they’, “they’d”, “they’ll”, “they’re”, “they’ve”, ‘this’, ‘those’, ‘through’, ‘to’, ‘too’, ‘under’, ‘until’, ‘up’, ‘ve’, ‘very’, ‘was’, ‘wasn’, “wasn’t”, ‘we’, “we’d”, “we’ll”, “we’re”, ‘were’, ‘weren’, “weren’t”, “we’ve”, ‘what’, ‘when’, ‘where’, ‘which’, ‘while’, ‘who’, ‘whom’, ‘why’, ‘will’, ‘with’, ‘won’, “won’t”, ‘wouldn’, “wouldn’t”, ‘y’, ‘you’, “you’d”, “you’ll”, ‘your’, “you’re”, ‘yours’, ‘yourself’, ‘yourselves’, “you’ve”]
Output
C:\Users\Win10x64i7\PycharmProjects\StopWords\.venv\Scripts\python.exe C:\Users\Win10x64i7\PycharmProjects\StopWords\.venv\StopWords.py
[nltk_data] Downloading package stopwords to
[nltk_data] C:\Users\Win10x64i7\AppData\Roaming\nltk_data…
[nltk_data] Package stopwords is already up-to-date!
Stopwords in English
[‘a’, ‘about’, ‘above’, ‘after’, ‘again’, ‘against’, ‘ain’, ‘all’, ‘am’, ‘an’, ‘and’, ‘any’, ‘are’, ‘aren’, “aren’t”, ‘as’, ‘at’, ‘be’, ‘because’, ‘been’, ‘before’, ‘being’, ‘below’, ‘between’, ‘both’, ‘but’, ‘by’, ‘can’, ‘couldn’, “couldn’t”, ‘d’, ‘did’, ‘didn’, “didn’t”, ‘do’, ‘does’, ‘doesn’, “doesn’t”, ‘doing’, ‘don’, “don’t”, ‘down’, ‘during’, ‘each’, ‘few’, ‘for’, ‘from’, ‘further’, ‘had’, ‘hadn’, “hadn’t”, ‘has’, ‘hasn’, “hasn’t”, ‘have’, ‘haven’, “haven’t”, ‘having’, ‘he’, “he’d”, “he’ll”, ‘her’, ‘here’, ‘hers’, ‘herself’, “he’s”, ‘him’, ‘himself’, ‘his’, ‘how’, ‘i’, “i’d”, ‘if’, “i’ll”, “i’m”, ‘in’, ‘into’, ‘is’, ‘isn’, “isn’t”, ‘it’, “it’d”, “it’ll”, “it’s”, ‘its’, ‘itself’, “i’ve”, ‘just’, ‘ll’, ‘m’, ‘ma’, ‘me’, ‘mightn’, “mightn’t”, ‘more’, ‘most’, ‘mustn’, “mustn’t”, ‘my’, ‘myself’, ‘needn’, “needn’t”, ‘no’, ‘nor’, ‘not’, ‘now’, ‘o’, ‘of’, ‘off’, ‘on’, ‘once’, ‘only’, ‘or’, ‘other’, ‘our’, ‘ours’, ‘ourselves’, ‘out’, ‘over’, ‘own’, ‘re’, ‘s’, ‘same’, ‘shan’, “shan’t”, ‘she’, “she’d”, “she’ll”, “she’s”, ‘should’, ‘shouldn’, “shouldn’t”, “should’ve”, ‘so’, ‘some’, ‘such’, ‘t’, ‘than’, ‘that’, “that’ll”, ‘the’, ‘their’, ‘theirs’, ‘them’, ‘themselves’, ‘then’, ‘there’, ‘these’, ‘they’, “they’d”, “they’ll”, “they’re”, “they’ve”, ‘this’, ‘those’, ‘through’, ‘to’, ‘too’, ‘under’, ‘until’, ‘up’, ‘ve’, ‘very’, ‘was’, ‘wasn’, “wasn’t”, ‘we’, “we’d”, “we’ll”, “we’re”, ‘were’, ‘weren’, “weren’t”, “we’ve”, ‘what’, ‘when’, ‘where’, ‘which’, ‘while’, ‘who’, ‘whom’, ‘why’, ‘will’, ‘with’, ‘won’, “won’t”, ‘wouldn’, “wouldn’t”, ‘y’, ‘you’, “you’d”, “you’ll”, ‘your’, “you’re”, ‘yours’, ‘yourself’, ‘yourselves’, “you’ve”]
Full Sentence: It was too far to go to the shop and he did not want her to walk
Full Sentence Lower: it was too far to go to the shop and he did not want her to walk
Stopword Sentence: far go shop want walk
Stopword Sentence Custom: far shop did not want walk
Process finished with exit code 0