org.kie.pmml.commons.utils.KiePMMLModelUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kie-pmml-commons Show documentation
Show all versions of kie-pmml-commons Show documentation
Common code for PMML module
/*
* Copyright 2020 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.kie.pmml.commons.utils;
import java.util.UUID;
import javax.lang.model.SourceVersion;
import org.kie.pmml.api.enums.DATA_TYPE;
public class KiePMMLModelUtils {
private KiePMMLModelUtils() {
}
/**
* Method to be used by every KiePMML implementation to retrieve the package name
* out of the model name
* @param modelName
* @return
*/
public static String getSanitizedPackageName(String modelName) {
return modelName.replaceAll("[^A-Za-z0-9.]", "").toLowerCase();
}
/**
* Convert the given String
in a valid class name (i.e. no dots, no spaces, first letter upper case)
* @param input
* @return
*/
public static String getSanitizedClassName(String input) {
String upperCasedInput = input.substring(0, 1).toUpperCase() + input.substring(1);
return upperCasedInput.replaceAll("[^A-Za-z0-9]", "");
}
/**
* Convert the given String
in a valid variable name (i.e. no dots, no spaces, first letter lower case, no keyword)
* @param input
* @return
*/
public static String getSanitizedVariableName(String input) {
String lowerCasedInput = input.substring(0, 1).toLowerCase() + input.substring(1);
String toReturn = lowerCasedInput.replaceAll("[^A-Za-z0-9]", "");
if (SourceVersion.isKeyword(toReturn)) {
toReturn += "var";
}
return toReturn;
}
/**
* Returns an autogenerated classname whose name starts with the given prefix
* @param prefix
* @return
*/
public static String getGeneratedClassName(final String prefix) {
String rawName = prefix + UUID.randomUUID();
return getSanitizedClassName(rawName);
}
public static Object commonEvaluate(Object rawObject, DATA_TYPE dataType) {
return dataType != null && rawObject != null ? dataType.getActualValue(rawObject) : rawObject;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy