Skip to content

Instantly share code, notes, and snippets.

@mostafam
Created August 13, 2020 08:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mostafam/08386857005aa1b61fe581c1beb0abd3 to your computer and use it in GitHub Desktop.
Save mostafam/08386857005aa1b61fe581c1beb0abd3 to your computer and use it in GitHub Desktop.
Core Model
package ml.combust.mleap.core.feature
import ml.combust.mleap.core.Model
import ml.combust.mleap.core.types.{ScalarType, StructField, StructType}
/**
* Created by mostafam on 6/30/20.
*/
case class StringCheckerModel(caseSensitive: Boolean) extends Model {
def apply(text: String, query: String): Double = {
if (caseSensitive){
text.contains(query).compare(false)
} else {
text.toLowerCase().contains(query.toLowerCase()).compare(false)
}
}
override def inputSchema: StructType = StructType(
StructField(s"text", ScalarType.String),
StructField(s"query", ScalarType.String)
).get
override def outputSchema: StructType = StructType("output" -> ScalarType.Double.nonNullable).get
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment