Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spell check and/or spell correction in Java [duplicate]

How can I do spell checking and/or spell correction in a Java application?

like image 679
Ronaldinho Learn Coding Avatar asked May 24 '12 05:05

Ronaldinho Learn Coding


People also ask

How to perform spelling correction for given string in Java?

Generally, The Jazzy API is used to perform Spelling Correction for Given String in Java. It can be downloaded in the below link. Download Jazzy Core 0.5.2 Jar and Add downloaded jar file to your eclipse Project.

What is spellcheckerapplication in Java?

The SpellCheckerApplication is a class, which contain the main method. Eventually Its our entry point of Java Spelling Checker application.

How to check if the spelling of a string key is correct?

Given an array of strings str [] and a string key, the task is to check if the spelling of the key is correct or not. If found to be true, then print “YES”. Otherwise, print the suggested correct spellings. The string “geek” not present in the array of strings.

How to create a spell checker using stringwordparser in Java?

Create a SpellingDialog (AWT) or JSpellCheckDlg (Swing) object and pass the StringWordParser to the constructor Call the SpellingDialog's or JSpellCheckDlg's setVisible method to being the spell check operation.


2 Answers

Google's Spell Checker http://code.google.com/p/google-api-spelling-java/

 SpellChecker checker = new SpellChecker();

 SpellResponse spellResponse = checker.check( "helloo worlrd" );

 for( SpellCorrection sc : spellResponse.getCorrections() )
    System.out.println( sc.getValue() );

It's much like when you use Gmail or Google services (like translate.google.com or search) that gives you alternate suggestion if you have a typo.

What happens in the background?

The SpellChecker class transforms the request into XML and sends it to the Google's spell checker service. The response is also in XML, which is then deserialized into simple POJOs.

The request to the first example above looks like:

  <?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
  <spellrequest textalreadyclipped="0" ignoredigits="1" 
                          ignoreallcaps="1" ignoredups="0">
    <text>helloo worlrd</text>  
  </spellrequest>

And the response XML looks like:

  <?xml version="1.0" encoding="UTF-8"?>  
  <spellresult error="0" clipped="0" charschecked="13">
     <c o="0" l="6" s="1">hello  Helli   hell    hallo   hullo</c>
     <c o="7" l="6" s="1">world  whorled wold    warlord would</c>  
  </spellresult>

Haven't tried though.


UPDATE:
Google might have started charging for this. I do not have time to code to check this. Someone can confirm. As far as Google is concerned, it seems that they have deprecated the old API for new and paid one.

Refer: Google Translate API FAQ

What happened to earlier free versions of Translate API?
Google Translate API v1 is no longer available as of December 1, 2011 and has been replaced by Google Translate API v2. Google Translate API v1 was officially deprecated on May 26, 2011. The decision to deprecate the API and replace it with the paid service was made due to the substantial economic burden caused by extensive abuse.

like image 52
Nishant Avatar answered Sep 25 '22 06:09

Nishant


You can use JOrtho. I have used it earlier in one of the swing app.

like image 38
Rakesh Avatar answered Sep 26 '22 06:09

Rakesh