okapi/vectorizer_tf.py
Mikołaj Pokrywka 18e254888b wip
2022-04-10 18:18:05 +02:00

16 lines
454 B
Python

from sklearn.feature_extraction.text import CountVectorizer, TfidfTransformer
import pandas as pd
class VectorizerTf:
def __init__(self, corpus):
vectorizer = CountVectorizer()
self.tf_matrix = vectorizer.fit_transform(corpus)
self.vectorizer = vectorizer
self.feature_names = self.vectorizer.get_feature_names()
def get_tf_for_document(self, term):
return self.vectorizer.transform([term]).toarray()