Search in sources :

Example 1 with MLAlgoParameter

use of org.opensearch.ml.common.annotation.MLAlgoParameter in project ml-commons by opensearch-project.

the class MLCommonsClassLoader method loadMLAlgoParameterClassMapping.

/**
 * Load ML algorithm parameter and ML output class.
 */
private static void loadMLAlgoParameterClassMapping() {
    Reflections reflections = new Reflections("org.opensearch.ml.common.parameter");
    Set<Class<?>> classes = reflections.getTypesAnnotatedWith(MLAlgoParameter.class);
    // Load ML algorithm parameter class
    for (Class<?> clazz : classes) {
        MLAlgoParameter mlAlgoParameter = clazz.getAnnotation(MLAlgoParameter.class);
        FunctionName[] algorithms = mlAlgoParameter.algorithms();
        if (algorithms != null && algorithms.length > 0) {
            for (FunctionName name : algorithms) {
                parameterClassMap.put(name, clazz);
            }
        }
    }
    // Load ML output class
    classes = reflections.getTypesAnnotatedWith(MLAlgoOutput.class);
    for (Class<?> clazz : classes) {
        MLAlgoOutput mlAlgoOutput = clazz.getAnnotation(MLAlgoOutput.class);
        MLOutputType mlOutputType = mlAlgoOutput.value();
        if (mlOutputType != null) {
            parameterClassMap.put(mlOutputType, clazz);
        }
    }
}
Also used : FunctionName(org.opensearch.ml.common.parameter.FunctionName) MLOutputType(org.opensearch.ml.common.parameter.MLOutputType) MLAlgoOutput(org.opensearch.ml.common.annotation.MLAlgoOutput) MLAlgoParameter(org.opensearch.ml.common.annotation.MLAlgoParameter) Reflections(org.reflections.Reflections)

Aggregations

MLAlgoOutput (org.opensearch.ml.common.annotation.MLAlgoOutput)1 MLAlgoParameter (org.opensearch.ml.common.annotation.MLAlgoParameter)1 FunctionName (org.opensearch.ml.common.parameter.FunctionName)1 MLOutputType (org.opensearch.ml.common.parameter.MLOutputType)1 Reflections (org.reflections.Reflections)1