Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

include method to remove stopwords #163

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions textblob/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from __future__ import unicode_literals, absolute_import
import sys
import json
import re
from collections import defaultdict

import nltk
Expand Down Expand Up @@ -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.
Expand Down