You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by cp...@apache.org on 2017/06/08 11:09:50 UTC
lucene-solr:branch_6x: SOLR-10174: reduce makeFeatureWeights code
duplication in tests
Repository: lucene-solr
Updated Branches:
refs/heads/branch_6x 9586b9195 -> c09d6b0f7
SOLR-10174: reduce makeFeatureWeights code duplication in tests
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/c09d6b0f
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/c09d6b0f
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/c09d6b0f
Branch: refs/heads/branch_6x
Commit: c09d6b0f73ba703b57efab864e927a504e65b433
Parents: 9586b91
Author: Christine Poerschke <cp...@apache.org>
Authored: Thu Jun 8 10:15:54 2017 +0100
Committer: Christine Poerschke <cp...@apache.org>
Committed: Thu Jun 8 12:09:25 2017 +0100
----------------------------------------------------------------------
.../apache/solr/ltr/TestLTRScoringQuery.java | 20 +++++---------------
.../solr/ltr/TestSelectiveWeightCreation.java | 14 ++------------
.../apache/solr/ltr/model/TestLinearModel.java | 10 ++++++++++
3 files changed, 17 insertions(+), 27 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c09d6b0f/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRScoringQuery.java
----------------------------------------------------------------------
diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRScoringQuery.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRScoringQuery.java
index 0576c99..e20f7e1 100644
--- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRScoringQuery.java
+++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRScoringQuery.java
@@ -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));
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c09d6b0f/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestSelectiveWeightCreation.java
----------------------------------------------------------------------
diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestSelectiveWeightCreation.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestSelectiveWeightCreation.java
index 7bf8373..32584d1 100644
--- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestSelectiveWeightCreation.java
+++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestSelectiveWeightCreation.java
@@ -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();
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c09d6b0f/solr/contrib/ltr/src/test/org/apache/solr/ltr/model/TestLinearModel.java
----------------------------------------------------------------------
diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/model/TestLinearModel.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/model/TestLinearModel.java
index 067bd27..4649624 100644
--- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/model/TestLinearModel.java
+++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/model/TestLinearModel.java
@@ -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;