本文整理匯總了Java中opennlp.tools.sentdetect.SentenceDetectorME.sentPosDetect方法的典型用法代碼示例。如果您正苦於以下問題:Java SentenceDetectorME.sentPosDetect方法的具體用法?Java SentenceDetectorME.sentPosDetect怎麽用?Java SentenceDetectorME.sentPosDetect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類opennlp.tools.sentdetect.SentenceDetectorME
的用法示例。
在下文中一共展示了SentenceDetectorME.sentPosDetect方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import opennlp.tools.sentdetect.SentenceDetectorME; //導入方法依賴的package包/類
public static void main(String[] strings) throws Exception {
String text = "“But I don’t want to go among mad people,” Alice remarked. " +
"“Oh, you can’t help that,” said the Cat: “we’re all mad here. I’m mad. You’re mad.” " +
"“How do you know I’m mad?” said Alice. " +
"“You must be,” said the Cat, “or you wouldn’t have come here.”";
try (InputStream modelIn = new FileInputStream(NATURAL_LANGUAGE_PROCESSING_SRC_MAIN_RESOURCES_EN_SENT_BIN)) {
SentenceModel model = new SentenceModel(modelIn);
SentenceDetectorME sentenceDetector = new SentenceDetectorME(model);
String sentences[] = sentenceDetector.sentDetect(text);
Span sentences2[] = sentenceDetector.sentPosDetect(text);
for (String sentence : sentences) {
System.out.println(sentence);
}
System.out.println(Arrays.deepToString(sentences2));
}
}
示例2: apply
import opennlp.tools.sentdetect.SentenceDetectorME; //導入方法依賴的package包/類
@Override
public void apply(Document doc) {
SentenceDetectorME detector = new SentenceDetectorME(model);
Span[] spans = detector.sentPosDetect(doc.text());
for(int i = 0; i < spans.length; i++) {
int start = spans[i].getStart();
int end = spans[i].getEnd();
new Sentence(doc).setRange(start, end);
}
}
示例3: testOpenNLPPosition
import opennlp.tools.sentdetect.SentenceDetectorME; //導入方法依賴的package包/類
private static Span[] testOpenNLPPosition(String text) throws Exception {
try (InputStream modelIn = new FileInputStream(RESOURCES_EN_SENT_BIN)) {
SentenceModel model = new SentenceModel(modelIn);
SentenceDetectorME sentenceDetector = new SentenceDetectorME(model);
return sentenceDetector.sentPosDetect(text);
}
}