@@ -0,0 +1,1733 @@
+import java.io.IOException;%0Aimport java.util.List;%0A%0Aimport main.java.hk.ust.comp4321.database.DocInfo;%0Aimport main.java.hk.ust.comp4321.database.ForwardIndexTable;%0Aimport main.java.hk.ust.comp4321.database.IndexInfo;%0Aimport main.java.hk.ust.comp4321.database.InvertedIndexTable;%0A%0A/**%0A * %0A * @author Paul Wong%0A *%0A */%0A%0Apublic class TermWeight %7B%0A%09%0A%09// Constants and fields.%0A%09// -------------------------------------------------------------------------%09%0A%09%0A%09InvertedIndexTable invertedIndexTable;%0A%09private int wordId;%0A%09private int pageId;%0A%09private final int totalPage = 300;%0A%09%0A%09// Constructors.%0A%09// -------------------------------------------------------------------------%0A%0A%09/**%0A%09 * This constructor encapsulates the WordId and PageId.%0A%09 * %0A%09 * @param WordId        the word's id%0A%09 * @param PageId        the page's id%0A%09 */%0A%09public TermWeight(int WordId, int PageId)%0A%09%7B%0A%09%09wordId = WordId;%0A%09%09pageId = PageId;%0A%09%7D%0A%09%0A%09/**%0A%09 * This method converts base 10 log to base 2 log.%0A%09 * %0A%09 * @param n        number needed to be log%0A%09 */%0A%09private static double log2(int n)%0A%09%7B%0A%09    return (Math.log(n) / Math.log(2));%0A%09%7D%0A%09%0A%09/**%0A%09 * This method finds the termWeight by (tf/max. tf) * log (N/df).%0A%09 * %0A%09 * @return termWeight%0A%09 */%0A%09public double getTermWeight() throws IOException%0A%09%7B%0A%09%09int tfmax=0;%0A%09%09int tf = invertedIndexTable.getIndexInfo(wordId, pageId).getPositionList().size(); //tf%0A%09%09int numOfPage = invertedIndexTable.getIndexInfoList(wordId).size(); //N%0A%09%09for(int i=0; i%3CnumOfPage; i++) // max. tf%0A%09%09%7B%0A%09%09%09if (invertedIndexTable.getIndexInfoList(wordId).get(i).getPositionList().size() %3E tfmax)%0A%09%09%09%7B%0A%09%09%09%09tfmax = invertedIndexTable.getIndexInfoList(wordId).get(i).getPositionList().size();%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return tf*tfmax/log2(numOfPage/totalPage);%0A%09%7D%0A%7D%0A

Create TermWeight.java