Scala 解析段落中的单个句子

Scala 解析段落中的单个句子,scala,parsing,nlp,Scala,Parsing,Nlp,我正在尝试构建一个解析器,可以将段落转换为句子列表,但我遇到了一个主要问题。所以我使用斯坦福解析器智能地提取句子,但问题是解析器只存储标记列表,而不是句子本身。如果我的客户希望文本与之前显示的完全一致(包括之前的任何间距),这可能会成为一个很大的问题 有人对我如何解决这个问题有什么建议吗 def prepSentenceStrings(text: String): List[String] = { val mod = text.replace("Sr.", "Sr") // deals

我正在尝试构建一个解析器,可以将段落转换为句子列表,但我遇到了一个主要问题。所以我使用斯坦福解析器智能地提取句子,但问题是解析器只存储标记列表,而不是句子本身。如果我的客户希望文本与之前显示的完全一致(包括之前的任何间距),这可能会成为一个很大的问题

有人对我如何解决这个问题有什么建议吗

def prepSentenceStrings(text: String): List[String] = {
     val mod = text.replace("Sr.", "Sr") // deals with an edge case
     val doc = new DocumentPreprocessor(new StringReader(mod))
     doc.map(x => reconfigureSentence(Sentence.listToString(x))).toList}


def reconfigureSentence(text:String) :String = {
    text.replace(" .", ".").replace(" ,",",").replace(" !", "!").replace("( ","(").replace("< ", "<").replace(" )", ")")
def prepSentenceStrings(text:String):List[String]={
val mod=text.replace(“Sr.,“Sr”)//处理边缘情况
val doc=新文档预处理器(新StringReader(mod))
doc.map(x=>reconformesentence(句子.listToString(x))).toList}
def重新配置内容(文本:字符串):字符串={

text.replace(“.”,“)。replace(“,”,”)。replace(“!”,“!”)。replace(“,”)。replace(“<”,“使用Stanford NLP执行句子拆分的问题是,它首先标记整个段落,并在这个过程中删除所有空白字符。据我所知,没有办法重建它们,而且总是有可能最终导致句子稍微改动

您的任务必须使用Scala吗?已经有非常好的分句解决方案,如Perl实现的。我已经使用过几次此工具,并且对输出非常满意。也许您可以从Scala程序调用它,然后处理结果

您可以找到有关不同分句器及其工作原理的概述。

您可以使用的是,为方便起见,它还附带了一个main方法。否则,它只需要一个字符串并返回一个
IndexedSeq[string]
,每句一个。保留空白。如果需要字符偏移量,可以查看Epic的Slab数据结构,该结构可用于此目的

fukaeri:epic dlwh (master)$ java -Xmx8g -cp target/scala-2.11/epic-assembly-0.4-SNAPSHOT.jar epic.preprocess.SegmentSentences
fukaeri:epic dlwh (master)$ vi qq.txt
fukaeri:epic dlwh (master)$ cat qq.txt
I'm trying to build a parser that can turn a          paragraph into a list of sentences, but I'm running into a major problem. So I'm using the stanford parser to pull out the sentences intelligently, but the issue is that the parser only stores the list of tokens, rather than the sentence itself. This can become very problematic if my client wants the text EXACTLY as it showed up before (including any spacing that was there before.
fukaeri:epic dlwh (master)$ java -Xmx8g -cp target/scala-2.11/epic-assembly-0.4-SNAPSHOT.jar epic.preprocess.SegmentSentences < qq.txt
I'm trying to build a parser that can turn a          paragraph into a list of sentences, but I'm running into a major problem.
So I'm using the stanford parser to pull out the sentences intelligently, but the issue is that the parser only stores the list of tokens, rather than the sentence itself.
This can become very problematic if my client wants the text EXACTLY as it showed up before (including any spacing that was there before.
fukaeri:epic dlwh(master)$java-Xmx8g-cp target/scala-2.11/epic-assembly-0.4-SNAPSHOT.jar epic.preprocess.com
fukaeri:epic dlwh(master)$vi qq.txt
fukaeri:epic dlwh(master)$cat qq.txt
我正在尝试构建一个解析器,它可以将段落转换为句子列表,但我遇到了一个大问题。因此我使用斯坦福解析器智能地提取句子,但问题是解析器只存储标记列表,而不是句子本身。如果我的客户想要将文本与之前显示的内容一模一样(包括之前出现的任何间距)。
fukaeri:epic dlwh(master)$java-Xmx8g-cp target/scala-2.11/epic-assembly-0.4-SNAPSHOT.jar epic.preprocess.segmentSequences