All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.pmml4s.transformations.UserDefinedFunctions.scala Maven / Gradle / Ivy

/*
 * Copyright (c) 2017-2019 AutoDeploy AI
 *
 * 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.pmml4s.transformations

import org.pmml4s.data.DataVal

/**
 * Defines several user-defined functions produced by various vendors, actually, well-defined "DefineFunction" is fully
 * supported by pmml4s, while some could be not. Here is the place for those user-defined functions are not well defined.
 */
object UserDefinedFunctions extends FunctionProvider {
  lazy val functions: Map[String, Function] = {
    val set = Set(`SAS-EM-String-Normalize`, `SAS-FORMAT-BESTw`, `SAS-FORMAT-$CHARw`)
    set.map(x => (x.symbol, x)).toMap
  }

  def getFunction(symbol: String): Option[Function] = functions.get(symbol)
}

/**
 *
 * {{{
 * 
 *  
 *  
 *  
 *    
 *      
 *      
 *      1
 *      FMTWIDTH
 *      
 *    
 *  
 * 
 * }}}
 */
object `SAS-EM-String-Normalize` extends BinaryFunction {
  override def eval(left: DataVal, right: DataVal): DataVal = {
    TrimBlanks.eval(Uppercase.eval(Substring.eval(right, DataVal.`1`, left)))
  }

  override def symbol: String = "SAS-EM-String-Normalize"
}

/**
 *
 * {{{
 * 
 *  
 *  
 *  
 *    
 *    FMTWIDTH
 *  
 * 
 * }}}
 */
object `SAS-FORMAT-BESTw` extends BinaryFunction {
  override def eval(left: DataVal, right: DataVal): DataVal = {
    FormatNumber.eval(left, right)
  }

  override def symbol: String = "SAS-FORMAT-BESTw"
}

/**
 *
 * {{{
 * 
 *  
 *  
 *  
 *    
 *    1
 *    FMTWIDTH
 *  
 * 
 * }}}
 */
object `SAS-FORMAT-$CHARw` extends BinaryFunction {
  override def eval(left: DataVal, right: DataVal): DataVal = {
    Substring.eval(right, DataVal.`1`, left)
  }

  override def symbol: String = "SAS-FORMAT-$CHARw"
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy