本文整理汇总了Scala中java.text.BreakIterator类的典型用法代码示例。如果您正苦于以下问题:Scala BreakIterator类的具体用法?Scala BreakIterator怎么用?Scala BreakIterator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BreakIterator类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: NLP
//设置package包名称以及导入依赖的类
package util
import java.text.BreakIterator
import java.util.Locale
object NLP {
def cleanText(text: String): String = {
text.split("\n").map(
(line) => line.trim
// TODO remove links
).filter(
(line) => {
line.length > 50 &&
line.split(" ").size > 5
}
).mkString("\n")
}
// TODO option to resolve DBPedia entities here
def getSentences(text: String): List[String] = {
var sentences: List[String] = List()
val iterator: BreakIterator = BreakIterator.getSentenceInstance(Locale.US)
val source: String = text
iterator.setText(source)
var start: Int = iterator.first
val sb: StringBuffer = new StringBuffer
var end: Int = iterator.next
while (end != BreakIterator.DONE) {
val sentence: String = source.substring(start, end)
sentences = sentences ++ List(sentence)
start = end
end = iterator.next
}
sentences
}
}