-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
30 lines (23 loc) · 893 Bytes
/
utils.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
# -*- coding: utf-8 -*-
import nltk
from nltk.corpus import stopwords
from string import punctuation
def is_stop_word(word):
"""Function to check if a word is a Stopword or a punctuation symbol."""
return word in stopwords.words('english') or word in punctuation
def initialize_nltk_tokenizer():
"""Function to initialize tokenizer from nltk library."""
try:
nltk.data.find('tokenizers/punkt')
except LookupError:
print "Downloading and installing Punkt tokenizer..."
nltk.download('punkt')
print "Punkt tokenizer was installed!"
def initialize_nltk_stopwords():
"""Function to initialize stopwords from nltk library."""
try:
nltk.data.find('corpora/stopwords')
except LookupError:
print "Downloading and installing Stopwords..."
nltk.download('stopwords')
print "Stopwords was installed!"