Modified:
trunk/src/main/java/com/google/bspell/BSpellCheck.java
trunk/src/main/java/com/google/bspell/ant/BSpellTask.java
trunk/src/main/java/com/google/bspell/parsers/JavaParser.java
Log:
* Check the combined words
* All reserved words are lowercased
* Filter the valid files
Modified: trunk/src/main/java/com/google/bspell/BSpellCheck.java
==============================================================================
--- trunk/src/main/java/com/google/bspell/BSpellCheck.java (original)
+++ trunk/src/main/java/com/google/bspell/BSpellCheck.java Sun Aug 12 17:54:05 2007
@@ -5,11 +5,14 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import java.util.StringTokenizer;
import com.google.bspell.model.Configuration;
import com.google.bspell.model.Word;
+import com.google.bspell.utils.StringUtils;
import com.google.bspell.parsers.Parser;
import com.google.bspell.parsers.ParserFactory;
+
import com.softcorporation.suggester.BasicSuggester;
import com.softcorporation.suggester.Suggestion;
import com.softcorporation.suggester.dictionary.BasicDictionary;
@@ -21,28 +24,28 @@
public class BSpellCheck {
private Configuration config;
+ private SpellCheck spellCheck;
public BSpellCheck() {
}
- public void setConfiguration(final Configuration c) {
+ public void init(final Configuration c) {
this.config = c;
- }
-
- public List<Word> check(final File file) throws FileNotFoundException, IOException {
- if (config == null) {
- System.out.println("Warning: No configration is specified.");
- }
BasicDictionary dictionary = new BasicDictionary("file://" + config.getDictionary());
SpellCheckConfiguration configuration = new SpellCheckConfiguration("file://" + config.getSpellCheckConfig());
BasicSuggester suggester = new BasicSuggester(configuration);
suggester.attach(dictionary);
-
- SpellCheck spellCheck = new SpellCheck(configuration);
+ spellCheck = new SpellCheck(configuration);
spellCheck.setSuggester(suggester);
- spellCheck.setSuggestionLimit(3);
+ spellCheck.setSuggestionLimit(5);
+ }
+
+ public List<Word> check(final File file) throws FileNotFoundException, IOException {
+ if (config == null) {
+ System.out.println("Warning: No configuration is specified.");
+ }
Parser parser = ParserFactory.getInstance(config).getParser(file);
List<Word> words = parser.parse(file);
@@ -56,16 +59,59 @@
ArrayList suggestions = null;
while (spellCheck.hasMisspelt()) {
- failed.add(word);
- String misspeltWord = spellCheck.getMisspelt();
suggestions = spellCheck.getSuggestions();
+
+ String combined = getCombinedWithValidWords(suggestions, spellCheck.getMisspelt());
+ if (combined != null) {
+ word.getSuggestions().add(combined);
+ break;
+ }
+
for (int j = 0; j < suggestions.size(); j++) {
Suggestion suggestion = (Suggestion) suggestions.get(j);
word.getSuggestions().add(suggestion.getWord());
}
spellCheck.checkNext();
}
+ if (word.getSuggestions().size() > 0) {
+ failed.add(word);
+ }
}
return failed;
}
+
+ public String getCombinedWithValidWords(ArrayList suggestions, String misspeltWord) {
+ for (int j = 0; j < suggestions.size(); j++) {
+ Suggestion suggestion = (Suggestion) suggestions.get(j);
+ String word = suggestion.getWord();
+ if (word.indexOf(" ") == -1) {
+ continue;
+ }
+ StringTokenizer tokens = new StringTokenizer(word, " ");
+ StringBuffer sample = new StringBuffer();
+ boolean found = true;
+ while (tokens.hasMoreTokens()) {
+ String token = tokens.nextToken().toLowerCase();
+ if (hasMisspelt(token)) {
+ found = false;
+ break;
+ }
+ sample.append(StringUtils.capitalize(token));
+ if (!misspeltWord.toLowerCase().startsWith(sample.toString().toLowerCase())) {
+ found = false;
+ break;
+ }
+ }
+ if (found) {
+ return sample.toString();
+ }
+ }
+ return null;
+ }
+
+ private boolean hasMisspelt(String word) {
+ spellCheck.setText(word, Constants.DOC_TYPE_TEXT, "en");
+ spellCheck.check();
+ return spellCheck.hasMisspelt();
+ }
}
Modified: trunk/src/main/java/com/google/bspell/ant/BSpellTask.java
==============================================================================
--- trunk/src/main/java/com/google/bspell/ant/BSpellTask.java (original)
+++ trunk/src/main/java/com/google/bspell/ant/BSpellTask.java Sun Aug 12 17:54:05 2007
@@ -72,14 +72,16 @@
}
BSpellCheck checker = new BSpellCheck();
- checker.setConfiguration(this.config);
+ checker.init(this.config);
Map<File, List<Word>> failures = new HashMap<File, List<Word>>();
try {
for (File source : sources) {
List<Word> failed = checker.check(source);
- failures.put(source, failed);
+ if (!failed.isEmpty()) {
+ failures.put(source, failed);
+ }
}
} catch (Exception e) {
e.printStackTrace();
Modified: trunk/src/main/java/com/google/bspell/parsers/JavaParser.java
==============================================================================
--- trunk/src/main/java/com/google/bspell/parsers/JavaParser.java (original)
+++ trunk/src/main/java/com/google/bspell/parsers/JavaParser.java Sun Aug 12 17:54:05 2007
@@ -18,7 +18,7 @@
));
public static final Set<String> EXCLUDES = new HashSet<String>(Arrays.asList(
- "println", "util", "args", "argv", "main", "Millis",
+ "println", "util", "args", "argv", "main", "millis",
"get", "set", "io", "out", "src", "jaxb", "jaxws", "wsdl4j", "xmlns", "pom"
));