views:

39

answers:

1

Hello !

I am trying to get the most occurring term frequencies for every particular document in Lucene index. I am trying to set the treshold of top occuring terms that I care about, maybe 20

However, I am getting the "no inclosing instance of type DisplayTermVectors is accessible" when calling Comparator...

So to this function I pass vector of every document and max top terms i would like to know

protected static Collection getTopTerms(TermFreqVector tfv, int maxTerms){
  String[] terms = tfv.getTerms();   
  int[] tFreqs = tfv.getTermFrequencies();  

  List result = new ArrayList(terms.length); 

  for (int i = 0; i < tFreqs.length; i++) {
    TermFrq tf = new TermFrq(terms[i], tFreqs[i]);
    result.add(tf); 

  }
  Collections.sort(result, new FreqComparator()); 
  if(maxTerms < result.size()){
    result = result.subList(0, maxTerms);
  }
  return result; 
}
/*Class for objects to hold the term/freq pairs*/

static class TermFrq{
   private String term;
   private int freq;

   public TermFrq(String term,int freq){
   this.term = term;
   this.freq = freq;
 }
   public String getTerm(){
   return this.term;
 }
 public int getFreq(){
   return this.freq;
 }
}


/*Comparator to compare the objects by the frequency*/
 class FreqComparator implements Comparator{
  public int compare(Object pair1, Object pair2){
   int f1 = ((TermFrq)pair1).getFreq();
   int f2 = ((TermFrq)pair2).getFreq();

   if(f1 > f2) return 1;
   else if(f1 < f2) return -1;
   else return 0;
  }
}

Explanations and corrections i will very much appreciate, and also if someone else had experience with term frequency extraction and did it better way, I am opened to all suggestions!

Please help!!!! Thanx!

A: 

I think you'd need to make your TermFrq public static class.

extraneon