从Lucene索引获取文档的顶级频率时,“没有包含实例错误”

时间:2010-05-02 19:10:45

标签: java vector frequency lucene

我正在尝试为Lucene索引中的每个特定文档获取最常出现的术语频率。我正在尝试设置我关心的最常见术语的阈值,可能是20

但是,当调用Comparator时,我得到“无法访问类型DisplayTermVectors的实例”...

所以对于这个函数,我传递了每个文档的向量和最想要知道的顶部术语

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;
  }
}

解释和更正我将非常感激,如果其他人有使用术语频率提取的经验并且做得更好,我会接受所有建议!

请帮忙!!!!感谢名单!

1 个答案:

答案 0 :(得分:0)

我认为您需要制作TermFrq public static class