我正在尝试使用OpenNLP 1.5.0构建一个简单的句子检测器。我正在使用Maven Eclipse。我从http://opennlp.sourceforge.net/models-1.5/下载了“en-sent.bin”模型文件并将其放在src / main / resources文件夹中。我的pom.xml文件如下。
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>dakshila.research</groupId>
<artifactId>new1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>new1</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
在'src / main / java'文件夹里面我创建了“dk.research.new1”包,其App.java文件包含以下代码。
package dk.research.new1;
public class App{
public void SentenceSplitter() {
SentenceDetector sentenceDetector = null;
InputStream modelIn = null;
try {
modelIn = getClass().getResourceAsStream("en-sent.bin");
final SentenceModel sentenceModel = new SentenceModel(modelIn);
modelIn.close();
sentenceDetector = new SentenceDetectorME(sentenceModel);
} catch (final IOException ioe) {
ioe.printStackTrace();
} finally {
if (modelIn != null) {
try {
modelIn.close();
} catch (final IOException e) {}
}
}
String sentences[]=(sentenceDetector.sentDetect("I am a student. I am learning programming. I like java language."));
for(int i=0; i<sentences.length;i++) {
System.out.println(sentences[i]);
}
}
}
我在App.java文件中收到以下错误消息。
为什么我会收到这些错误?我尝试了Project-&gt; Clean但我无法摆脱这些错误。我该怎么做才能解决这个问题?
答案 0 :(得分:2)
在<dependencies>
部分的POM中添加:
<dependency>
<groupId>org.apache.opennlp</groupId>
<artifactId>opennlp-tools</artifactId>
<version>1.6.0</version>
</dependency>
然后,您必须在行public class App
添加:
import java.io.IOException;
import java.io.InputStream;
import opennlp.tools.sentdetect.SentenceDetector;
import opennlp.tools.sentdetect.SentenceDetectorME;
import opennlp.tools.sentdetect.SentenceModel;