Created
August 13, 2020 08:27
-
-
Save mostafam/08386857005aa1b61fe581c1beb0abd3 to your computer and use it in GitHub Desktop.
Core Model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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