0

Eclipse と共に LanguageTool を使用しています。API には、次のリンクを使用してアクセスできます: Click here . 特定の列にスペルミスのある単語があることを示すテキスト出力を取得できますが、入力として指定されたスペルミスの文字列の修正された文字列バージョンである出力を取得できません。これが私のコードです:

JLanguageTool langTool = new JLanguageTool(new BritishEnglish());
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 line " +
      match.getLine() + ", column " +
      match.getColumn() + ": " + match.getMessage());
  System.out.println("Suggested correction: " +
      match.getSuggestedReplacements());
}

得られる出力は次のとおりです。

Potential error at line 0, column 17: Use <suggestion>an</suggestion> instead of 'a' if the following word starts with a vowel sound, e.g. 'an article', 'an hour'
Suggested correction: [an]
Potential error at line 0, column 32: Possible spelling mistake found
Suggested correction: [Hitch-hiker]
Potential error at line 0, column 51: Did you mean <suggestion>to the</suggestion>?
Suggested correction: [to the]

次のように、出力を入力文字列の修正バージョンにしたいと思います。

A sentence with an error in the Hitchhiker's Guide to the Galaxy

どうすればこれを実行できますか?

4

2 に答える 2

0

のいずれかを使用して、元の入力文字列を from ~ にmatch.getSuggestedReplacements()置き換えます。使用する候補 (複数ある場合) を自動的に決定することはできず、ユーザーは 1 つを選択する必要があります。match.getFromPos()match.getToPos()

于 2016-07-30T16:00:01.363 に答える