2016-10-03 8 views
0

LanguageTool Java APIを使用して、テキストファイルにあるスペルの間違った単語を修正しようとしています。 LTのwikiとhttps://languagetool.org/を通過した後、私はいくつかのサンプルコードを試してみました -LanguageTool Java APIを使用して正しくスペルチェックできない

JLanguageTool langTool; 
String text = "I.- Any reference _in this Section to a panicular genus or species of an anirmgl, cxccpl where the context"; 
langTool = new JLanguageTool(Language.AMERICAN_ENGLISH); 
langTool.activateDefaultPatternRules(); 

List<RuleMatch> matches = langTool.check(text); 
for (RuleMatch match : matches) { 
      System.out.println("Potential error at line " + 
       match.getEndLine() + ", column " + 
       match.getColumn() + ": " + match.getMessage()); 
      System.out.println("Suggested correction: " + 
       match.getSuggestedReplacements()); 
} 

次のように出力されている -

Potential error at line 0, column 19: Possible spelling mistake found 
Suggested correction: [Lin, Min, ain, bin, din, fin, gin, in, kin, min, pin, sin, tin, win, yin] 
Potential error at line 0, column 41: Possible spelling mistake found 
Suggested correction: [] 
Potential error at line 0, column 74: Possible spelling mistake found 
Suggested correction: [] 
Potential error at line 0, column 83: Possible spelling mistake found 
Suggested correction: [] 

期待出力リレー -

Starting check in English (American)... 
1. Line 1, column 19 
Message: Possible spelling mistake found (deactivate) 
Correction: in; win; bin; pin; tin; min; Lin; din; gin; kin; yin; ain; fin; sin; IN; In; Min; PIN 
Context: I.- Any reference _in this Section to a panicular genus or sp... 
2. Line 1, column 41 
Message: Possible spelling mistake found (deactivate) 
Correction: particular; funicular 
Context: ...I.- Any reference _in this Section to a panicular genus or species of an anirmgl, cxccpl ... 
3. Line 1, column 74 
Message: Possible spelling mistake found (deactivate) 
Correction: animal 
Context: ...n to a panicular genus or species of an anirmgl, cxccpl where the context 
4. Line 1, column 83 
Message: Possible spelling mistake found (deactivate) 
Context: ...nicular genus or species of an anirmgl, cxccpl where the context 
Potential problems found: 4 (time: 171ms) 
How you can improve LanguageTool 

私はLT standaloneからこの出力を得ましたデスクトップソフトウェア。インストールフォルダとその内容を私のソースコードとAPIのjarファイルと比較しましたが、前者をより良い解決策にする特別なものは見つかりませんでした。

また、スペルミスリストの最初の要素に間違った単語を置きたいと思います。

どのようなヘルプも高く評価されます。

答えて

1

私は古いLanguagetool jarを使用していました。これを使用してください -

<dependency> 
<groupId>org.languagetool</groupId> 
<artifactId>language-en</artifactId> 
<version>3.5</version> 
</dependency> 

また、スペル訂正は、その((match.getFromPos()match.getToPosに())からのスペルミスを選択し、候補リストから最も説得力のある言葉に置き換えることによって行うことができますプログラマーにその言葉を選ぶまで)。

希望します。

+0

「3.5」は最新のものですが、3ヶ月で時代遅れになります。 http://wiki.languagetool.org/java-apiにあるバージョンを使用してください。私たちはそのページを更新しています。 (Disclosure:私はLanguageToolのメンテナーです) –

+0

Danielに感謝します。 – Rana

関連する問題