我正在使用this示例代码来使用API。我不想使用maven,所以我从here下载了jar文件,并将org和lib中的Jar文件包含到构建路径中,然后尝试运行示例代码。我收到了这个错误:
Error:(15, 56) java: cannot find symbol
symbol: class BritishEnglish
location: class draft
Error:(3, 34) java: cannot find symbol
symbol: class BritishEnglish
location: package org.languagetool.language
这是我的代码
import org.languagetool.JLanguageTool;
import org.languagetool.language.BritishEnglish;
import org.languagetool.rules.RuleMatch;
import java.io.*;
import java.util.List;
public class draft {
public static void main(String[] args) throws IOException {
JLanguageTool langTool = new JLanguageTool(new BritishEnglish());
// comment in to use statistical ngram data:
//langTool.activateLanguageModelRules(new File("/data/google-ngram-data"));
List<RuleMatch> matches = langTool.check("A sentence with a error in the Hitchhiker's Guide tot he Galaxy");
for (RuleMatch match : matches) {
System.out.println("Potential error at characters " +
match.getFromPos() + "-" + match.getToPos() + ": " +
match.getMessage());
System.out.println("Suggested correction(s): " +
match.getSuggestedReplacements());
}
}
}
我在网上找到了这个答案,但我不明白。
&#34;英国英语在&#34; org&#34;目录而不是JAR,但你可以放入这样的JAR:&#34; zip -r languages.jar org /&#34 ;,然后像其他JAR一样将languages.jar添加到类路径中。 &#34;
答案 0 :(得分:1)
显然,语言实现本身被打包到单独的jar中。你需要的是language-en.jar:
https://search.maven.org/remotecontent?filepath=org/languagetool/language-en/3.5/language-en-3.5.jar
你可以在这里看到:
jameson@spinach:~$ jar -tf language-en-3.5.jar | grep BritishEnglish
org/languagetool/language/BritishEnglish.class
尝试下载并将其添加到类路径中。另外,请务必执行doc http://wiki.languagetool.org/java-api#toc4中的项目。我不建议重新打包一个依赖jar,那就是kludgy。我也建议改用maven。