我遇到了斯坦福的句子注释器的问题。作为输入,我得到了包含句子的文本,但在某些部分之后没有空格。像这样:
狗爱猫。猫爱老鼠。老鼠讨厌每个人。
因此,当我尝试使用SentenceAnnotator时 - 我得到2个句子
狗爱猫。猫爱老鼠。
老鼠讨厌每个人。
这是我的代码
Annotation doc = new Annotation(t);
Properties props = new Properties();
props.setProperty("annotators", "tokenize,ssplit,pos,lemma,ner,parse,coref");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
pipeline.annotate(doc);
List<CoreMap> sentences = doc.get(CoreAnnotations.SentencesAnnotation.class);
我也尝试添加属性
props.setProperty("ssplit.boundaryTokenRegex", "\\.");
但没有效果。
也许我错过了什么?谢谢!
UPD我还尝试使用PTBTokenizer对文本进行标记
PTBTokenizer ptbTokenizer = new PTBTokenizer(
new FileReader(classLoader.getResource("simplifiedParagraphs.txt").getFile())
,new WordTokenFactory()
,"untokenizable=allKeep,tokenizeNLs=true,ptb3Escaping=true,strictTreebank3=true,unicodeEllipsis=true");
List<String> strings = ptbTokenizer.tokenize();
但是tokenizer认为cat.Cat是单个单词并且不会拆分它。
这是一个管道,其中句子分割器将识别由标记器提供的标记的句子边界,但是句子分割器仅将相邻的标记分组为句子,它不会尝试合并或拆分它们。
正如您所发现的那样,我认为ssplit.boundaryTokenRegex
属性会告诉句子分割器在看到“。”时结束一个句子。作为一种标记,但是在令牌化器没有拆分“。”的情况下这没有用。除了周围的文本成一个单独的标记。
你需要:
通常打算与报纸文本一起使用的标准英语标记器都没有被开发来处理这种文本。
一些相关问题:
Does the NLTK sentence tokenizer assume correct punctuation and spacing?
How to split text into sentences when there is no space after full stop?