mirror of https://github.com/apache/lucene.git
SOLR-10174: reduce makeFeatureWeights code duplication in tests
This commit is contained in:
parent
b0020634ac
commit
cf9b70b253
|
@ -89,16 +89,6 @@ public class TestLTRScoringQuery extends LuceneTestCase {
|
|||
return features;
|
||||
}
|
||||
|
||||
private static Map<String,Object> makeFeatureWeights(List<Feature> features) {
|
||||
final Map<String,Object> nameParams = new HashMap<String,Object>();
|
||||
final HashMap<String,Double> modelWeights = new HashMap<String,Double>();
|
||||
for (final Feature feat : features) {
|
||||
modelWeights.put(feat.getName(), 0.1);
|
||||
}
|
||||
nameParams.put("weights", modelWeights);
|
||||
return nameParams;
|
||||
}
|
||||
|
||||
private LTRScoringQuery.ModelWeight performQuery(TopDocs hits,
|
||||
IndexSearcher searcher, int docid, LTRScoringQuery model) throws IOException,
|
||||
ModelException {
|
||||
|
@ -132,7 +122,7 @@ public class TestLTRScoringQuery extends LuceneTestCase {
|
|||
Collections.nCopies(features.size(),IdentityNormalizer.INSTANCE));
|
||||
final List<Feature> allFeatures = makeFeatures(
|
||||
new int[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
|
||||
final Map<String,Object> modelParams = makeFeatureWeights(features);
|
||||
final Map<String,Object> modelParams = TestLinearModel.makeFeatureWeights(features);
|
||||
|
||||
final LTRScoringModel algorithm1 = TestLinearModel.createLinearModel(
|
||||
"testModelName",
|
||||
|
@ -222,7 +212,7 @@ public class TestLTRScoringQuery extends LuceneTestCase {
|
|||
Collections.nCopies(features.size(),IdentityNormalizer.INSTANCE));
|
||||
LTRScoringModel ltrScoringModel = TestLinearModel.createLinearModel("test",
|
||||
features, norms, "test", allFeatures,
|
||||
makeFeatureWeights(features));
|
||||
TestLinearModel.makeFeatureWeights(features));
|
||||
|
||||
LTRScoringQuery.ModelWeight modelWeight = performQuery(hits, searcher,
|
||||
hits.scoreDocs[0].doc, new LTRScoringQuery(ltrScoringModel));
|
||||
|
@ -248,7 +238,7 @@ public class TestLTRScoringQuery extends LuceneTestCase {
|
|||
new ArrayList<Normalizer>(
|
||||
Collections.nCopies(features.size(),IdentityNormalizer.INSTANCE));
|
||||
ltrScoringModel = TestLinearModel.createLinearModel("test",
|
||||
features, norms, "test", allFeatures, makeFeatureWeights(features));
|
||||
features, norms, "test", allFeatures, TestLinearModel.makeFeatureWeights(features));
|
||||
|
||||
modelWeight = performQuery(hits, searcher, hits.scoreDocs[0].doc,
|
||||
new LTRScoringQuery(ltrScoringModel));
|
||||
|
@ -268,7 +258,7 @@ public class TestLTRScoringQuery extends LuceneTestCase {
|
|||
Collections.nCopies(features.size(),IdentityNormalizer.INSTANCE));
|
||||
try {
|
||||
ltrScoringModel = TestLinearModel.createLinearModel("test",
|
||||
features, norms, "test", allFeatures, makeFeatureWeights(features));
|
||||
features, norms, "test", allFeatures, TestLinearModel.makeFeatureWeights(features));
|
||||
fail("unexpectedly got here instead of catching "+expectedModelException);
|
||||
modelWeight = performQuery(hits, searcher, hits.scoreDocs[0].doc,
|
||||
new LTRScoringQuery(ltrScoringModel));
|
||||
|
@ -301,7 +291,7 @@ public class TestLTRScoringQuery extends LuceneTestCase {
|
|||
Collections.nCopies(features.size(),norm));
|
||||
final LTRScoringModel normMeta = TestLinearModel.createLinearModel("test",
|
||||
features, norms, "test", allFeatures,
|
||||
makeFeatureWeights(features));
|
||||
TestLinearModel.makeFeatureWeights(features));
|
||||
|
||||
modelWeight = performQuery(hits, searcher, hits.scoreDocs[0].doc,
|
||||
new LTRScoringQuery(normMeta));
|
||||
|
|
|
@ -70,16 +70,6 @@ public class TestSelectiveWeightCreation extends TestRerankBase {
|
|||
return features;
|
||||
}
|
||||
|
||||
private static Map<String,Object> makeFeatureWeights(List<Feature> features) {
|
||||
final Map<String,Object> nameParams = new HashMap<String,Object>();
|
||||
final HashMap<String,Double> modelWeights = new HashMap<String,Double>();
|
||||
for (final Feature feat : features) {
|
||||
modelWeights.put(feat.getName(), 0.1);
|
||||
}
|
||||
nameParams.put("weights", modelWeights);
|
||||
return nameParams;
|
||||
}
|
||||
|
||||
private LTRScoringQuery.ModelWeight performQuery(TopDocs hits,
|
||||
IndexSearcher searcher, int docid, LTRScoringQuery model) throws IOException,
|
||||
ModelException {
|
||||
|
@ -168,7 +158,7 @@ public class TestSelectiveWeightCreation extends TestRerankBase {
|
|||
// when features are NOT requested in the response, only the modelFeature weights should be created
|
||||
final LTRScoringModel ltrScoringModel1 = TestLinearModel.createLinearModel("test",
|
||||
features, norms, "test", allFeatures,
|
||||
makeFeatureWeights(features));
|
||||
TestLinearModel.makeFeatureWeights(features));
|
||||
LTRScoringQuery.ModelWeight modelWeight = performQuery(hits, searcher,
|
||||
hits.scoreDocs[0].doc, new LTRScoringQuery(ltrScoringModel1, false)); // features not requested in response
|
||||
LTRScoringQuery.FeatureInfo[] featuresInfo = modelWeight.getFeaturesInfo();
|
||||
|
@ -185,7 +175,7 @@ public class TestSelectiveWeightCreation extends TestRerankBase {
|
|||
// when features are requested in the response, weights should be created for all features
|
||||
final LTRScoringModel ltrScoringModel2 = TestLinearModel.createLinearModel("test",
|
||||
features, norms, "test", allFeatures,
|
||||
makeFeatureWeights(features));
|
||||
TestLinearModel.makeFeatureWeights(features));
|
||||
modelWeight = performQuery(hits, searcher,
|
||||
hits.scoreDocs[0].doc, new LTRScoringQuery(ltrScoringModel2, true)); // features requested in response
|
||||
featuresInfo = modelWeight.getFeaturesInfo();
|
||||
|
|
|
@ -45,6 +45,16 @@ public class TestLinearModel extends TestRerankBase {
|
|||
return model;
|
||||
}
|
||||
|
||||
public static Map<String,Object> makeFeatureWeights(List<Feature> features) {
|
||||
final Map<String,Object> nameParams = new HashMap<String,Object>();
|
||||
final HashMap<String,Double> modelWeights = new HashMap<String,Double>();
|
||||
for (final Feature feat : features) {
|
||||
modelWeights.put(feat.getName(), 0.1);
|
||||
}
|
||||
nameParams.put("weights", modelWeights);
|
||||
return nameParams;
|
||||
}
|
||||
|
||||
static ManagedModelStore store = null;
|
||||
static FeatureStore fstore = null;
|
||||
|
||||
|
|
Loading…
Reference in New Issue