Skip to content

Commit 22a0055

Browse files
authored
Merge pull request #263 from AbuBakkar32/Abu-Bakkar
Abu bakkar
2 parents d21ed85 + f91e7da commit 22a0055

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

GeoPy/NLTK.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,19 @@
11
import nltk
22
from nltk.corpus import stopwords
3-
from nltk.tokenize import word_tokenize
3+
from nltk.tokenize import wordpunct_tokenize
44
from string import punctuation
5+
from colorama import Fore
56

7+
# Example sentence
68
example_sent = "This is a sample sentence, showing off the stop words filtration."
79

10+
# Load English stopwords
811
stop_words = set(stopwords.words('english'))
9-
print(stop_words)
10-
word_tokens = word_tokenize(example_sent)
11-
print(word_tokens)
1212

13-
# filtered_sentence = [w for w in word_tokens if not w in stop_words]
14-
15-
filtered_sentence = []
16-
17-
for w in word_tokens:
18-
if w not in stop_words:
19-
filtered_sentence.append(w)
13+
# Tokenize and filter in one step
14+
filtered_sentence = [
15+
word.upper() for word in wordpunct_tokenize(example_sent)
16+
if word.lower() not in stop_words and word not in punctuation
17+
]
2018

2119
print(filtered_sentence)
22-
23-
filter = []
24-
for a in filtered_sentence:
25-
if a not in punctuation:
26-
filter.append(a)
27-
print(filter)
28-

0 commit comments

Comments
 (0)