Revision: 8620
http://languagetool.svn.sourceforge.net/languagetool/?rev=8620&view=rev
Author: dnaber
Date: 2012-12-21 22:58:18 +0000 (Fri, 21 Dec 2012)
Log Message:
-----------
small code cleanup by moving logic to their own methods
Modified Paths:
--------------
trunk/JLanguageTool/docs/internal.txt
trunk/JLanguageTool/src/main/java/org/languagetool/rules/spelling/SuggestionExtractor.java
trunk/JLanguageTool/src/main/java/org/languagetool/rules/spelling/morfologik/MorfologikSpellerRule.java
Modified: trunk/JLanguageTool/docs/internal.txt
===================================================================
--- trunk/JLanguageTool/docs/internal.txt 2012-12-21 20:14:29 UTC (rev
8619)
+++ trunk/JLanguageTool/docs/internal.txt 2012-12-21 22:58:18 UTC (rev
8620)
@@ -19,7 +19,7 @@
-ask for Transifex updates if needed
-no new i18n strings allowed
-ask for fixing false alarms on
http://community.languagetool.org/corpusMatch/list?lang=en etc
--announce freeze on twitter
+-ask people to test the snapshots on twitter and in the forum
** How to make a LanguageTool release **
Modified:
trunk/JLanguageTool/src/main/java/org/languagetool/rules/spelling/SuggestionExtractor.java
===================================================================
---
trunk/JLanguageTool/src/main/java/org/languagetool/rules/spelling/SuggestionExtractor.java
2012-12-21 20:14:29 UTC (rev 8619)
+++
trunk/JLanguageTool/src/main/java/org/languagetool/rules/spelling/SuggestionExtractor.java
2012-12-21 22:58:18 UTC (rev 8620)
@@ -57,9 +57,7 @@
}
/**
- * Get suggestions that don't use back references or regular
- * @param message
- * @return
+ * Get suggestions that don't use back references or regular expressions.
*/
List<String> getSimpleSuggestions(String message) {
final Matcher matcher = SUGGESTION_PATTERN.matcher(message);
Modified:
trunk/JLanguageTool/src/main/java/org/languagetool/rules/spelling/morfologik/MorfologikSpellerRule.java
===================================================================
---
trunk/JLanguageTool/src/main/java/org/languagetool/rules/spelling/morfologik/MorfologikSpellerRule.java
2012-12-21 20:14:29 UTC (rev 8619)
+++
trunk/JLanguageTool/src/main/java/org/languagetool/rules/spelling/morfologik/MorfologikSpellerRule.java
2012-12-21 22:58:18 UTC (rev 8620)
@@ -46,13 +46,12 @@
private final static String LANGUAGETOOL = "LanguageTool";
private Speller speller;
-
private Locale conversionLocale = Locale.getDefault();
/**
* Get the filename, e.g., <tt>/resource/pl/spelling.dict</tt>.
*/
- public abstract String getFileName();
+ public abstract String getFileName();
public MorfologikSpellerRule(ResourceBundle messages, Language language)
throws IOException {
super(messages, language);
@@ -70,7 +69,7 @@
public void setLocale(Locale locale) {
conversionLocale = locale;
- }
+ }
@Override
public RuleMatch[] match(AnalyzedSentence text) throws IOException {
@@ -112,32 +111,18 @@
}
}
}
- }
+ }
return toRuleMatchArray(ruleMatches);
}
private List<RuleMatch> getRuleMatch(final String word, final int
startPos) throws CharacterCodingException {
- boolean isAlphabetic = true;
final List<RuleMatch> ruleMatches = new ArrayList<RuleMatch>();
- if (word.length() == 1) { // dictionaries usually do not contain
punctuation
- isAlphabetic = StringTools.isAlphabetic(word.charAt(0));
- }
- if (word.length() > 0 && isAlphabetic
- && !containsDigit(word)
- && !LANGUAGETOOL.equals(word)
- && !speller.isInDictionary(word)
- &&
!speller.isInDictionary(word.toLowerCase(conversionLocale))) {
- final List<String> suggestions = new ArrayList<String>();
- suggestions.addAll(speller.findReplacements(word));
- if (!word.toLowerCase(conversionLocale).equals(word)) {
-
suggestions.addAll(speller.findReplacements(word.toLowerCase(conversionLocale)));
- }
- suggestions.addAll(speller.replaceRunOnWords(word));
-
- final RuleMatch ruleMatch = new RuleMatch(this,
+ if (isMisspelled(word)) {
+ final RuleMatch ruleMatch = new RuleMatch(this,
startPos, startPos + word.length(),
messages.getString("spelling"),
messages.getString("desc_spelling_short"));
+ final List<String> suggestions = getSuggestions(word);
if (!suggestions.isEmpty()) {
ruleMatch.setSuggestedReplacements(suggestions);
}
@@ -145,7 +130,19 @@
}
return ruleMatches;
}
-
+
+ private boolean isMisspelled(String word) {
+ boolean isAlphabetic = true;
+ if (word.length() == 1) { // dictionaries usually do not contain
punctuation
+ isAlphabetic = StringTools.isAlphabetic(word.charAt(0));
+ }
+ return word.length() > 0 && isAlphabetic
+ && !containsDigit(word)
+ && !LANGUAGETOOL.equals(word)
+ && !speller.isInDictionary(word)
+ && !speller.isInDictionary(word.toLowerCase(conversionLocale));
+ }
+
private boolean containsDigit(final String s) {
for (int k = 0; k < s.length(); k++) {
if (Character.isDigit(s.charAt(k))) {
@@ -154,7 +151,17 @@
}
return false;
}
-
+
+ private List<String> getSuggestions(String word) throws
CharacterCodingException {
+ final List<String> suggestions = new ArrayList<String>();
+ suggestions.addAll(speller.findReplacements(word));
+ if (!word.toLowerCase(conversionLocale).equals(word)) {
+
suggestions.addAll(speller.findReplacements(word.toLowerCase(conversionLocale)));
+ }
+ suggestions.addAll(speller.replaceRunOnWords(word));
+ return suggestions;
+ }
+
/**
* Get the regular expression pattern used to tokenize
* the words as in the source dictionary. For example,
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
Languagetool-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/languagetool-commits