Skip to content

Commit

Permalink
[nl] improve CheckCaseRule
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-baas committed Oct 27, 2023
1 parent 7172614 commit 2d79dce
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*/
public abstract class AbstractCheckCaseRule extends AbstractSimpleReplaceRule2 {
private final Language language;
public boolean ignoreShortUppercaseWords = true;
private boolean ignoreShortUppercaseWords = true;

public AbstractCheckCaseRule(ResourceBundle messages, Language language) {
super(messages, language);
Expand Down Expand Up @@ -96,17 +96,16 @@ public RuleMatch[] match(AnalyzedSentence sentence) {
// The phrase is correct. Don't look into shorter phrases inside this phrase.
break;
}
if (ignoreShortUppercaseWords) {
if (originalPhrase.equals(originalPhrase.toUpperCase())) {
// Toggle is ON and it's a capitalized sentence, continue
if (originalPhrase.equals(originalPhrase.toUpperCase())) {
if (ignoreShortUppercaseWords) {
continue;
} else {
if( originalPhrase.length() < 5 ){
// correct uppercase word less than 5 chars if toggle is on
} else{
continue;
}
}
} else if (originalPhrase.length() < 5) {
//System.out.println("toggle off, <5 chars");
// Toggle OFF and <5 chars
} else {
//toggle OFF but >5 chars
continue;
}
if (correctPhrase != null && !correctPhrase.equals(originalPhrase)) {
RuleMatch ruleMatch;
Expand Down Expand Up @@ -141,7 +140,7 @@ public RuleMatch[] match(AnalyzedSentence sentence) {
return toRuleMatchArray(ruleMatches);
}

public boolean ignoreShortUppercaseWords() {
public boolean isIgnoreShortUppercaseWords() {
return ignoreShortUppercaseWords;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class CheckCaseRule extends AbstractCheckCaseRule {
public CheckCaseRule(ResourceBundle messages, Language language) {
super(messages, language);
useSubRuleSpecificIds();
// do not ignore abbreviations like "apk, dvd" etc
setIgnoreShortUppercaseWords(false);
}

@Override
Expand Down Expand Up @@ -66,10 +68,4 @@ public Locale getLocale() {
return NL_LOCALE;
}

@Override
public boolean ignoreShortUppercaseWords() {
//does not override boolean
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public void testRule() throws IOException {
assertEquals(0, rule.match(lt.getAnalyzedSentence("een bisschop")).length);
assertEquals(0, rule.match(lt.getAnalyzedSentence("Een bisschop")).length);

// ignored sentence:
assertEquals(0, rule.match(lt.getAnalyzedSentence("EEN BISSCHOP")).length);

// incorrect sentences:
RuleMatch[] matches = rule.match(lt.getAnalyzedSentence("Een Bisschop"));
assertEquals(1, matches.length);
Expand All @@ -55,9 +58,14 @@ public void testRule() throws IOException {
assertEquals(1, matches.length);
assertEquals("een bisschop", matches[0].getSuggestedReplacements().get(0));

matches = rule.match(lt.getAnalyzedSentence("Dit is een video op dVD."));
// less than 5chars:
matches = rule.match(lt.getAnalyzedSentence("Mag ik die DVD lenen?"));
assertEquals(1, matches.length);
assertEquals("dvd", matches[0].getSuggestedReplacements().get(0));

matches = rule.match(lt.getAnalyzedSentence("Heb je de nieuwe IPAD al gezien?"));
assertEquals(1, matches.length);
assertEquals("iPad", matches[0].getSuggestedReplacements().get(0));

}
}

0 comments on commit 2d79dce

Please sign in to comment.