2016-10-03 7 views
0

Je tente de corriger certains mots mal orthographiés présents dans un fichier texte à l'aide de LanguageTool Java API. Après avoir traversé wiki LT et https://languagetool.org/ J'ai essayé quelques exemples de codes -Impossible d'orthographe correcte à l'aide de l'API Java LanguageTool

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

La sortie est la suivante -

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

Ouput attendu -

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 

Je suis cette sortie autonome LT Logiciel de bureau J'ai comparé ses dossiers d'installation et son contenu avec mon code source et mes bogues d'API, mais je n'ai rien trouvé de spécial, ce qui en fait une meilleure solution.

En outre, je souhaite remplacer les mots mal orthographiés par le premier élément de la liste de suggestions.

Tout type d'aide sera grandement apprécié.

Répondre

1

J'utilisais un vieux pot de Languagetool. S'il vous plaît utiliser -

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

En outre, la correction orthographique peut être fait en sélectionnant les mots mal orthographiés de (match.getFromPos() à match.getToPos()) et le remplacer par le mot le plus convaincant de la liste de suggestion (son jusqu'à ce que le programmeur choisisse le mot).

Espérons que cela puisse être utile.

+0

'3.5' est ce qui est à jour maintenant, il sera également obsolète dans 3 mois. Alors s'il vous plaît utilisez la version donnée sur http://wiki.languagetool.org/java-api, nous gardons cette page à jour. (Divulgation: Je suis le mainteneur de LanguageTool) –

+0

Merci Daniel .. – Rana