mirror of https://github.com/apache/lucene.git
- Cosmetics
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@415093 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
924914d82b
commit
7bbc7b1544
|
@ -25,9 +25,8 @@ import java.util.Iterator;
|
|||
public interface Dictionary {
|
||||
|
||||
/**
|
||||
* return all the words present in the dictionnary
|
||||
* Return all words present in the dictionary
|
||||
* @return Iterator
|
||||
*/
|
||||
public Iterator getWordsIterator();
|
||||
|
||||
Iterator getWordsIterator();
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ public class LuceneDictionary implements Dictionary {
|
|||
final class LuceneIterator implements Iterator {
|
||||
private TermEnum termEnum;
|
||||
private Term actualTerm;
|
||||
private boolean has_next_called;
|
||||
private boolean hasNextCalled;
|
||||
|
||||
public LuceneIterator() {
|
||||
try {
|
||||
|
@ -59,16 +59,16 @@ public class LuceneDictionary implements Dictionary {
|
|||
|
||||
|
||||
public Object next() {
|
||||
if (!has_next_called) {
|
||||
if (!hasNextCalled) {
|
||||
hasNext();
|
||||
}
|
||||
has_next_called = false;
|
||||
hasNextCalled = false;
|
||||
return (actualTerm != null) ? actualTerm.text() : null;
|
||||
}
|
||||
|
||||
|
||||
public boolean hasNext() {
|
||||
has_next_called = true;
|
||||
hasNextCalled = true;
|
||||
try {
|
||||
// if there is still words
|
||||
if (!termEnum.next()) {
|
||||
|
@ -90,6 +90,6 @@ public class LuceneDictionary implements Dictionary {
|
|||
}
|
||||
|
||||
public void remove() {
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,10 +27,10 @@ import java.io.*;
|
|||
/**
|
||||
* Dictionary represented by a file text.
|
||||
*
|
||||
* <p>Format allowed: 1 word per line:<br>
|
||||
* word1<br>
|
||||
* word2<br>
|
||||
* word3<br>
|
||||
* <p/>Format allowed: 1 word per line:<br/>
|
||||
* word1<br/>
|
||||
* word2<br/>
|
||||
* word3<br/>
|
||||
*
|
||||
* @author Nicolas Maisonneuve
|
||||
*/
|
||||
|
@ -38,7 +38,7 @@ public class PlainTextDictionary implements Dictionary {
|
|||
|
||||
private BufferedReader in;
|
||||
private String line;
|
||||
private boolean has_next_called;
|
||||
private boolean hasNextCalled;
|
||||
|
||||
public PlainTextDictionary(File file) throws FileNotFoundException {
|
||||
in = new BufferedReader(new FileReader(file));
|
||||
|
@ -55,16 +55,16 @@ public class PlainTextDictionary implements Dictionary {
|
|||
|
||||
final class fileIterator implements Iterator {
|
||||
public Object next() {
|
||||
if (!has_next_called) {
|
||||
if (!hasNextCalled) {
|
||||
hasNext();
|
||||
}
|
||||
has_next_called = false;
|
||||
hasNextCalled = false;
|
||||
return line;
|
||||
}
|
||||
|
||||
|
||||
public boolean hasNext() {
|
||||
has_next_called = true;
|
||||
hasNextCalled = true;
|
||||
try {
|
||||
line = in.readLine();
|
||||
} catch (IOException ex) {
|
||||
|
@ -77,7 +77,7 @@ public class PlainTextDictionary implements Dictionary {
|
|||
|
||||
|
||||
public void remove() {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -351,7 +351,7 @@ public class SpellChecker {
|
|||
}
|
||||
|
||||
|
||||
protected void finalize () throws Throwable {
|
||||
protected void finalize() throws Throwable {
|
||||
if (reader!=null) {
|
||||
reader.close();
|
||||
}
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
final class SuggestWord {
|
||||
final class SuggestWord {
|
||||
/**
|
||||
* the score of the word
|
||||
*/
|
||||
public float score;
|
||||
|
||||
|
||||
/**
|
||||
* The freq of the word
|
||||
*/
|
||||
public int freq;
|
||||
|
||||
|
||||
/**
|
||||
* the suggested word
|
||||
*/
|
||||
public String string;
|
||||
|
||||
|
||||
public final int compareTo (SuggestWord a) {
|
||||
//first criteria: the edit distance
|
||||
if (score>a.score) {
|
||||
if (score > a.score) {
|
||||
return 1;
|
||||
}
|
||||
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) {
|
||||
if (freq > a.freq) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (freq<a.freq) {
|
||||
return-1;
|
||||
if (freq < a.freq) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,25 +17,23 @@ package org.apache.lucene.search.spell;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* to sort SuggestWord
|
||||
* @author Nicolas Maisonneuve
|
||||
*/
|
||||
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) {
|
||||
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;
|
||||
SuggestWord wa = (SuggestWord) a;
|
||||
SuggestWord wb = (SuggestWord) b;
|
||||
int val = wa.compareTo(wb);
|
||||
return val < 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue