/
SentenceWithManRule.java
103 lines (88 loc) · 3.19 KB
/
SentenceWithManRule.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/* LanguageTool, a natural language style checker
* Copyright (C) 2005 Daniel Naber (http://www.danielnaber.de)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
* USA
*/
package org.languagetool.rules.de;
import java.util.List;
import java.util.ResourceBundle;
import org.languagetool.AnalyzedTokenReadings;
import org.languagetool.Language;
import org.languagetool.UserConfig;
import org.languagetool.rules.AbstractStatisticSentenceStyleRule;
/**
* A rule that gives Hints about the use of German filler words.
* The Hints are only given when the percentage of filler words per chapter/text exceeds the given limit.
* A limit of 0 shows all used filler words. Direct speech or citation is excluded otherwise.
* This rule detects no grammar error but gives stylistic hints (default off).
* @author Fred Kruse
* @since 4.2
*/
public class SentenceWithManRule extends AbstractStatisticSentenceStyleRule {
private static final int DEFAULT_MIN_PERCENT = 15;
String sentenceMessage = null;
public SentenceWithManRule(ResourceBundle messages, Language lang, UserConfig userConfig) {
super(messages, lang, userConfig, DEFAULT_MIN_PERCENT);
}
/**
* Word is 'man'
*/
private static boolean isWordMan(AnalyzedTokenReadings token) {
return (token.hasLemma("man"));
}
/**
* Is sentence with verb man
*/
@Override
protected AnalyzedTokenReadings conditionFulfilled(List<AnalyzedTokenReadings> sentence) {
for (int i = 0; i < sentence.size(); i++) {
if(isWordMan(sentence.get(i))) {
return sentence.get(i);
}
}
return null;
}
@Override
protected boolean excludeDirectSpeech() {
return true;
}
/**
* Minimal value is given in per mil
*/
@Override
public double denominator() {
return 1000.0;
}
@Override
protected String getLimitMessage(int limit, double percent) {
if (limit == 0) {
return "Sätze mit der indirekten Leseransprache 'man' sind stilistisch wenig elegant formuliert. Lässt sich das Wort vermeiden?";
}
return "Mehr als " + limit + "‰ Sätze mit der indirekten Leseransprache 'man' {" + ((int) (percent +0.5d)) + "‰} gefunden. Lässt sich das Wort vermeiden?";
}
@Override
public String getId() {
return "SENTENCE_WITH_MAN_DE";
}
@Override
public String getDescription() {
return "Statistische Stilanalyse: Sätze mit indirekter Leseransprache 'man'";
}
@Override
public String getConfigureText() {
return "Anzeigen wenn mehr als ...‰ Sätze eines Kapitels 'man' enthalten:";
}
}