human
I am working on the file "GroupGensimAndTextblob.ipynb".
The first task is:
Vectorize sentences just to check if it is better if I do this myself other than lexrank
Can you write Python code for it?
 ... Can you provide a the Python code you requested?
assistant
#Here is the Python code you requested.

from sklearn.feature_extraction.text import TfidfVectorizer
import nltk.stem

english_stemmer = nltk.stem.SnowballStemmer('english')

class StemmedTfidfVectorizer(TfidfVectorizer):
    def build_analyzer(self):
        analyzer=super(StemmedTfidfVectorizer,self).build_analyzer()
        return lambda doc:(english_stemmer.stem(w) for w in analyzer(doc))

vectorizer = StemmedTfidfVectorizer(min_df=1, stop_words='english')


article_s =  all_article_sentences
comment_s = all_comments_sentences
for i, (article, comments) in enumerate(zip(article_s, comment_s)): 
    X_article = vectorizer.fit_transform(article)
    X_comments = vectorizer.fit_transform(comments)
    db_a = DBSCAN(eps=0.3, min_samples=2).fit(X_article)
    db_c = DBSCAN(eps=0.3, min_samples=2).fit(X_comments)
    
    print "\nARTICLE {0}".format(i)
    print_results(db_a)
    print "\nCOMMENTS {0}".format(i)
    print_results(db_c)