Skip to content

Commit

Permalink
added a facility method to generate model factory from relevance json…
Browse files Browse the repository at this point in the history
… object
  • Loading branch information
sguo committed May 1, 2012
1 parent 5dd0df1 commit 05d5429
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,28 @@ else if (jsonRelevance.has(RelevanceJSONConstants.KW_MODEL))
throw new IllegalArgumentException("the relevance json is not valid");
}
}

/**
* A facility method to build a relevance model factory object from a relevance json object;
* A relevance model factory can be used to generate scorefunction object as many as you want.
* @param jsonRelevance
* @return Relevance model Factory
* @throws JSONException
*/
public static CustomRelevanceFunctionFactory buildModelFactory(JSONObject jsonRelevance) throws JSONException
{
// runtime anonymous model;
if (jsonRelevance.has(RelevanceJSONConstants.KW_MODEL))
{
JSONObject modelJson = jsonRelevance.optJSONObject(RelevanceJSONConstants.KW_MODEL);
DataTable _dt = new DataTable();
CustomMathModel _cModel = CompilationHelper.createCustomMathScorer(modelJson, _dt);
RuntimeRelevanceFunction sm = new RuntimeRelevanceFunction(_cModel, _dt);
RuntimeRelevanceFunctionFactory rrfFactory = new RuntimeRelevanceFunctionFactory(sm);
return rrfFactory;
}
else{
throw new IllegalArgumentException("the relevance json is not valid to create a model factory.");
}
}
}

0 comments on commit 05d5429

Please sign in to comment.