com.mayabot.nlp.segment.lexer.perceptron.PerceptronSegmentPatch.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mynlp Show documentation
Show all versions of mynlp Show documentation
Maya Nlp subproject :mynlp
package com.mayabot.nlp.segment.lexer.perceptron
import com.mayabot.nlp.MynlpEnv
import com.mayabot.nlp.injector.Singleton
@Singleton
class PerceptronSegmentPatch
constructor(val mynlpEnv: MynlpEnv) {
val examples = ArrayList()
init {
examples += loadExample("patch/cws-default.txt")
examples += loadExample("patch/cws.txt")
}
fun addExample(line: String) {
examples += line
}
fun removeExample(line: String) {
examples.remove(line)
}
fun addResources(rsName: String) {
examples += loadExample(rsName)
}
private fun loadExample(rsName: String): List {
val resource = mynlpEnv.tryLoadResource(rsName, Charsets.UTF_8)
if (resource != null) {
return resource.inputStream().bufferedReader().readLines()
.map { it.trim() }.filter {
it.isNotBlank() && !it.startsWith("#")
}
}
return listOf()
}
}