Skip to content

Commit

Permalink
Merge pull request meta-toolkit#89 from husseinhazimeh/master
Browse files Browse the repository at this point in the history
Change query_term_count -> query_term_weight to support non-integer weighted queries.
  • Loading branch information
Chase Geigle committed Jun 3, 2015
2 parents 39752d5 + e2ead62 commit a5f7688
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions include/index/score_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ struct score_data

/// doc term id
term_id t_id;
/// query term count
uint64_t query_term_count;
/// query term count (or weight in case of feedback)
double query_term_weight;
/// number of docs that t_id appears in
uint64_t doc_count;
/// number of times t_id appears in corpus
Expand Down
2 changes: 1 addition & 1 deletion src/index/ranker/lm_ranker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ double language_model_ranker::score_one(const score_data& sd)
double ps = smoothed_prob(sd);
double pc = static_cast<double>(sd.corpus_term_count) / sd.total_terms;

return sd.query_term_count * std::log(ps / (doc_constant(sd) * pc));
return sd.query_term_weight * std::log(ps / (doc_constant(sd) * pc));
}

double language_model_ranker::initial_score(const score_data& sd) const
Expand Down
4 changes: 2 additions & 2 deletions src/index/ranker/okapi_bm25.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ double okapi_bm25::score_one(const score_data& sd)
/ ((k1_ * ((1.0 - b_) + b_ * doc_len / sd.avg_dl))
+ sd.doc_term_count);

double QTF = ((k3_ + 1.0) * sd.query_term_count)
/ (k3_ + sd.query_term_count);
double QTF = ((k3_ + 1.0) * sd.query_term_weight)
/ (k3_ + sd.query_term_weight);

return TF * IDF * QTF;
}
Expand Down
2 changes: 1 addition & 1 deletion src/index/ranker/pivoted_length.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ double pivoted_length::score_one(const score_data& sd)
double norm = (1 - s_) + s_ * (doc_len / sd.avg_dl);
double IDF = log((sd.num_docs + 1) / (0.5 + sd.doc_count));

return TF / norm * sd.query_term_count * IDF;
return TF / norm * sd.query_term_weight * IDF;
}

template <>
Expand Down
2 changes: 1 addition & 1 deletion src/index/ranker/ranker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ranker::score(inverted_index& idx, corpus::document& query,
auto pdata = idx.search_primary(t_id);
sd.doc_count = pdata->counts().size();
sd.t_id = t_id;
sd.query_term_count = tpair.second;
sd.query_term_weight = tpair.second;
sd.corpus_term_count = idx.total_num_occurences(sd.t_id);
for (auto& dpair : pdata->counts())
{
Expand Down

0 comments on commit a5f7688

Please sign in to comment.