From 5f9d518697fe202f1e4413c01eba3036fb4f3cf6 Mon Sep 17 00:00:00 2001 From: mynameisvinn Date: Sun, 14 May 2017 10:55:18 -0400 Subject: [PATCH] include method to remove stopwords --- textblob/blob.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/textblob/blob.py b/textblob/blob.py index f8182f20..b74058f3 100644 --- a/textblob/blob.py +++ b/textblob/blob.py @@ -23,6 +23,7 @@ from __future__ import unicode_literals, absolute_import import sys import json +import re from collections import defaultdict import nltk @@ -368,6 +369,16 @@ def __init__(self, text, tokenizer=None, _initialize_models(self, tokenizer, pos_tagger, np_extractor, analyzer, parser, classifier) + @cached_property + def remove_stopwords(self,fname="stopwords.txt"): + """Take raw string and remove stop words. + :rtype: str + """ + with open(fname) as f: + stopwords = [word for line in f for word in re.findall(r'\w+', line)] + clean_string = ' '.join([word for word in self.raw.split() if word not in stopwords]) + return clean_string + @cached_property def words(self): """Return a list of word tokens. This excludes punctuation characters.