- Cosmetics

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@415093 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Otis Gospodnetic 2006-06-18 05:32:54 +00:00
parent 924914d82b
commit 7bbc7b1544
6 changed files with 68 additions and 75 deletions

View File

@ -24,10 +24,9 @@ import java.util.Iterator;
*/ */
public interface Dictionary { public interface Dictionary {
/** /**
* return all the words present in the dictionnary * Return all words present in the dictionary
* @return Iterator * @return Iterator
*/ */
public Iterator getWordsIterator(); Iterator getWordsIterator();
} }

View File

@ -47,7 +47,7 @@ public class LuceneDictionary implements Dictionary {
final class LuceneIterator implements Iterator { final class LuceneIterator implements Iterator {
private TermEnum termEnum; private TermEnum termEnum;
private Term actualTerm; private Term actualTerm;
private boolean has_next_called; private boolean hasNextCalled;
public LuceneIterator() { public LuceneIterator() {
try { try {
@ -59,16 +59,16 @@ public class LuceneDictionary implements Dictionary {
public Object next() { public Object next() {
if (!has_next_called) { if (!hasNextCalled) {
hasNext(); hasNext();
} }
has_next_called = false; hasNextCalled = false;
return (actualTerm != null) ? actualTerm.text() : null; return (actualTerm != null) ? actualTerm.text() : null;
} }
public boolean hasNext() { public boolean hasNext() {
has_next_called = true; hasNextCalled = true;
try { try {
// if there is still words // if there is still words
if (!termEnum.next()) { if (!termEnum.next()) {
@ -90,6 +90,6 @@ public class LuceneDictionary implements Dictionary {
} }
public void remove() { public void remove() {
}; }
} }
} }

View File

@ -27,10 +27,10 @@ import java.io.*;
/** /**
* Dictionary represented by a file text. * Dictionary represented by a file text.
* *
* <p>Format allowed: 1 word per line:<br> * <p/>Format allowed: 1 word per line:<br/>
* word1<br> * word1<br/>
* word2<br> * word2<br/>
* word3<br> * word3<br/>
* *
* @author Nicolas Maisonneuve * @author Nicolas Maisonneuve
*/ */
@ -38,7 +38,7 @@ public class PlainTextDictionary implements Dictionary {
private BufferedReader in; private BufferedReader in;
private String line; private String line;
private boolean has_next_called; private boolean hasNextCalled;
public PlainTextDictionary(File file) throws FileNotFoundException { public PlainTextDictionary(File file) throws FileNotFoundException {
in = new BufferedReader(new FileReader(file)); in = new BufferedReader(new FileReader(file));
@ -55,16 +55,16 @@ public class PlainTextDictionary implements Dictionary {
final class fileIterator implements Iterator { final class fileIterator implements Iterator {
public Object next() { public Object next() {
if (!has_next_called) { if (!hasNextCalled) {
hasNext(); hasNext();
} }
has_next_called = false; hasNextCalled = false;
return line; return line;
} }
public boolean hasNext() { public boolean hasNext() {
has_next_called = true; hasNextCalled = true;
try { try {
line = in.readLine(); line = in.readLine();
} catch (IOException ex) { } catch (IOException ex) {
@ -77,7 +77,7 @@ public class PlainTextDictionary implements Dictionary {
public void remove() { public void remove() {
}; }
} }
} }

View File

@ -38,8 +38,8 @@ import java.util.*;
/** /**
* <p> * <p>
* Spell Checker class (Main class) <br/> * Spell Checker class (Main class) <br/>
* (initially inspired by the David Spencer code). * (initially inspired by the David Spencer code).
* </p> * </p>
* *
* <p>Example Usage: * <p>Example Usage:
@ -351,7 +351,7 @@ public class SpellChecker {
} }
protected void finalize () throws Throwable { protected void finalize() throws Throwable {
if (reader!=null) { if (reader!=null) {
reader.close(); reader.close();
} }

View File

@ -18,47 +18,43 @@ package org.apache.lucene.search.spell;
*/ */
/** /**
* SuggestWord Class, used in suggestSimilar method in SpellChecker class. * SuggestWord, used in suggestSimilar method in SpellChecker class.
* *
* @author Nicolas Maisonneuve * @author Nicolas Maisonneuve
*/ */
final class SuggestWord { final class SuggestWord {
/** /**
* the score of the word * the score of the word
*/ */
public float score; public float score;
/**
* The freq of the word
*/
public int freq;
/** /**
* The freq of the word * the suggested word
*/ */
public int freq; public String string;
public final int compareTo (SuggestWord a) {
/** //first criteria: the edit distance
* the suggested word if (score > a.score) {
*/ return 1;
public String string;
public final int compareTo (SuggestWord a) {
//first criteria: the edit distance
if (score>a.score) {
return 1;
}
if (score<a.score) {
return-1;
}
//second criteria (if first criteria is equal): the popularity
if (freq>a.freq) {
return 1;
}
if (freq<a.freq) {
return-1;
}
return 0;
} }
if (score < a.score) {
return -1;
}
//second criteria (if first criteria is equal): the popularity
if (freq > a.freq) {
return 1;
}
if (freq < a.freq) {
return -1;
}
return 0;
}
} }

View File

@ -17,25 +17,23 @@ package org.apache.lucene.search.spell;
* limitations under the License. * limitations under the License.
*/ */
/**
* to sort SuggestWord
* @author Nicolas Maisonneuve
*/
import org.apache.lucene.util.PriorityQueue; import org.apache.lucene.util.PriorityQueue;
final class SuggestWordQueue /**
extends PriorityQueue { * Sorts SuggestWord instances
* @author Nicolas Maisonneuve
*/
final class SuggestWordQueue extends PriorityQueue {
SuggestWordQueue (int size) { SuggestWordQueue (int size) {
initialize(size); initialize(size);
} }
protected final boolean lessThan (Object a, Object b) {
SuggestWord wa=(SuggestWord) a;
SuggestWord wb=(SuggestWord) b;
int val=wa.compareTo(wb);
return val<0;
}
protected final boolean lessThan (Object a, Object b) {
SuggestWord wa = (SuggestWord) a;
SuggestWord wb = (SuggestWord) b;
int val = wa.compareTo(wb);
return val < 0;
}
} }