我有一个包含以下数据的 .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`
}