Skip to content

Commit

Permalink
Add some comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
afoucret committed Nov 24, 2023
1 parent df776b8 commit a521745
Showing 1 changed file with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,24 @@ public LearnToRankService(
this.parserConfiguration = parserConfiguration;
}

/**
* Asynchronously load a regression model to be used for learn to rank.
*
* @param modelId The model id to be loaded.
* @param listener Response listener.
*/
public void loadLocalModel(String modelId, ActionListener<LocalModel> listener) {
modelLoadingService.getModelForLearnToRank(modelId, listener);
}

/**
* Asynchronously load the learn to rank config by model id.
* Once the model is loaded, templates are executed using params provided.
*
* @param modelId Id of the model.
* @param params Templates params.
* @param listener Response listener.
*/
public void loadLearnToRankConfig(String modelId, Map<String, Object> params, ActionListener<LearnToRankConfig> listener) {
trainedModelProvider.getTrainedModel(
modelId,
Expand All @@ -98,6 +112,15 @@ public void loadLearnToRankConfig(String modelId, Map<String, Object> params, Ac
);
}

/**
* Applies templates params to a {@link LearnToRankConfig} object.
*
* @param config Original config.
* @param params Templates params.
* @return A {@link LearnToRankConfig} object with templates applied.
*
* @throws IOException
*/
private LearnToRankConfig applyParams(LearnToRankConfig config, Map<String, Object> params) throws IOException {
if (scriptService.isLangSupported(DEFAULT_TEMPLATE_LANG) == false) {
return config;
Expand All @@ -117,6 +140,15 @@ private LearnToRankConfig applyParams(LearnToRankConfig config, Map<String, Obje
return LearnToRankConfig.builder(config).setLearnToRankFeatureExtractorBuilders(featureExtractorBuilders).build();
}

/**
* Applies templates to features extractors.
*
* @param featureExtractorBuilder Source feature extractor builder.
* @param params Templates params.
* @return A new feature extractor with templates applied.
*
* @throws IOException
*/
private LearnToRankFeatureExtractorBuilder applyParams(
LearnToRankFeatureExtractorBuilder featureExtractorBuilder,
Map<String, Object> params
Expand All @@ -128,6 +160,15 @@ private LearnToRankFeatureExtractorBuilder applyParams(
return featureExtractorBuilder;
}

/**
* Applies templates to a {@link QueryExtractorBuilder} object.
*
* @param queryExtractorBuilder Source query extractor builder.
* @param params Templates params.
* @return A {@link QueryExtractorBuilder} with templates applied.
*
* @throws IOException
*/
private QueryExtractorBuilder applyParams(QueryExtractorBuilder queryExtractorBuilder, Map<String, Object> params) throws IOException {
String templateSource = templateSource(queryExtractorBuilder.query());

Expand Down

0 comments on commit a521745

Please sign in to comment.