このサンプル コードを使用して API を使用しています。私はmavenを使いたくないので、ここから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());
}
}
}
この回答をオンラインで見つけましたが、理解できません。
" BritishEnglish は "org" ディレクトリにあり、JAR にはありませんが、"zip -r languages.jar org/" のような JAR を入れて、他の JAR と同じように languages.jar をクラスパスに追加できます。 "