Remove usage of FromXContentBuilder

This commit is contained in:
Isabel Drost-Fromm 2016-09-07 11:48:50 +02:00
parent 6bc646ac84
commit 333b769871
10 changed files with 15 additions and 50 deletions

View File

@ -20,7 +20,6 @@
package org.elasticsearch.index.rankeval;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.ParseFieldMatcher;
import org.elasticsearch.common.ParseFieldMatcherSupplier;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
@ -38,7 +37,7 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
public class DiscountedCumulativeGainAt extends RankedListQualityMetric<DiscountedCumulativeGainAt> {
public class DiscountedCumulativeGainAt extends RankedListQualityMetric {
/** rank position up to which to check results. */
private int position;
@ -192,11 +191,6 @@ public class DiscountedCumulativeGainAt extends RankedListQualityMetric<Discount
PARSER.declareInt(DiscountedCumulativeGainAt::setUnknownDocRating, UNKNOWN_DOC_RATING_FIELD);
}
@Override
public DiscountedCumulativeGainAt fromXContent(XContentParser parser, ParseFieldMatcher matcher) {
return DiscountedCumulativeGainAt.fromXContent(parser, () -> matcher);
}
public static DiscountedCumulativeGainAt fromXContent(XContentParser parser, ParseFieldMatcherSupplier matcher) {
return PARSER.apply(parser, matcher);
}

View File

@ -20,7 +20,6 @@
package org.elasticsearch.index.rankeval;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.ParseFieldMatcher;
import org.elasticsearch.common.ParseFieldMatcherSupplier;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
@ -43,7 +42,7 @@ import javax.naming.directory.SearchResult;
* By default documents with a rating equal or bigger than 1 are considered to be "relevant" for the precision
* calculation. This value can be changes using the "relevant_rating_threshold" parameter.
* */
public class PrecisionAtN extends RankedListQualityMetric<PrecisionAtN> {
public class PrecisionAtN extends RankedListQualityMetric {
/** Number of results to check against a given set of relevant results. */
private int n;
@ -113,17 +112,6 @@ public class PrecisionAtN extends RankedListQualityMetric<PrecisionAtN> {
return relevantRatingThreshhold ;
}
@Override
public PrecisionAtN fromXContent(XContentParser parser, ParseFieldMatcher matcher) {
return PrecisionAtN.fromXContent(parser, new ParseFieldMatcherSupplier() {
@Override
public ParseFieldMatcher getParseFieldMatcher() {
return matcher;
}
});
}
public static PrecisionAtN fromXContent(XContentParser parser, ParseFieldMatcherSupplier matcher) {
return PARSER.apply(parser, matcher);
}

View File

@ -46,7 +46,7 @@ public class RankEvalSpec extends ToXContentToBytes implements Writeable {
/** Collection of query specifications, that is e.g. search request templates to use for query translation. */
private Collection<RatedRequest> ratedRequests = new ArrayList<>();
/** Definition of the quality metric, e.g. precision at N */
private RankedListQualityMetric<?> metric;
private RankedListQualityMetric metric;
/** a unique id for the whole QA task */
private String specId;
@ -54,7 +54,7 @@ public class RankEvalSpec extends ToXContentToBytes implements Writeable {
// TODO think if no args ctor is okay
}
public RankEvalSpec(String specId, Collection<RatedRequest> specs, RankedListQualityMetric<?> metric) {
public RankEvalSpec(String specId, Collection<RatedRequest> specs, RankedListQualityMetric metric) {
this.specId = specId;
this.ratedRequests = specs;
this.metric = metric;
@ -80,7 +80,7 @@ public class RankEvalSpec extends ToXContentToBytes implements Writeable {
out.writeString(specId);
}
public void setEval(RankedListQualityMetric<?> eval) {
public void setEval(RankedListQualityMetric eval) {
this.metric = eval;
}
@ -93,12 +93,12 @@ public class RankEvalSpec extends ToXContentToBytes implements Writeable {
}
/** Returns the precision at n configuration (containing level of n to consider).*/
public RankedListQualityMetric<?> getEvaluator() {
public RankedListQualityMetric getEvaluator() {
return metric;
}
/** Sets the precision at n configuration (containing level of n to consider).*/
public void setEvaluator(RankedListQualityMetric<?> config) {
public void setEvaluator(RankedListQualityMetric config) {
this.metric = config;
}

View File

@ -23,7 +23,6 @@ import org.elasticsearch.action.support.ToXContentToBytes;
import org.elasticsearch.common.ParseFieldMatcherSupplier;
import org.elasticsearch.common.ParsingException;
import org.elasticsearch.common.io.stream.NamedWriteable;
import org.elasticsearch.common.xcontent.FromXContentBuilder;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentParser.Token;
@ -39,9 +38,7 @@ import java.util.List;
*
* RelevancyLevel specifies the type of object determining the relevancy level of some known docid.
* */
public abstract class RankedListQualityMetric<T extends RankedListQualityMetric<?>>
extends ToXContentToBytes
implements NamedWriteable, FromXContentBuilder<T> {
public abstract class RankedListQualityMetric extends ToXContentToBytes implements NamedWriteable {
/**
* Returns a single metric representing the ranking quality of a set of returned documents
@ -52,8 +49,8 @@ public abstract class RankedListQualityMetric<T extends RankedListQualityMetric<
* */
public abstract EvalQueryQuality evaluate(SearchHit[] hits, List<RatedDocument> ratedDocs);
public static RankedListQualityMetric<?> fromXContent(XContentParser parser, ParseFieldMatcherSupplier context) throws IOException {
RankedListQualityMetric<?> rc;
public static RankedListQualityMetric fromXContent(XContentParser parser, ParseFieldMatcherSupplier context) throws IOException {
RankedListQualityMetric rc;
Token token = parser.nextToken();
if (token != XContentParser.Token.FIELD_NAME) {
throw new ParsingException(parser.getTokenLocation(), "[_na] missing required metric name");

View File

@ -20,7 +20,6 @@
package org.elasticsearch.index.rankeval;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.ParseFieldMatcher;
import org.elasticsearch.common.ParseFieldMatcherSupplier;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
@ -44,7 +43,7 @@ import javax.naming.directory.SearchResult;
* By default documents with a rating equal or bigger than 1 are considered to be "relevant" for the reciprocal rank
* calculation. This value can be changes using the "relevant_rating_threshold" parameter.
* */
public class ReciprocalRank extends RankedListQualityMetric<ReciprocalRank> {
public class ReciprocalRank extends RankedListQualityMetric {
public static final String NAME = "reciprocal_rank";
public static final int DEFAULT_MAX_ACCEPTABLE_RANK = 10;
@ -160,17 +159,6 @@ public class ReciprocalRank extends RankedListQualityMetric<ReciprocalRank> {
PARSER.declareInt(ReciprocalRank::setRelevantRatingThreshhold, RELEVANT_RATING_FIELD);
}
@Override
public ReciprocalRank fromXContent(XContentParser parser, ParseFieldMatcher matcher) {
return ReciprocalRank.fromXContent(parser, new ParseFieldMatcherSupplier() {
@Override
public ParseFieldMatcher getParseFieldMatcher() {
return matcher;
}
});
}
public static ReciprocalRank fromXContent(XContentParser parser, ParseFieldMatcherSupplier matcher) {
return PARSER.apply(parser, matcher);
}

View File

@ -133,7 +133,7 @@ public class DiscountedCumulativeGainAtTests extends XContentRoundtripTests<Disc
XContentParser itemParser = roundtrip(testItem);
itemParser.nextToken();
itemParser.nextToken();
DiscountedCumulativeGainAt parsedItem = testItem.fromXContent(itemParser, ParseFieldMatcher.STRICT);
DiscountedCumulativeGainAt parsedItem = DiscountedCumulativeGainAt.fromXContent(itemParser, () -> ParseFieldMatcher.STRICT);
assertNotSame(testItem, parsedItem);
assertEquals(testItem, parsedItem);
assertEquals(testItem.hashCode(), parsedItem.hashCode());

View File

@ -144,7 +144,7 @@ public class PrecisionAtNTests extends XContentRoundtripTests<PrecisionAtN> {
XContentParser itemParser = roundtrip(testItem);
itemParser.nextToken();
itemParser.nextToken();
PrecisionAtN parsedItem = testItem.fromXContent(itemParser, ParseFieldMatcher.STRICT);
PrecisionAtN parsedItem = PrecisionAtN.fromXContent(itemParser, () -> ParseFieldMatcher.STRICT);
assertNotSame(testItem, parsedItem);
assertEquals(testItem, parsedItem);
assertEquals(testItem.hashCode(), parsedItem.hashCode());

View File

@ -86,7 +86,6 @@ public class RankEvalSpecTests extends ESTestCase {
}
String specId = randomAsciiOfLengthBetween(1, 10); // TODO we should reject zero length ids ...
@SuppressWarnings("rawtypes")
RankedListQualityMetric metric;
if (randomBoolean()) {
metric = PrecisionAtNTests.createTestItem();

View File

@ -157,7 +157,7 @@ public class ReciprocalRankTests extends XContentRoundtripTests<ReciprocalRank>
XContentParser itemParser = roundtrip(testItem);
itemParser.nextToken();
itemParser.nextToken();
ReciprocalRank parsedItem = testItem.fromXContent(itemParser, ParseFieldMatcher.STRICT);
ReciprocalRank parsedItem = ReciprocalRank.fromXContent(itemParser, () -> ParseFieldMatcher.STRICT);
assertNotSame(testItem, parsedItem);
assertEquals(testItem, parsedItem);
assertEquals(testItem.hashCode(), parsedItem.hashCode());

View File

@ -20,7 +20,6 @@
package org.elasticsearch.index.rankeval;
import org.elasticsearch.action.support.ToXContentToBytes;
import org.elasticsearch.common.xcontent.FromXContentBuilder;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
@ -31,7 +30,7 @@ import org.elasticsearch.test.ESTestCase;
import java.io.IOException;
public class XContentRoundtripTests<T extends ToXContentToBytes & FromXContentBuilder<T>> extends ESTestCase {
public class XContentRoundtripTests<T extends ToXContentToBytes> extends ESTestCase {
public XContentParser roundtrip(T testItem) throws IOException {
XContentBuilder builder = XContentFactory.contentBuilder(randomFrom(XContentType.values()));