当前位置: 首页>>代码示例>>Java>>正文


Java PriorityQueue类代码示例

本文整理汇总了Java中org.apache.lucene.util.PriorityQueue的典型用法代码示例。如果您正苦于以下问题:Java PriorityQueue类的具体用法?Java PriorityQueue怎么用?Java PriorityQueue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PriorityQueue类属于org.apache.lucene.util包,在下文中一共展示了PriorityQueue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: updateTop

import org.apache.lucene.util.PriorityQueue; //导入依赖的package包/类
private void updateTop(CandidateSet[] candidates, Candidate[] path, PriorityQueue<Correction> corrections, double cutoffScore, double score)
        throws IOException {
    score = Math.exp(score);
    assert Math.abs(score - score(path, candidates)) < 0.00001;
    if (score > cutoffScore) {
        if (corrections.size() < maxNumCorrections) {
            Candidate[] c = new Candidate[candidates.length];
            System.arraycopy(path, 0, c, 0, path.length);
            corrections.add(new Correction(score, c));
        } else if (corrections.top().compareTo(score, path) < 0) {
            Correction top = corrections.top();
            System.arraycopy(path, 0, top.candidates, 0, path.length);
            top.score = score;
            corrections.updateTop();
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:CandidateScorer.java

示例2: addToQuery

import org.apache.lucene.util.PriorityQueue; //导入依赖的package包/类
/**
 * Add to an existing boolean query the More Like This query from this PriorityQueue
 */
private void addToQuery(PriorityQueue<ScoreTerm> q, BooleanQuery query) {
    ScoreTerm scoreTerm;
    float bestScore = -1;

    while ((scoreTerm = q.pop()) != null) {
        TermQuery tq = new TermQuery(new Term(scoreTerm.topField, scoreTerm.word));

        if (boost) {
            if (bestScore == -1) {
                bestScore = (scoreTerm.score);
            }
            float myScore = (scoreTerm.score);
            tq.setBoost(boostFactor * myScore / bestScore);
        }

        try {
            query.add(tq, BooleanClause.Occur.SHOULD);
        }
        catch (BooleanQuery.TooManyClauses ignore) {
            break;
        }
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:27,代码来源:XMoreLikeThis.java

示例3: retrieveTerms

import org.apache.lucene.util.PriorityQueue; //导入依赖的package包/类
/**
 * Find words for a more-like-this query former.
 *
 * @param docNum
 *          the id of the lucene document from which to find terms
 */
private PriorityQueue<ScoreTerm> retrieveTerms(int docNum) throws IOException
{
  Map<String, Int> termFreqMap = new HashMap<>();
  for (String fieldName : fieldNames) {
    final Terms vector = ir.getTermVector(docNum, fieldName);
    // field does not store term vector info
    if (vector == null) {
      Document d = ir.document(docNum);
      IndexableField[] fields = d.getFields(fieldName);
      for (IndexableField field : fields) {
        final String stringValue = field.stringValue();
        if (stringValue != null) {
          addTermFrequencies(new StringReader(stringValue), termFreqMap, fieldName);
        }
      }
    }
    else {
      addTermFrequencies(termFreqMap, vector);
    }
  }

  return createQueue(termFreqMap);
}
 
开发者ID:oeuvres,项目名称:Alix,代码行数:30,代码来源:MoreLikeThis.java

示例4: createQuery

import org.apache.lucene.util.PriorityQueue; //导入依赖的package包/类
/**
 * Create the More like query from a PriorityQueue
 */
private Query createQuery(PriorityQueue<ScoreTerm> q) {
  BooleanQuery query = new BooleanQuery();
  ScoreTerm scoreTerm;
  float bestScore = -1;

  while ((scoreTerm = q.pop()) != null) {
    TermQuery tq = new TermQuery(new Term(scoreTerm.topField, scoreTerm.word));

    if (boost) {
      if (bestScore == -1) {
        bestScore = (scoreTerm.score);
      }
      float myScore = (scoreTerm.score);
      tq.setBoost(boostFactor * myScore / bestScore);
    }

    try {
      query.add(tq, BooleanClause.Occur.SHOULD);
    }
    catch (BooleanQuery.TooManyClauses ignore) {
      break;
    }
  }
  return query;
}
 
开发者ID:europeana,项目名称:search,代码行数:29,代码来源:MoreLikeThis.java

示例5: addSiblings

import org.apache.lucene.util.PriorityQueue; //导入依赖的package包/类
@Override
protected final int addSiblings(int ordinal, int[] siblings, PriorityQueue<FacetResultNode> pq) {
  FacetResultNode top = pq.top();
  int numResults = 0;
  while (ordinal != TaxonomyReader.INVALID_ORDINAL) {
    int value = values[ordinal];
    if (value > top.value) {
      top.value = value;
      top.ordinal = ordinal;
      top = pq.updateTop();
      ++numResults;
    }
    ordinal = siblings[ordinal];
  }
  return numResults;
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:17,代码来源:IntFacetResultsHandler.java

示例6: addSiblings

import org.apache.lucene.util.PriorityQueue; //导入依赖的package包/类
@Override
protected final int addSiblings(int ordinal, int[] siblings, PriorityQueue<FacetResultNode> pq) {
  FacetResultNode top = pq.top();
  int numResults = 0;
  while (ordinal != TaxonomyReader.INVALID_ORDINAL) {
    float value = values[ordinal];
    if (value > top.value) {
      top.value = value;
      top.ordinal = ordinal;
      top = pq.updateTop();
      ++numResults;
    }
    ordinal = siblings[ordinal];
  }
  return numResults;
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:17,代码来源:FloatFacetResultsHandler.java

示例7: buildDocHits

import org.apache.lucene.util.PriorityQueue; //导入依赖的package包/类
/** Construct the array of doc hits for the hit group. */
private void buildDocHits(int group, ResultGroup resultGroup) 
{
  PriorityQueue queue = hitQueue[group];
  int nFound = queue.size();
  DocHitImpl[] hitArray = new DocHitImpl[nFound];
  for (int i = 0; i < nFound; i++) {
    int index = nFound - i - 1;
    hitArray[index] = (DocHitImpl)queue.pop();
  }

  int start = startDoc[group];
  int max = maxDocs[group];

  int nHits = Math.max(0, Math.min(nFound - start, max));
  resultGroup.docHits = new DocHit[nHits];

  resultGroup.totalDocs = nDocHits(group);
  resultGroup.startDoc = start;
  resultGroup.endDoc = start + nHits;

  for (int i = startDoc[group]; i < nFound; i++)
    resultGroup.docHits[i - start] = hitArray[i];
}
 
开发者ID:CDLUC3,项目名称:dash-xtf,代码行数:25,代码来源:GroupCounts.java

示例8: createQueue

import org.apache.lucene.util.PriorityQueue; //导入依赖的package包/类
/**
 * Create a PriorityQueue from a word->tf map.
 *
 * @param words a map of words keyed on the word(String) with Int objects as the values.
 */
private PriorityQueue createQueue(IndexReader indexReader, Map words)
  throws IOException 
{
  // Will order words by score
  int queueSize = Math.min(words.size(), maxQueryTerms);
  QueryWordQueue queue = new QueryWordQueue(queueSize);

  // For each term...
  Iterator it = words.keySet().iterator();
  while (it.hasNext()) 
  {
    String word = (String)it.next();
    float score = ((Flt)words.get(word)).x;

    // Okay, add an entry to the queue.
    queue.insert(new QueryWord(word, score));
  }

  return queue;
}
 
开发者ID:CDLUC3,项目名称:dash-xtf,代码行数:26,代码来源:MoreLikeThisQuery.java

示例9: insertInto

import org.apache.lucene.util.PriorityQueue; //导入依赖的package包/类
public final boolean insertInto(PriorityQueue queue) 
{
  if (docHit == null)
    docHit = new DocHitImpl(doc, score);

  try 
  {
    docHit.setSpanSource(spanSrc);
    boolean inserted = queue.insert(docHit);
    
    // If we're keeping this hit, make sure spans have been grabbed. 
    if (inserted)
      docHit.totalSnippets();
    
    return inserted;
  }
  finally {
    docHit.setSpanSource(null); // prevent memory leaks
  }

}
 
开发者ID:CDLUC3,项目名称:dash-xtf,代码行数:22,代码来源:DefaultQueryProcessor.java

示例10: findCandidates

import org.apache.lucene.util.PriorityQueue; //导入依赖的package包/类
public void findCandidates(CandidateSet[] candidates, Candidate[] path, int ord, int numMissspellingsLeft,
        PriorityQueue<Correction> corrections, double cutoffScore, final double pathScore) throws IOException {
    CandidateSet current = candidates[ord];
    if (ord == candidates.length - 1) {
        path[ord] = current.originalTerm;
        updateTop(candidates, path, corrections, cutoffScore, pathScore + scorer.score(path, candidates, ord, gramSize));
        if (numMissspellingsLeft > 0) {
            for (int i = 0; i < current.candidates.length; i++) {
                path[ord] = current.candidates[i];
                updateTop(candidates, path, corrections, cutoffScore, pathScore + scorer.score(path, candidates, ord, gramSize));
            }
        }
    } else {
        if (numMissspellingsLeft > 0) {
            path[ord] = current.originalTerm;
            findCandidates(candidates, path, ord + 1, numMissspellingsLeft, corrections, cutoffScore, pathScore + scorer.score(path, candidates, ord, gramSize));
            for (int i = 0; i < current.candidates.length; i++) {
                path[ord] = current.candidates[i];
                findCandidates(candidates, path, ord + 1, numMissspellingsLeft - 1, corrections, cutoffScore, pathScore + scorer.score(path, candidates, ord, gramSize));
            }
        } else {
            path[ord] = current.originalTerm;
            findCandidates(candidates, path, ord + 1, 0, corrections, cutoffScore, pathScore + scorer.score(path, candidates, ord, gramSize));
        }
    }

}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:28,代码来源:CandidateScorer.java

示例11: retrieveTerms

import org.apache.lucene.util.PriorityQueue; //导入依赖的package包/类
/**
 * Find words for a more-like-this query former.
 *
 * @param docNum the id of the lucene document from which to find terms
 */
private PriorityQueue<ScoreTerm> retrieveTerms(int docNum) throws IOException {
    Map<String, Int> termFreqMap = new HashMap<>();
    for (String fieldName : fieldNames) {
        final Fields vectors = ir.getTermVectors(docNum);
        final Terms vector;
        if (vectors != null) {
            vector = vectors.terms(fieldName);
        } else {
            vector = null;
        }

        // field does not store term vector info
        if (vector == null) {
            Document d = ir.document(docNum);
            IndexableField fields[] = d.getFields(fieldName);
            for (IndexableField field : fields) {
                final String stringValue = field.stringValue();
                if (stringValue != null) {
                    addTermFrequencies(new FastStringReader(stringValue), termFreqMap, fieldName);
                }
            }
        } else {
            addTermFrequencies(termFreqMap, vector, fieldName);
        }
    }

    return createQueue(termFreqMap);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:34,代码来源:XMoreLikeThis.java

示例12: retrieveInterestingTerms

import org.apache.lucene.util.PriorityQueue; //导入依赖的package包/类
/**
 * @see #retrieveInterestingTerms(java.io.Reader, String)
 */
public String[] retrieveInterestingTerms(int docNum) throws IOException {
    ArrayList<Object> al = new ArrayList<>(maxQueryTerms);
    PriorityQueue<ScoreTerm> pq = retrieveTerms(docNum);
    ScoreTerm scoreTerm;
    int lim = maxQueryTerms; // have to be careful, retrieveTerms returns all words but that's probably not useful to our caller...
    // we just want to return the top words
    while (((scoreTerm = pq.pop()) != null) && lim-- > 0) {
        al.add(scoreTerm.word); // the 1st entry is the interesting word
    }
    String[] res = new String[al.size()];
    return al.toArray(res);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:16,代码来源:XMoreLikeThis.java

示例13: buildQueryFromFieldTermFrequencies

import org.apache.lucene.util.PriorityQueue; //导入依赖的package包/类
private RFQuery buildQueryFromFieldTermFrequencies(Map<String, Map<String, Flt>> fieldTermFreq, boolean contentStreamQuery) throws IOException {

        List<RFTerm> interestingTerms = new ArrayList<RFTerm>();
        for(String fieldName: fieldTermFreq.keySet()){
            Map<String,Flt> words = fieldTermFreq.get(fieldName);
            PriorityQueue<RFTerm> queue = createQueue(fieldName, words, contentStreamQuery);
            interestingTerms.addAll(getMostInterestingTerms(queue));
        }

        RFQuery rfResult = new RFQuery(interestingTerms, getMm());
        return rfResult;
    }
 
开发者ID:DiceTechJobs,项目名称:RelevancyFeedback,代码行数:13,代码来源:RelevancyFeedback.java

示例14: getMostInterestingTerms

import org.apache.lucene.util.PriorityQueue; //导入依赖的package包/类
/**
 * Compute the top most interesting terms from the priority queue of all RF Terms
 */
private List<RFTerm> getMostInterestingTerms(PriorityQueue<RFTerm> q) {

    int maxTerms = (maxQueryTermsPerField <= 0) ? Integer.MAX_VALUE : maxQueryTermsPerField;
    double sumQuaredBoost = 0.0f;

    List<RFTerm> interestingTerms = new ArrayList<RFTerm>();
    RFTerm currentTerm = null;
    while ((currentTerm = q.pop()) != null
            && interestingTerms.size() < maxTerms) {
        // if not boost, then set score to 1.0 not tf.idf
        // now implemented inside RFTerm

        // if not boost, boostValue == 1.0, so this just adds 1 as desired
        sumQuaredBoost += Math.pow(currentTerm.getTermWeight(),2);
        interestingTerms.add(currentTerm);
    }

    float vectorLength = (float) Math.sqrt(sumQuaredBoost);
    if(vectorLength <= 0.0){
        return new ArrayList<RFTerm>();
    }

    if(this.isNormalizeFieldBoosts()){
        for(RFTerm term: interestingTerms){
            term.setVectorLength(vectorLength);
        }
    }
    return interestingTerms;
}
 
开发者ID:DiceTechJobs,项目名称:RelevancyFeedback,代码行数:33,代码来源:RelevancyFeedback.java

示例15: retrieveInterestingTerms

import org.apache.lucene.util.PriorityQueue; //导入依赖的package包/类
/**
 * @see #retrieveInterestingTerms(java.io.Reader, String)
 */
public String[] retrieveInterestingTerms(int docNum) throws IOException
{
  ArrayList<Object> al = new ArrayList<>(maxQueryTerms);
  PriorityQueue<ScoreTerm> pq = retrieveTerms(docNum);
  ScoreTerm scoreTerm;
  int lim = maxQueryTerms; // have to be careful, retrieveTerms returns all words but that's probably not
                           // useful to our caller...
  // we just want to return the top words
  while (((scoreTerm = pq.pop()) != null) && lim-- > 0) {
    al.add(scoreTerm.word); // the 1st entry is the interesting word
  }
  String[] res = new String[al.size()];
  return al.toArray(res);
}
 
开发者ID:oeuvres,项目名称:Alix,代码行数:18,代码来源:MoreLikeThis.java


注:本文中的org.apache.lucene.util.PriorityQueue类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。