斯坦福coreNLP分裂句子没有空格

问题描述 投票:0回答:1

我遇到了斯坦福的句子注释器的问题。作为输入,我得到了包含句子的文本,但在某些部分之后没有空格。像这样:

狗爱猫。猫爱老鼠。老鼠讨厌每个人。

因此,当我尝试使用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是单个单词并且不会拆分它。

java nlp stanford-nlp
1个回答
1
投票

这是一个管道,其中句子分割器将识别由标记器提供的标记的句子边界,但是句子分割器仅将相邻的标记分组为句子,它不会尝试合并或拆分它们。

正如您所发现的那样,我认为ssplit.boundaryTokenRegex属性会告诉句子分割器在看到“。”时结束一个句子。作为一种标记,但是在令牌化器没有拆分“。”的情况下这没有用。除了周围的文本成一个单独的标记。

你需要:

  • 预处理您的文本(在“cat。”之后插入一个空格),
  • 对你的代币或句子进行后处理以分割这样的案例,或者
  • 查找/开发一个可以将“cat.Cat”拆分为三个标记的标记生成器。

通常打算与报纸文本一起使用的标准英语标记器都没有被开发来处理这种文本。

一些相关问题:

Does the NLTK sentence tokenizer assume correct punctuation and spacing?

How to split text into sentences when there is no space after full stop?

© www.soinside.com 2019 - 2024. All rights reserved.