當前位置: 首頁>>代碼示例>>Java>>正文


Java Explanation.match方法代碼示例

本文整理匯總了Java中org.apache.lucene.search.Explanation.match方法的典型用法代碼示例。如果您正苦於以下問題:Java Explanation.match方法的具體用法?Java Explanation.match怎麽用?Java Explanation.match使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.lucene.search.Explanation的用法示例。


在下文中一共展示了Explanation.match方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: explain

import org.apache.lucene.search.Explanation; //導入方法依賴的package包/類
@Override
public Explanation explain(LeafReaderContext context, int doc,
                           float finalScore, List<Explanation> featureExplanations) {

  String modelDescription = "";
  for (int layer = 0; layer < weightMatrices.size(); layer++) {
    float[][] weightMatrix = weightMatrices.get(layer);
    int numRows = weightMatrix.length;
    int numCols = weightMatrix[0].length;
    if (layer == 0) {
      modelDescription += String.format("Input has %1$d features.", numCols - 1);
    } else {
      modelDescription += String.format("%nHidden layer #%1$d has %2$d units.", layer, numCols);
    }
  }
  return Explanation.match(finalScore, modelDescription);
}
 
開發者ID:airalcorn2,項目名稱:RankNet,代碼行數:18,代碼來源:RankNet.java

示例2: explainTFNorm

import org.apache.lucene.search.Explanation; //導入方法依賴的package包/類
private Explanation explainTFNorm(int doc, Explanation freq, BM25StatsFixed stats, NumericDocValues norms) {
  List<Explanation> subs = new ArrayList<>();
  subs.add(freq);
  subs.add(Explanation.match(k1, "parameter k1"));
  if (norms == null) {
    subs.add(Explanation.match(0, "parameter b (norms omitted for field)"));
    return Explanation.match(
        (freq.getValue() * (k1 + 1)) / (freq.getValue() + k1),
        "tfNorm, computed from:", subs);
  } else {
    float doclen = norms.get(doc);
    subs.add(Explanation.match(b, "parameter b"));
    subs.add(Explanation.match(stats.avgdl, "avgFieldLength"));
    subs.add(Explanation.match(doclen, "fieldLength"));
    return Explanation.match(
        (freq.getValue() * (k1 + 1)) / (freq.getValue() + k1 * (1 - b + b * doclen/stats.avgdl)),
        "tfNorm, computed from:", subs);
  }
}
 
開發者ID:sebastian-hofstaetter,項目名稱:ir-generalized-translation-models,代碼行數:20,代碼來源:BM25SimilarityLossless.java

示例3: explain

import org.apache.lucene.search.Explanation; //導入方法依賴的package包/類
@Override
public Explanation explain(int topLevelDocId, SearchContext context, RescoreSearchContext rescoreContext,
                           Explanation sourceExplanation) throws IOException {
    QueryRescoreContext rescore = (QueryRescoreContext) rescoreContext;
    ContextIndexSearcher searcher = context.searcher();
    if (sourceExplanation == null) {
        // this should not happen but just in case
        return Explanation.noMatch("nothing matched");
    }
    // TODO: this isn't right?  I.e., we are incorrectly pretending all first pass hits were rescored?  If the requested docID was
    // beyond the top rescoreContext.window() in the first pass hits, we don't rescore it now?
    Explanation rescoreExplain = searcher.explain(rescore.query(), topLevelDocId);
    float primaryWeight = rescore.queryWeight();

    Explanation prim;
    if (sourceExplanation.isMatch()) {
        prim = Explanation.match(
                sourceExplanation.getValue() * primaryWeight,
                "product of:", sourceExplanation, Explanation.match(primaryWeight, "primaryWeight"));
    } else {
        prim = Explanation.noMatch("First pass did not match", sourceExplanation);
    }

    // NOTE: we don't use Lucene's Rescorer.explain because we want to insert our own description with which ScoreMode was used.  Maybe
    // we should add QueryRescorer.explainCombine to Lucene?
    if (rescoreExplain != null && rescoreExplain.isMatch()) {
        float secondaryWeight = rescore.rescoreQueryWeight();
        Explanation sec = Explanation.match(
                rescoreExplain.getValue() * secondaryWeight,
                "product of:",
                rescoreExplain, Explanation.match(secondaryWeight, "secondaryWeight"));
        QueryRescoreMode scoreMode = rescore.scoreMode();
        return Explanation.match(
                scoreMode.combine(prim.getValue(), sec.getValue()),
                scoreMode + " of:",
                prim, sec);
    } else {
        return prim;
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:41,代碼來源:QueryRescorer.java

示例4: parseExplanation

import org.apache.lucene.search.Explanation; //導入方法依賴的package包/類
private static Explanation parseExplanation(XContentParser parser) throws IOException {
    ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.currentToken(), parser::getTokenLocation);
    XContentParser.Token token;
    Float value = null;
    String description = null;
    List<Explanation> details = new ArrayList<>();
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        ensureExpectedToken(XContentParser.Token.FIELD_NAME, token, () -> parser.getTokenLocation());
        String currentFieldName = parser.currentName();
        token = parser.nextToken();
        if (Fields.VALUE.equals(currentFieldName)) {
            value = parser.floatValue();
        } else if (Fields.DESCRIPTION.equals(currentFieldName)) {
            description = parser.textOrNull();
        } else if (Fields.DETAILS.equals(currentFieldName)) {
            ensureExpectedToken(XContentParser.Token.START_ARRAY, token, () -> parser.getTokenLocation());
            while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
                details.add(parseExplanation(parser));
            }
        } else {
            throwUnknownField(currentFieldName, parser.getTokenLocation());
        }
    }
    if (value == null) {
        throw new ParsingException(parser.getTokenLocation(), "missing explanation value");
    }
    if (description == null) {
        throw new ParsingException(parser.getTokenLocation(), "missing explanation description");
    }
    return Explanation.match(value, description, details);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:32,代碼來源:SearchHit.java

示例5: readExplanation

import org.apache.lucene.search.Explanation; //導入方法依賴的package包/類
public static Explanation readExplanation(StreamInput in) throws IOException {
    boolean match = in.readBoolean();
    String description = in.readString();
    final Explanation[] subExplanations = new Explanation[in.readVInt()];
    for (int i = 0; i < subExplanations.length; ++i) {
        subExplanations[i] = readExplanation(in);
    }
    if (match) {
        return Explanation.match(in.readFloat(), description, subExplanations);
    } else {
        return Explanation.noMatch(description, subExplanations);
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:14,代碼來源:Lucene.java

示例6: explainScore

import org.apache.lucene.search.Explanation; //導入方法依賴的package包/類
private Explanation explainScore(int doc, Explanation freq, BM25StatsFixed stats, NumericDocValues norms) {
  Explanation boostExpl = Explanation.match(stats.boost, "boost");
  List<Explanation> subs = new ArrayList<>();
  if (boostExpl.getValue() != 1.0f)
    subs.add(boostExpl);
  subs.add(stats.idf);
  Explanation tfNormExpl = explainTFNorm(doc, freq, stats, norms);
  subs.add(tfNormExpl);
  return Explanation.match(
      boostExpl.getValue() * stats.idf.getValue() * tfNormExpl.getValue(),
      "score(doc="+doc+",freq="+freq+"), product of:", subs);
}
 
開發者ID:sebastian-hofstaetter,項目名稱:ir-generalized-translation-models,代碼行數:13,代碼來源:BM25SimilarityLossless.java

示例7: explain

import org.apache.lucene.search.Explanation; //導入方法依賴的package包/類
@Override
public Explanation explain(int topLevelDocId, SearchContext context, RescoreSearchContext rescoreContext,
                           Explanation sourceExplanation) throws IOException {
    QueryRescoreContext rescore = (QueryRescoreContext) rescoreContext;
    ContextIndexSearcher searcher = context.searcher();
    if (sourceExplanation == null) {
        // this should not happen but just in case
        return Explanation.noMatch("nothing matched");
    }
    // TODO: this isn't right?  I.e., we are incorrectly pretending all first pass hits were rescored?  If the requested docID was
    // beyond the top rescoreContext.window() in the first pass hits, we don't rescore it now?
    Explanation rescoreExplain = searcher.explain(rescore.query(), topLevelDocId);
    float primaryWeight = rescore.queryWeight();

    Explanation prim;
    if (sourceExplanation.isMatch()) {
        prim = Explanation.match(
                sourceExplanation.getValue() * primaryWeight,
                "product of:", sourceExplanation, Explanation.match(primaryWeight, "primaryWeight"));
    } else {
        prim = Explanation.noMatch("First pass did not match", sourceExplanation);
    }

    // NOTE: we don't use Lucene's Rescorer.explain because we want to insert our own description with which ScoreMode was used.  Maybe
    // we should add QueryRescorer.explainCombine to Lucene?
    if (rescoreExplain != null && rescoreExplain.isMatch()) {
        float secondaryWeight = rescore.rescoreQueryWeight();
        Explanation sec = Explanation.match(
                rescoreExplain.getValue() * secondaryWeight,
                "product of:",
                rescoreExplain, Explanation.match(secondaryWeight, "secondaryWeight"));
        ScoreMode scoreMode = rescore.scoreMode();
        return Explanation.match(
                scoreMode.combine(prim.getValue(), sec.getValue()),
                scoreMode + " of:",
                prim, sec);
    } else {
        return prim;
    }
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:41,代碼來源:QueryRescorer.java

示例8: explainFunction

import org.apache.lucene.search.Explanation; //導入方法依賴的package包/類
@Override
public Explanation explainFunction(String valueExpl, double value, double scale) {
    return Explanation.match(
            (float) evaluate(value, scale),
            "max(0.0, ((" + scale + " - " + valueExpl + ")/" + scale + ")");
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:7,代碼來源:LinearDecayFunctionBuilder.java

示例9: explainFunction

import org.apache.lucene.search.Explanation; //導入方法依賴的package包/類
@Override
public Explanation explainFunction(String valueExpl, double value, double scale) {
    return Explanation.match(
            (float) evaluate(value, scale),
            "exp(- " + valueExpl + " * " + -1 * scale + ")");
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:7,代碼來源:ExponentialDecayFunctionBuilder.java

示例10: explainWeight

import org.apache.lucene.search.Explanation; //導入方法依賴的package包/類
public Explanation explainWeight() {
    return Explanation.match(getWeight(), "weight");
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:4,代碼來源:WeightFactorFunction.java

示例11: explain

import org.apache.lucene.search.Explanation; //導入方法依賴的package包/類
@Override
public Explanation explain(Explanation subQueryScore) throws IOException {
    Explanation scoreExp = Explanation.match(subQueryScore.getValue(), "_score: ", subQueryScore);
    return Explanation.match((float) (runAsDouble()), "This script returned " + runAsDouble(), scoreExp);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:6,代碼來源:ExplainableScriptIT.java

示例12: explain

import org.apache.lucene.search.Explanation; //導入方法依賴的package包/類
@Override
public Explanation explain(LeafReaderContext context, int doc) throws IOException {
    return Explanation.match(getBoost(), "not implemented yet...");
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:5,代碼來源:ChildrenQuery.java

示例13: idfExplain

import org.apache.lucene.search.Explanation; //導入方法依賴的package包/類
/**
 * Computes a score factor for a phrase.
 * 
 * <p>
 * The default implementation sums the idf factor for
 * each term in the phrase.
 * 
 * @param collectionStats collection-level statistics
 * @param termStats term-level statistics for the terms in the phrase
 * @return an Explain object that includes both an idf 
 *         score factor for the phrase and an explanation 
 *         for each term.
 */
public Explanation idfExplain(CollectionStatistics collectionStats, TermStatistics termStats[]) {
  final long docCount = collectionStats.docCount() == -1 ? collectionStats.maxDoc() : collectionStats.docCount();
  float idf = 0.0f;
  List<Explanation> details = new ArrayList<>();
  for (final TermStatistics stat : termStats ) {
    final long df = stat.docFreq();
    final float termIdf = idf(df, docCount);
    details.add(Explanation.match(termIdf, "idf(docFreq=" + df + ", docCount=" + docCount + ")"));
    idf += termIdf;
  }
  return Explanation.match(idf, "idf(), sum of:", details);
}
 
開發者ID:sebastian-hofstaetter,項目名稱:ir-generalized-translation-models,代碼行數:26,代碼來源:BM25SimilarityLossless.java


注:本文中的org.apache.lucene.search.Explanation.match方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。