nlp - 斯坦福 NLP CoreNLP 不对中文进行句子分割

标签 nlp stanford-nlp

我的环境:

  • CoreNLP 3.5.1
  • stanford-chinese-corenlp-2015-01-30-models
  • 中文默认属性文件:StanfordCoreNLP-chinese.properties
    • 注释器 = 分段、ssplit
<小时/>

我的测试文本是“这是第一个句子。这是第二个句子。” 我从

得到句子
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 注释器。

为了方便起见,我在这里对参数进行了硬编码,尽管正确的方法应该解析 Prop 。

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

并在属性文件中指定类。

customAnnotatorClass.myssplit = ...
<小时/>

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

关于nlp - 斯坦福 NLP CoreNLP 不对中文进行句子分割,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29542569/

相关文章:

stanford-nlp - 斯坦福 CoreNLP 服务器禁用日志记录

nlp - 在计算unigram LM时如何处理<s>和</s>?

java - synset 中的 wordnet 词组

python - 如何使用 NLP 和实体识别从文本中正确提取设施和设施等实体?

java - 使用 Stanford CoreNLP 的共指解析

stanford-nlp - CoreNLP 服务器不返回实体提及

python - 如何使用无监督方法将句子分类到预定义的主题桶之一

google-cloud-platform - 我如何训练以在 NLP 中找到美国状态的出现?

neural-network - 预训练的 GloVe 矢量文件(例如 glove.6B.50d.txt)中的 "unk"是什么?

java - 斯坦福 POS 标记器 : How to preserve newlines in the output?