package cz.vutbr.feec.utko.xonder02.lda;


public class TfIdf {

    private Dictionary dictionary;

    public TfIdf(Dictionary dictionary) {
        this.dictionary = dictionary;
    }

    public void computeForCorpus(Corpus corpus) {
        int documentCount = corpus.documentCount();

        for (Document document : corpus) {
            for (Term term : document) {
                double tf = term.frequency / document.getTermCount();
                double idf = Math.log(documentCount / (double)dictionary.getTokenCountById(term.id));

                term.frequency = tf * idf;
            }
        }
    }
}
