Stanford CoreNLP:每行输入一个句子
Stanford CoreNLP: input with one sentence per line
我在大学作业中使用 Stanford NLP 工具。该解析器在每个点(句点)结束句子,但我还需要在每一行中结束,即在每个字符中结束 '\n' 。通过命令行,您可以使用选项“-sentences”,但到目前为止还没有类似的代码命令。
LexicalizedParser 中的选项 setOptionFlags 也不起作用
您正在寻找的选项是 ssplit.newlineIsSentenceBreak = always
(或者,在命令行中,-ssplit.newlineIsSentenceBreak always
)。除了按通常的标点符号拆分之外,这将始终在换行符上拆分句子。参见 http://nlp.stanford.edu/software/corenlp.shtml
这里有一些示例代码来详细说明 Gabor 的回答:
import java.nio.file.Paths;
import java.nio.file.Files;
import java.nio.charset.StandardCharsets;
import java.io.*;
import java.util.*;
import java.nio.file.Paths;
import java.nio.file.Files;
import java.nio.charset.StandardCharsets;
import edu.stanford.nlp.io.*;
import edu.stanford.nlp.ling.*;
import edu.stanford.nlp.pipeline.*;
import edu.stanford.nlp.trees.*;
import edu.stanford.nlp.semgraph.*;
import edu.stanford.nlp.trees.TreeCoreAnnotations.*;
import edu.stanford.nlp.ling.CoreAnnotations.*;
import edu.stanford.nlp.util.*;
public class ParserExample {
public static void main (String[] args) throws IOException {
String text = new String(Files.readAllBytes(Paths.get(args[0])), StandardCharsets.UTF_8);
Annotation document = new Annotation(text);
Properties props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse");
props.setProperty("ssplit.newlineIsSentenceBreak", "always");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
pipeline.annotate(document);
}
}
args[0] 应该是你的文件路径,每行一句话
您需要从此 link 下载 Stanford CoreNLP 3.5.2 并将下载的 jar 文件放入您的类路径中:http://nlp.stanford.edu/software/corenlp.shtml
您可以使用 props.setProperty()
为解析器设置其他选项
如果你有一个每行一个句子的文件,你可以使用
props.setProperty("ssplit.eolonly", "true");
如果您只想按换行符拆分。
在属性文件中,添加:
ssplit.newlineIsSentenceBreak = always
我在大学作业中使用 Stanford NLP 工具。该解析器在每个点(句点)结束句子,但我还需要在每一行中结束,即在每个字符中结束 '\n' 。通过命令行,您可以使用选项“-sentences”,但到目前为止还没有类似的代码命令。
LexicalizedParser 中的选项 setOptionFlags 也不起作用
您正在寻找的选项是 ssplit.newlineIsSentenceBreak = always
(或者,在命令行中,-ssplit.newlineIsSentenceBreak always
)。除了按通常的标点符号拆分之外,这将始终在换行符上拆分句子。参见 http://nlp.stanford.edu/software/corenlp.shtml
这里有一些示例代码来详细说明 Gabor 的回答:
import java.nio.file.Paths;
import java.nio.file.Files;
import java.nio.charset.StandardCharsets;
import java.io.*;
import java.util.*;
import java.nio.file.Paths;
import java.nio.file.Files;
import java.nio.charset.StandardCharsets;
import edu.stanford.nlp.io.*;
import edu.stanford.nlp.ling.*;
import edu.stanford.nlp.pipeline.*;
import edu.stanford.nlp.trees.*;
import edu.stanford.nlp.semgraph.*;
import edu.stanford.nlp.trees.TreeCoreAnnotations.*;
import edu.stanford.nlp.ling.CoreAnnotations.*;
import edu.stanford.nlp.util.*;
public class ParserExample {
public static void main (String[] args) throws IOException {
String text = new String(Files.readAllBytes(Paths.get(args[0])), StandardCharsets.UTF_8);
Annotation document = new Annotation(text);
Properties props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse");
props.setProperty("ssplit.newlineIsSentenceBreak", "always");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
pipeline.annotate(document);
}
}
args[0] 应该是你的文件路径,每行一句话
您需要从此 link 下载 Stanford CoreNLP 3.5.2 并将下载的 jar 文件放入您的类路径中:http://nlp.stanford.edu/software/corenlp.shtml
您可以使用 props.setProperty()
为解析器设置其他选项如果你有一个每行一个句子的文件,你可以使用
props.setProperty("ssplit.eolonly", "true");
如果您只想按换行符拆分。
在属性文件中,添加:
ssplit.newlineIsSentenceBreak = always