lucene

Did you mean feature with Apache Lucene Spell-Checker

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package com.javacodegeeks.lucene.spellcheck;
  
import java.io.File;
  
import org.apache.lucene.search.spell.PlainTextDictionary;
import org.apache.lucene.search.spell.SpellChecker;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
  
public class SimpleSuggestionService {
     
    public static void main(String[] args) throws Exception {
 
   
 
  File dir = new File("c:/spellchecker/");
 
   
 
  Directory directory = FSDirectory.open(dir);
 
   
 
  SpellChecker spellChecker = new SpellChecker(directory);
 
   
 
  spellChecker.indexDictionary(
 
 
 new PlainTextDictionary(new File("c:/fulldictionary00.txt")));
 
   
 
  String wordForSuggestions = "hwllo";
 
   
 
  int suggestionsNumber = 5;
  
 
  String[] suggestions = spellChecker.
 
 
suggestSimilar(wordForSuggestions, suggestionsNumber);
  
 
  if (suggestions!=null && suggestions.length>0) {
 
 
for (String word : suggestions) {
 
 
    System.out.println("Did you mean:" + word);
 
 
}
 
  }
 
  else {
 
 
System.out.println("No suggestions found for word:"+wordForSuggestions);
 
  }
 
 
 
    }
  
}

Related Article:

Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy

Ilias Tsagklis

Ilias is a software developer turned online entrepreneur. He is co-founder and Executive Editor at Java Code Geeks.
Subscribe
Notify of
guest


This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to top button