Revision: 7265
http://languagetool.svn.sourceforge.net/languagetool/?rev=7265&view=rev
Author: dnaber
Date: 2012-06-06 17:36:49 +0000 (Wed, 06 Jun 2012)
Log Message:
-----------
small code cleanups; using the author's name as copyright holder; use lowercase
filename for consistency
Modified Paths:
--------------
trunk/JLanguageTool/src/java/org/languagetool/rules/WrongWordInContextRule.java
trunk/JLanguageTool/src/java/org/languagetool/rules/de/GermanWrongWordInContextRule.java
trunk/JLanguageTool/src/test/org/languagetool/rules/de/GermanWrongWordInContextRuleTest.java
Added Paths:
-----------
trunk/JLanguageTool/src/rules/de/wrongWordInContext.txt
Removed Paths:
-------------
trunk/JLanguageTool/src/rules/de/WrongWordInContext.txt
Modified:
trunk/JLanguageTool/src/java/org/languagetool/rules/WrongWordInContextRule.java
===================================================================
---
trunk/JLanguageTool/src/java/org/languagetool/rules/WrongWordInContextRule.java
2012-06-06 17:25:41 UTC (rev 7264)
+++
trunk/JLanguageTool/src/java/org/languagetool/rules/WrongWordInContextRule.java
2012-06-06 17:36:49 UTC (rev 7265)
@@ -1,5 +1,5 @@
/* LanguageTool, a natural language style checker
- * Copyright (C) 2005 Daniel Naber (http://www.danielnaber.de)
+ * Copyright (C) 2012 Markus Brenneis
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -39,20 +39,18 @@
*/
public abstract class WrongWordInContextRule extends Rule {
- private final String filename;
-
private final List<ContextWords> contextWordsSet;
-
+
public WrongWordInContextRule(final ResourceBundle messages) throws
IOException {
if (messages != null) {
super.setCategory(new Category(getCategoryString()));
}
- filename = getFilename();
+ final String filename = getFilename();
contextWordsSet =
loadContextWords(JLanguageTool.getDataBroker().getFromRulesDirAsStream(filename));
}
-
+
protected abstract String getFilename();
-
+
protected String getCategoryString() {
return messages.getString("category_misc");
}
@@ -72,8 +70,8 @@
final List<RuleMatch> ruleMatches = new ArrayList<RuleMatch>();
final AnalyzedTokenReadings[] tokens = text.getTokensWithoutWhitespace();
for (ContextWords contextWords: contextWordsSet) {
- boolean matchedWord[] = {false, false};
- Matcher matchers[] = {null, null};
+ final boolean[] matchedWord = {false, false};
+ final Matcher[] matchers = {null, null};
matchers[0] = contextWords.words[0].matcher("");
matchers[1] = contextWords.words[1].matcher("");
//start searching for words
@@ -114,7 +112,7 @@
}
if(foundWord != -1) {
- boolean matchedContext[] = {false, false};
+ final boolean[] matchedContext = {false, false};
matchers[foundWord] = contextWords.contexts[foundWord].matcher("");
matchers[notFoundWord] =
contextWords.contexts[notFoundWord].matcher("");
//start searching for context words
@@ -129,8 +127,9 @@
matchedContext[notFoundWord] =
matchers[notFoundWord].reset(token).find();
}
if(matchedContext[notFoundWord] && !matchedContext[foundWord]) {
- String msg = getMessage(matchedToken,
matchedToken.replaceFirst(contextWords.matches[foundWord],contextWords.matches[notFoundWord]),
contextWords.explanations[notFoundWord], contextWords.explanations[foundWord]);
- String shortMsg =
getShortMessage(matchedToken.replaceFirst(contextWords.matches[foundWord],contextWords.matches[notFoundWord]));
+ final String msg = getMessage(matchedToken,
matchedToken.replaceFirst(contextWords.matches[foundWord],contextWords.matches[notFoundWord]),
+ contextWords.explanations[notFoundWord],
contextWords.explanations[foundWord]);
+ final String shortMsg =
getShortMessage(matchedToken.replaceFirst(contextWords.matches[foundWord],contextWords.matches[notFoundWord]));
final RuleMatch ruleMatch = new RuleMatch(this, startPos, endPos,
msg, shortMsg);
ruleMatches.add(ruleMatch);
}
@@ -150,7 +149,8 @@
protected abstract String getShortMessageString();
/**
- * @return a string like "Possible confusion of words: Did you mean
<suggestion>$SUGGESTION</suggestion> (= $EXPLANATION_SUGGESTION) instead of
'$WRONGWORD' (= $EXPLANATION_WRONGWORD)?"
+ * @return a string like "Possible confusion of words: Did you mean
<suggestion>$SUGGESTION</suggestion>
+ * (= $EXPLANATION_SUGGESTION) instead of '$WRONGWORD' (=
$EXPLANATION_WRONGWORD)?"
*/
protected abstract String getLongMessageString();
@@ -158,7 +158,8 @@
if (explanationSuggestion.equals("") || explanationWrongWord.equals("")) {
return getMessageString().replaceFirst("\\$SUGGESTION",
suggestion).replaceFirst("\\$WRONGWORD", wrongWord);
} else {
- return getLongMessageString().replaceFirst("\\$SUGGESTION",
suggestion).replaceFirst("\\$WRONGWORD",
wrongWord).replaceFirst("\\$EXPLANATION_SUGGESTION",
explanationSuggestion).replaceFirst("\\$EXPLANATION_WRONGWORD",
explanationWrongWord);
+ return getLongMessageString().replaceFirst("\\$SUGGESTION",
suggestion).replaceFirst("\\$WRONGWORD", wrongWord)
+ .replaceFirst("\\$EXPLANATION_SUGGESTION",
explanationSuggestion).replaceFirst("\\$EXPLANATION_WRONGWORD",
explanationWrongWord);
}
}
@@ -178,9 +179,9 @@
if (line.charAt(0) == '#') {
continue;
}
- String[] column = line.split("\t");
+ final String[] column = line.split("\t");
if (column.length >= 6) {
- ContextWords contextWords = new ContextWords();
+ final ContextWords contextWords = new ContextWords();
contextWords.setWord(0, column[0]);
contextWords.setWord(1, column[1]);
contextWords.matches[0] = column[2];
Modified:
trunk/JLanguageTool/src/java/org/languagetool/rules/de/GermanWrongWordInContextRule.java
===================================================================
---
trunk/JLanguageTool/src/java/org/languagetool/rules/de/GermanWrongWordInContextRule.java
2012-06-06 17:25:41 UTC (rev 7264)
+++
trunk/JLanguageTool/src/java/org/languagetool/rules/de/GermanWrongWordInContextRule.java
2012-06-06 17:36:49 UTC (rev 7265)
@@ -1,5 +1,5 @@
/* LanguageTool, a natural language style checker
- * Copyright (C) 2005 Daniel Naber (http://www.danielnaber.de)
+ * Copyright (C) 2012 Markus Brenneis
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -18,7 +18,6 @@
*/
package org.languagetool.rules.de;
-import org.languagetool.Language;
import org.languagetool.rules.WrongWordInContextRule;
import java.io.IOException;
@@ -47,7 +46,7 @@
@Override
protected String getFilename() {
- return "/de/WrongWordInContext.txt";
+ return "/de/wrongWordInContext.txt";
}
@Override
Deleted: trunk/JLanguageTool/src/rules/de/WrongWordInContext.txt
===================================================================
--- trunk/JLanguageTool/src/rules/de/WrongWordInContext.txt 2012-06-06
17:25:41 UTC (rev 7264)
+++ trunk/JLanguageTool/src/rules/de/WrongWordInContext.txt 2012-06-06
17:36:49 UTC (rev 7265)
@@ -1,10 +0,0 @@
-#word1 word2 match1 match2 context1 context2 [explanation1
explanation2]
-#do not forget to add tests to GermanWrongWordInContextRuleTest.java
-# Lid/Lied
-Lid(e(rn?)?)? Lied(e(rn?)?)? id ied
Auge.*|entzünde.*|.*röt(e|lich).*|.*zuck.*|.*geschlossen.*|gesenkt.*|zusammengekniffen.*|zusammenkneif.+
Melodie.*|Note.*|sing.*|sang.*|gesungen.*|komponi.+|Musik|Strophen?|Balladen?|Gesang.*|Gesängen?|Arien?|Opern?
Augenlid gesungenes Musikstück
-# malen/mahlen
-(?i)(aus|ge)?mal(ene?n?|t?) (?i)(aus|ge)?mahl(ene?n?|t?) mal mahl
(?i).*Farbe|.*Bild|.*Porträt|Kunst.*|Malern?
Zahn|Mühle|Korn|Weizen|Roggen|Hafer|Dinkel|Getreide|.*Mehl|Müller mit
Farbe ein Bild erstellen in einer Mühle zerkleinern
-# Mine/Miene
-Minen? Mienen? in ien
(?i)explodier.*|unterirdisch.*|Kugelschreiber|.*stift|Explosion.*|.*stürzen|.*spreng.*|.*gestürzt
verzieh(en|t)|verzogen|auf(zu)?setzen|setze.*|setzt|gekränkt.*|unbewegt.*
unterirdischer Gang, Sprengkörper, Kugelschreibermine Gesichtsausdruck
-# Saite/Seite
-Saiten? Seiten? ait eit
(?i)aufzieh.*|aufgezogen.*|.*Bass(es)?|.*Bratsche|.*Cellos?|.*Harfen?|.*Geigen?|.*Gitarren?|.*Violas?|.*Violinen?|Klavier
.*Buch|.*Lektüre|umblätter\w\w?|umgeblättert|umzublättern|(ge)?lesen|las(en)?|geschrieben|schreiben?
Saite eines Musikinstruments [auch im übertragenen Sinn] Buchseite
Copied: trunk/JLanguageTool/src/rules/de/wrongWordInContext.txt (from rev 7262,
trunk/JLanguageTool/src/rules/de/WrongWordInContext.txt)
===================================================================
--- trunk/JLanguageTool/src/rules/de/wrongWordInContext.txt
(rev 0)
+++ trunk/JLanguageTool/src/rules/de/wrongWordInContext.txt 2012-06-06
17:36:49 UTC (rev 7265)
@@ -0,0 +1,10 @@
+#word1 word2 match1 match2 context1 context2 [explanation1
explanation2]
+#do not forget to add tests to GermanWrongWordInContextRuleTest.java
+# Lid/Lied
+Lid(e(rn?)?)? Lied(e(rn?)?)? id ied
Auge.*|entzünde.*|.*röt(e|lich).*|.*zuck.*|.*geschlossen.*|gesenkt.*|zusammengekniffen.*|zusammenkneif.+
Melodie.*|Note.*|sing.*|sang.*|gesungen.*|komponi.+|Musik|Strophen?|Balladen?|Gesang.*|Gesängen?|Arien?|Opern?
Augenlid gesungenes Musikstück
+# malen/mahlen
+(?i)(aus|ge)?mal(ene?n?|t?) (?i)(aus|ge)?mahl(ene?n?|t?) mal mahl
(?i).*Farbe|.*Bild|.*Porträt|Kunst.*|Malern?
Zahn|Mühle|Korn|Weizen|Roggen|Hafer|Dinkel|Getreide|.*Mehl|Müller mit
Farbe ein Bild erstellen in einer Mühle zerkleinern
+# Mine/Miene
+Minen? Mienen? in ien
(?i)explodier.*|unterirdisch.*|Kugelschreiber|.*stift|Explosion.*|.*stürzen|.*spreng.*|.*gestürzt
verzieh(en|t)|verzogen|auf(zu)?setzen|setze.*|setzt|gekränkt.*|unbewegt.*
unterirdischer Gang, Sprengkörper, Kugelschreibermine Gesichtsausdruck
+# Saite/Seite
+Saiten? Seiten? ait eit
(?i)aufzieh.*|aufgezogen.*|.*Bass(es)?|.*Bratsche|.*Cellos?|.*Harfen?|.*Geigen?|.*Gitarren?|.*Violas?|.*Violinen?|Klavier
.*Buch|.*Lektüre|umblätter\w\w?|umgeblättert|umzublättern|(ge)?lesen|las(en)?|geschrieben|schreiben?
Saite eines Musikinstruments [auch im übertragenen Sinn] Buchseite
Modified:
trunk/JLanguageTool/src/test/org/languagetool/rules/de/GermanWrongWordInContextRuleTest.java
===================================================================
---
trunk/JLanguageTool/src/test/org/languagetool/rules/de/GermanWrongWordInContextRuleTest.java
2012-06-06 17:25:41 UTC (rev 7264)
+++
trunk/JLanguageTool/src/test/org/languagetool/rules/de/GermanWrongWordInContextRuleTest.java
2012-06-06 17:36:49 UTC (rev 7265)
@@ -1,5 +1,5 @@
/* LanguageTool, a natural language style checker
- * Copyright (C) 2005 Daniel Naber (http://www.danielnaber.de)
+ * Copyright (C) 2012 Markus Brenneis
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -41,6 +41,7 @@
assertEquals(11, rule.match(langTool.getAnalyzedSentence("Ihre Lieder sind
entzündet."))[0].getToPos());
assertEquals("Lider", rule.match(langTool.getAnalyzedSentence("Er hat
entzündete Lieder."))[0].getSuggestedReplacements().get(0));
assertEquals("Lieder", rule.match(langTool.getAnalyzedSentence("Wir singen
gemeinsam Lider."))[0].getSuggestedReplacements().get(0));
+
// malen/mahlen
assertEquals(0, rule.match(langTool.getAnalyzedSentence("Ich soll Bilder
einer Mühle malen.")).length);
assertEquals(0, rule.match(langTool.getAnalyzedSentence("Ich male ein Bild
einer Mühle.")).length);
@@ -56,6 +57,7 @@
assertEquals(1, rule.match(langTool.getAnalyzedSentence("Er hat ein
schönes Selbstporträt gemahlt.")).length);
assertEquals("gemahlen", rule.match(langTool.getAnalyzedSentence("Das Korn
wird in den Mühlen gemalen."))[0].getSuggestedReplacements().get(0));
assertEquals("malten", rule.match(langTool.getAnalyzedSentence("Wir
mahlten im Kunstunterricht."))[0].getSuggestedReplacements().get(0));
+
// Mine/Miene
assertEquals(0, rule.match(langTool.getAnalyzedSentence("Er verzieht keine
Miene.")).length);
assertEquals(0, rule.match(langTool.getAnalyzedSentence("Die Explosion der
Mine.")).length);
@@ -72,6 +74,7 @@
assertEquals(1, rule.match(langTool.getAnalyzedSentence("Die Miene des
Kugelschreibers ist leer.")).length);
assertEquals("Minen", rule.match(langTool.getAnalyzedSentence("Er hat das
mit den Mienen weggesprengt."))[0].getSuggestedReplacements().get(0));
assertEquals("Miene", rule.match(langTool.getAnalyzedSentence("Er
versucht, keine Mine zu verziehen."))[0].getSuggestedReplacements().get(0));
+
// Saite/Seite
assertEquals(0, rule.match(langTool.getAnalyzedSentence("Die Seiten des
Buches sind beschrieben.")).length);
assertEquals(0, rule.match(langTool.getAnalyzedSentence("Dieses Buch über
die Gitarre hat nur sechs Seiten.")).length);
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Languagetool-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/languagetool-cvs