Stanford NLP CoreNLP 不对中文进行分句

Stanford NLP CoreNLP don't do sentence split for chinese

我的环境:


我的测试文本是"這是第一個句子。這是第二個句子。" 我从

得到句子
val sentences = annotation.get(classOf[SentencesAnnotation])
for (sent <- sentences) {
  count+=1
  println("sentence{$count} = " + sent.get(classOf[TextAnnotation]))
}

它总是将整个测试文本打印为一个句子,而不是预期的两个句子:

sentence1 = 這是第一個句子。這是第二個句子。

预期是:

expected sentence1 = 這是第一個句子。
expected sentence2 = 這是第二個句子。

如果我添加更多属性,即使结果相同:

ssplit.eolonly = false
ssplit.isOneSentence = false
ssplit.newlineIsSentenceBreak = always
ssplit.boundaryTokenRegex = [.]|[!?]+|[。]|[!?]+

CoreNLP 日志是

Registering annotator segment with class edu.stanford.nlp.pipeline.ChineseSegmenterAnnotator
Adding annotator segment
Loading Segmentation Model [edu/stanford/nlp/models/segmenter/chinese/ctb.gz]...Loading classifier from edu/stanford/nlp/models/segmenter/chinese/ctb.gz ... Loading Chinese dictionaries from 1 files:
  edu/stanford/nlp/models/segmenter/chinese/dict-chris6.ser.gz

loading dictionaries from edu/stanford/nlp/models/segmenter/chinese/dict-chris6.ser.gz...Done. Unique words in ChineseDictionary is: 423200
done [56.9 sec].
done. Time elapsed: 57041 ms
Adding annotator ssplit
Adding Segmentation annotation...output: [null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null]
INFO: TagAffixDetector: useChPos=false | useCTBChar2=true | usePKChar2=false
INFO: TagAffixDetector: building TagAffixDetector from edu/stanford/nlp/models/segmenter/chinese/dict/character_list and edu/stanford/nlp/models/segmenter/chinese/dict/in.ctb
Loading character dictionary file from edu/stanford/nlp/models/segmenter/chinese/dict/character_list
Loading affix dictionary from edu/stanford/nlp/models/segmenter/chinese/dict/in.ctb
這是第一個句子。這是第二個句子。
--->
[這是, 第一, 個, 句子, 。, 這是, 第二, 個, 句子, 。]
done. Time elapsed: 419 ms

我曾经看到someone得到以下日志(CoreNLP 3.5.0);但是奇怪的是我没有这个日志:

Adding annotator ssplit edu.stanford.nlp.pipeline.AnnotatorImplementations:ssplit.boundaryTokenRegex=[.]|[!?]+|[。]|[!?]+

有什么问题吗?有解决方法吗?如果无法解决,我可以自己拆分,但我不知道如何将我的拆分集成到 CoreNLP 管道中。

好的,我解决了这个问题。

自己定义 ssplit 注释器。

为了方便我在这里硬编码参数,虽然正确的方法应该解析道具。

class MyWordsToSentencesAnnotator extends WordsToSentencesAnnotator(
  true,
  "[.]|[!?]+|[。]|[!?]+",
  null,
  null,
  "never") {
  def this(name: String, props: Properties) { this() }
}

并在 属性 文件中指定 class。

customAnnotatorClass.myssplit = ...

显然,我猜默认的 CoreNLP 管道设置或代码有错误?

我遇到了同样的问题,直到我用它的 Unicode 格式替换中文标点符号并设置 属性 如下:

props.setProperty("ssplit.boundaryTokenRegex", "[.\u3002]|[!?\uFF01\uFF1F]+");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);