【问题标题】:Text mining with Scala使用 Scala 进行文本挖掘
【发布时间】:2026-01-28 17:05:02
【问题描述】:

我有一个包含以下数据的 .txt 文件:

L666371 +++$+++ u9030 +++$+++ m616 +++$+++ DURNFORD +++$+++ Lord Chelmsford seems to want me to stay back with my Basutos.
L666370 +++$+++ u9034 +++$+++ m616 +++$+++ VEREKER +++$+++ I'm to take the Sikali with the main column to the river
L666369 +++$+++ u9030 +++$+++ m616 +++$+++ DURNFORD +++$+++ Your orders, Mr Vereker?
L666257 +++$+++ u9030 +++$+++ m616 +++$+++ DURNFORD +++$+++ Good ones, yes, Mr Vereker. Gentlemen who can ride and shoot
L666256 +++$+++ u9034 +++$+++ m616 +++$+++ VEREKER +++$+++ Colonel Durnford... William Vereker. I hear you 've been seeking Officers?

我想将文本文件导入 Scala(我已经完成),然后通过提取所有文本来处理它。之后:标记化、小写、忽略单词形式、单独的标点符号,之后我想以这样的形式学习单词的计数:unigram、bigram 和 trigram 计数,按顶部的最高计数对结果进行排序。

谁能告诉我如何实现它?我有以下尝试,但它似乎不起作用:

import io.Source
val s = Source.fromFile("movie_lines.txt")("ISO-8859-1")
val lines = s.getLines
val str = s.mkString

val Pattern = "([A-Z]+.!)".r`enter code here`

Pattern.findAllIn(str).foreach { x => println(x) }

println ("\n This is the result\n")`enter code here`
  }

【问题讨论】:

    标签: regex text-mining text-extraction scala-ide scala-2.11


    【解决方案1】:

    您可以使用ScalaNLP 套装中的Epic 库来预处理文本(标记化),然后解析、标记和提取实体。

    【讨论】: