2016-10-03 1 views
0

Ich versuche einige falsch geschriebene Wörter in einer Textdatei mithilfe der LanguageTool Java API zu korrigieren. Nachdem man durch LT Wiki und https://languagetool.org/ habe ich versucht, einige Beispiel-Codes -Fehler bei der Rechtschreibprüfung mit LanguageTool Java API nicht möglich

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()); 
} 

Die Ausgabe wird wie folgt -

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: [] 

Erwartet Ouput -

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 

ich diese Ausgabe von LT Standalone bekam Desktop-Software. Ich habe seine Installationsordner und deren Inhalt mit meinem Quellcode und API-Gläsern verglichen, konnte aber nichts Besonderes finden, was die erstere zu einer besseren Lösung macht.

Auch ich möchte die falsch geschriebenen Wörter durch das erste Element in der Vorschlagsliste ersetzen.

Jede Art von Hilfe wird sehr geschätzt.

Antwort

1

Ich benutzte altes Languagetool Glas. Bitte verwenden Sie diese -

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

Auch kann die Rechtschreibkorrektur, indem Sie falsch geschriebene Wörter aus (match.getFromPos() zu match.getToPos()) und ersetzt sie mit dem überzeugendsten Wort aus Vorschlagsliste erfolgen (sein bis zum Programmierer, um das Wort zu wählen).

Ich hoffe, es kann hilfreich sein.

+0

'3,5' ist das, was aktuell ist, es wird auch in 3 Monaten veraltet sein. Bitte benutzen Sie die Version unter http://wiki.languagetool.org/java-api, wir aktualisieren diese Seite. (Disclosure: Ich bin der Betreuer von LanguageTool) –

+0

Danke Daniel .. – Rana

Verwandte Themen