package gannuNLP.keywordextraction;
import gannuNLP.corpus.WSM;
/**
* Filter for extracting keywords using TF-IDF measure.
* @author Francisco Viveros-Jiménez
*
*/
public class KeywordsByTFIDF extends KeywordExtractor {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Creates a TF-IDF keyword extractor.
*/
public KeywordsByTFIDF() {
super();
this.name="KeyWordsByTFIDF";
}
@Override
public void sortWords() {
int i,j,sel;
double aux;
WSM waux;
double idf[]= new double[this.words.size()];
for(i=0;i<this.words.size();i++)
idf[i]=this.source.getTFIDF(this.words.get(i).getDimension());
for(i=0;i<this.words.size()-1;i++)
{
sel=i;
for(j=i+1;j<this.words.size();j++)
{
if(idf[j]>idf[sel])
sel=j;
}
aux=idf[sel];
idf[sel]=idf[i];
idf[i]=aux;
waux=this.words.get(sel);
this.words.set(sel, this.words.get(i));
this.words.set(i, waux);
}
}
}