Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 754083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:58:17+00:00 2026-05-14T14:58:17+00:00

I am trying to get the most occurring term frequencies for every particular document

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T14:58:18+00:00Added an answer on May 14, 2026 at 2:58 pm

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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get the 5 most occurring IDs in my table, my table
I've been trying to get the most recent Facebook Status for a fan page
Tearing my hair out trying to get the most simple of tutorials to run,
I am new to YUI. Just trying to get a most basic functioning example
We've got a pretty complicated repository here, and I'm trying to get the most
Silly question 4 most, I guess, I'm trying to get my last li, which
I am trying to get the most recent data item from the datastore. I
Trying to get data in the most efficient way possible for some reports, using
I'm trying to get the most recent Friday in SQL Server 2008. I have
I have been trying to get this to work for most of the day

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.