我的环境:
- 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/