Skip to content

Commit

Permalink
[de] adresses problem described in #779
Browse files Browse the repository at this point in the history
  • Loading branch information
f-knorr committed Sep 9, 2017
1 parent 7e38a72 commit 7950b29
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.languagetool.rules;

import org.apache.commons.lang3.StringUtils;
import org.languagetool.AnalyzedSentence;
import org.languagetool.AnalyzedToken;
import org.languagetool.AnalyzedTokenReadings;
Expand Down Expand Up @@ -125,7 +126,7 @@ public RuleMatch[] match(AnalyzedSentence sentence) {
msg = withHyphenMessage;
}
if (isNotAllUppercase(origStringToCheck) && !getCompoundRuleData().getOnlyDashSuggestion().contains(stringToCheck)) {
replacement.add(mergeCompound(origStringToCheck));
replacement.add(mergeCompound(origStringToCheck, getCompoundRuleData().getNoDashIgnoreCaseSuggestion().stream().anyMatch(s -> origStringsToCheck.contains(s))));
msg = withoutHyphenMessage;
}
String[] parts = stringToCheck.split(" ");
Expand Down Expand Up @@ -199,15 +200,15 @@ private boolean isNotAllUppercase(String str) {
return true;
}

private String mergeCompound(String str) {
private String mergeCompound(String str, boolean uncapitalizeMidWords) {
String[] stringParts = str.split(" ");
StringBuilder sb = new StringBuilder();
for (int k = 0; k < stringParts.length; k++) {
if (isHyphenIgnored() || !"-".equals(stringParts[k])) {
if (k == 0) {
sb.append(stringParts[0]);
} else {
sb.append(stringParts[k]);
sb.append(uncapitalizeMidWords ? StringUtils.uncapitalize(stringParts[k]) : stringParts[k]);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
*/
package org.languagetool.rules;

import org.languagetool.JLanguageTool;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -28,6 +26,8 @@
import java.util.HashSet;
import java.util.Set;

import org.languagetool.JLanguageTool;

/**
* Data about words that are compounds and should thus not be written
* as separate words.
Expand All @@ -37,6 +37,7 @@ public class CompoundRuleData {

private final Set<String> incorrectCompounds = new HashSet<>();
private final Set<String> noDashSuggestion = new HashSet<>();
private final Set<String> noDashIgnoreCaseSuggestion = new HashSet<>();
private final Set<String> onlyDashSuggestion = new HashSet<>();

public CompoundRuleData(String path) {
Expand Down Expand Up @@ -65,6 +66,10 @@ Set<String> getOnlyDashSuggestion() {
return Collections.unmodifiableSet(onlyDashSuggestion);
}

Set<String> getNoDashIgnoreCaseSuggestion() {
return Collections.unmodifiableSet(noDashIgnoreCaseSuggestion);
}

private void loadCompoundFile(String path) throws IOException {
try (
InputStream stream = JLanguageTool.getDataBroker().getFromResourceDirAsStream(path);
Expand All @@ -84,6 +89,10 @@ private void loadCompoundFile(String path) throws IOException {
} else if (line.endsWith("*")) {
line = removeLastCharacter(line);
onlyDashSuggestion.add(line);
} else if (line.endsWith("?")) { // github issue #779
line = removeLastCharacter(line);
noDashSuggestion.add(line);
noDashIgnoreCaseSuggestion.add(line);
}
incorrectCompounds.add(line);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
# even if the word is usually not spelled with a hyphen or blank.
# "+" at the end of the line will turn off the suggestion that
# uses a hyphen.
# "?" at the end of the line will turn off the suggestion that
# uses a hyphen and offers lower-cased joined suggestions.
# "*" at the end of the line will only suggest hyphenated words.
# =========================================================================
# =========================================================================
Expand Down Expand Up @@ -302,7 +304,6 @@ Distanz-säule+
Domino-effekt+
Doppel-effekt+
Doppel-säule+
Doppler-effekt+
Dreh-effekt+
Dreh-säule+
Drogen-effekt+
Expand Down Expand Up @@ -1295,6 +1296,11 @@ Zusammen-spiels+
Zusatz-effekt+
zuteil-werden+
# =========================================================================
# "?" at end of line = no hyphen suggestion and join force lower case when
# joining words
# =========================================================================
Doppler-Effekt?
# =========================================================================
# The following part is based on the lists from http://tkltrans.sf.net
# This part is LGPL licensed, license text in http://www.fsf.org
# Owner: Lantol, email: lantol46_AT_nospam_DOT_yahoo_DOT_de
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public void testRule() throws IOException {
check(1, "Ein Start Ziel Sieg");
check(1, "Start Ziel Sieg");
check(1, "Start Ziel Sieg!");
check(1, "Doppler Effekt");
check(1, "Doppler effekt");
check(2, "Der dumme System Administrator legt die CD ROM");
check(2, "Der dumme System Administrator legt die CD ROM.");
check(2, "Der dumme System Administrator legt die CD ROM ein blah");
Expand Down

0 comments on commit 7950b29

Please sign in to comment.