Package org.getopt.luke

Examples of org.getopt.luke.SlowThread


    if (reader == null) {
      app.showStatus("No index loaded");
      cleanChart();
      return;
    }
    SlowThread st = new SlowThread(app) {
      public void execute() {
        try {
          int numBuckets = 100;
          TermsEnum te = MultiFields.getTerms(ir, field).iterator(null);
          ArrayList<TermCount> terms = new ArrayList<TermCount>();

          // most terms occur very infrequently - just keep group totals for the DFs
          // representing these "long tail" terms.
          int longTailDfStart = 1;
          int longTailDfEnd = 1000;
          int longTailTermDfCounts[] = new int[(longTailDfEnd - longTailDfStart) + 1];

          // For "short tail" terms there are less of them and they represent a lot
          // of different
          // DFs (typically in the thousands) so unlike long-tail terms we can't
          // predict what common DF buckets to accumulate counts in. For this reason
          // we don't attempt
          // to total them and keep a list of them individually (shouldn't occupy
          // too much ram)

          int numUniqueTerms = 0;
          while (te.next() != null) {
            numUniqueTerms++;
            int df = te.docFreq();
            if (df <= longTailDfEnd) {
              int i = df - longTailDfStart;
              longTailTermDfCounts[i]++;
            } else {
              terms.add(new TermCount(new Term(field, te.term().utf8ToString()), df));
            }
          }

          TermCount sortedTerms[] = (TermCount[]) terms.toArray(new TermCount[terms
              .size()]);
          Arrays.sort(sortedTerms);

          int termsPerBucket;
          if (numUniqueTerms < 100) {
            termsPerBucket = 1;
            numBuckets = numUniqueTerms;
          } else {
            termsPerBucket = numUniqueTerms / numBuckets;
          }
          ArrayList buckets = new ArrayList();
          Bucket currentBucket = new Bucket();
          buckets.add(currentBucket);
          for (int i = 0; i < sortedTerms.length; i++) {
            currentBucket.addTermDf(sortedTerms[i].df);
            if (currentBucket.numTermsInThisBucket >= termsPerBucket) {
              // start a new bucket
              currentBucket = new Bucket();
              buckets.add(currentBucket);
            }
          }
          // now work through the aggregated long-tail terms - start from
          // most common DF down to least common DF
          for (int i = longTailTermDfCounts.length - 1; i >= 0; i--) {
            int df = i + longTailDfStart;
            int numTerms = longTailTermDfCounts[i];
            for (int t = 0; t < numTerms; t++) {
              currentBucket.addTermDf(df);
              if (currentBucket.numTermsInThisBucket >= termsPerBucket) {
                // start a new bucket
                currentBucket = new Bucket();
                buckets.add(currentBucket);
              }
            }
          }
          if (currentBucket.numTermsInThisBucket == 0) buckets.remove(currentBucket);
          Bucket bucketsResult[] = (Bucket[]) buckets.toArray(new Bucket[buckets.size()]);
          float termBucketTotals[] = new float[bucketsResult.length];
          int maxDf = 0;
          for (int i = 0; i < bucketsResult.length; i++) {
            termBucketTotals[i] = bucketsResult[i].getAverageDf();
            maxDf = (int) Math.max(maxDf, termBucketTotals[i]);
          }
          // update the GUI
          Object maxdf = app.find(myUi, "maxdf");
          app.setString(maxdf, "text", "" + maxDf);
          Object maxterm = app.find(myUi, "maxterm");
          Object midterm = app.find(myUi, "midterm");
          app.setString(maxterm, "text", numUniqueTerms + "");
          app.setString(midterm, "text", (numUniqueTerms / 2) + "");

          chart.setScores(termBucketTotals);
          chart.invalidate();
          app.repaint();
        } catch (Exception e) {
          app.showStatus("ERROR: " + e.getMessage());
        }       
      }
    };
    if (app.isSlowAccess()) {
      st.start();
    } else {
      st.execute();
    }
  }
View Full Code Here


    if (reader == null) {
      app.showStatus("No index loaded");
      cleanChart();
      return;
    }
    SlowThread st = new SlowThread(app) {
      public void execute() {
        try {
          int numAgeGroups = 100;
          float numDocs = ir.maxDoc();
          if (numDocs < numAgeGroups) numAgeGroups = ir.maxDoc();
          float ageTotals[] = new float[numAgeGroups];
          TermsEnum te = MultiFields.getTerms(ir, field).iterator(null);
          while (te.next() != null) {
            DocsEnum td = te.docs(null, null, 0);
            td.nextDoc();
            float firstDocId = td.docID();
            int ageBracket = (int) ((firstDocId / numDocs) * numAgeGroups);
            ageTotals[ageBracket]++;
          }
          float total = 0.0f;
          float max = 0.0f;
          for (int i = 0; i < ageTotals.length; i++) {
            if (ageTotals[i] > max) max = ageTotals[i];
            total += ageTotals[i];
            if (i > 0 && cumul) {
              ageTotals[i] += ageTotals[i - 1]; // make totals cumulative
            }
          }
          Object maxpct = app.find(myUi, "maxpct");
          if (cumul) {
            app.setString(maxpct, "text", "100 %");
          } else {
            app.setString(maxpct, "text", (float)Math.round(max * 10000.0f / total) / 100.0f + " %");
          }
          chart.setScores(ageTotals);
          chart.invalidate();
          app.repaint();
        } catch (Exception e) {
          app.showStatus("ERROR: " + e.getMessage());
        }       
      }
    };
    if (app.isSlowAccess()) {
      st.start();
    } else {
      st.execute();
    }
  }
View Full Code Here

    try {
      bufferSize = Integer.parseInt(app.getString(bufSize, "text"));
    } catch (Exception e) {
      //
    }
    SlowThread st = new SlowThread(app) {
      public void execute() {
        openIndex(uriTxt);
      }
    };
    st.start();
  }
View Full Code Here

TOP

Related Classes of org.getopt.luke.SlowThread

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.