"""
@author: liushuchun
"""
def bow_extractor(corpus, ngram_range=(1, 1)):
	vectorizer = CountVectorizer(min_df=1, ngram_range=ngram_range)
	features = vectorizer.fit_transform(corpus)
	return vectorizer, features
def tfidf_transformer(bow_matrix):
	transformer = TfidfTransformer(norm="l2", smooth_idf=True, use_idf=True)
	tfidf_matrix = transformer.fit_transform(bow_matrix)
	return transformer, tfidf_matrix
def tfidf_extractor(corpus, ngram_range=(1, 1)):
	vectorizer = TfidfVectorizer(min_df=1, norm="l2", smooth_idf=True, use_idf=True, ngram_range=ngram_range)
	features = vectorizer.fit_transform(corpus)
	return vectorizer, features