summaryrefslogtreecommitdiffstats
path: root/JLanguageTool/src/test/de/danielnaber/languagetool/rules/nb/EnglishUnpairedBracketsRuleTest.java
blob: c245b8008cb271b87b95f8f846f1e5480a791398 (plain)
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/* LanguageTool, a natural language style checker 
 * Copyright (C) 2010 Daniel Naber (http://www.languagetool.org)
 * 
 * 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 de.danielnaber.languagetool.rules.en;

import java.io.IOException;
import java.util.List;

import de.danielnaber.languagetool.JLanguageTool;
import de.danielnaber.languagetool.Language;
import de.danielnaber.languagetool.TestTools;
import de.danielnaber.languagetool.rules.RuleMatch;
import junit.framework.TestCase;

public class EnglishUnpairedBracketsRuleTest extends TestCase {

  public void testRule() throws IOException {
    EnglishUnpairedBracketsRule rule = new EnglishUnpairedBracketsRule(TestTools
        .getEnglishMessages(), Language.ENGLISH);
    RuleMatch[] matches;
    JLanguageTool langTool = new JLanguageTool(Language.ENGLISH);
    // correct sentences:
    matches = rule.match(langTool
        .getAnalyzedSentence("(This is a test sentence)."));
    assertEquals(0, matches.length);
    matches = rule
        .match(langTool.getAnalyzedSentence("This is a word 'test'."));
    assertEquals(0, matches.length);
    matches = rule.match(langTool
        .getAnalyzedSentence("This is the joint presidents' declaration."));
    assertEquals(0, matches.length);
    matches = rule.match(langTool
        .getAnalyzedSentence("The screen is 20\" wide."));
    assertEquals(0, matches.length);
    matches = rule.match(langTool
        .getAnalyzedSentence("This is a [test] sentence..."));
    assertEquals(0, matches.length);
    matches = rule
        .match(langTool
            .getAnalyzedSentence("The plight of Tamil refugees caused a surge of support from most of the Tamil political parties.[90]"));
    assertEquals(0, matches.length);
    matches = rule
        .match(langTool
            .getAnalyzedSentence("This is what he said: \"We believe in freedom. This is what we do.\""));
    assertEquals(0, matches.length);
    matches = rule.match(langTool.getAnalyzedSentence("(([20] [20] [20]))"));
    assertEquals(0, matches.length);
    // test for a case that created a false alarm after disambiguation
    matches = rule.match(langTool
        .getAnalyzedSentence("This is a \"special test\", right?"));
    assertEquals(0, matches.length);
    // numerical bullets
    matches = rule.match(langTool
        .getAnalyzedSentence("We discussed this in Chapter 1)."));
    assertEquals(0, matches.length);
    matches = rule.match(langTool
        .getAnalyzedSentence("The jury recommended that: (1) Four additional deputies be employed."));
    assertEquals(0, matches.length);
    matches = rule.match(langTool
        .getAnalyzedSentence("We discussed this in section 1a)."));
    assertEquals(0, matches.length);
    matches = rule.match(langTool
        .getAnalyzedSentence("We discussed this in section iv)."));
    assertEquals(0, matches.length);

    //inches exception shouldn't match " here:
    matches = rule.match(langTool
        .getAnalyzedSentence("In addition, the government would pay a $1,000 \"cost of education\" grant to the schools."));
    assertEquals(0, matches.length);

    matches = rule.match(langTool
        .getAnalyzedSentence("Paradise lost to the alleged water needs of Texas' big cities Thursday."));
    assertEquals(0, matches.length);

    matches = rule.match(langTool
        .getAnalyzedSentence("Kill 'em all!"));
    assertEquals(0, matches.length);

    matches = rule.match(langTool
        .getAnalyzedSentence("Puttin' on the Ritz"));
    assertEquals(0, matches.length);    
    
    // incorrect sentences:
    matches = rule.match(langTool
        .getAnalyzedSentence("(This is a test sentence."));
    assertEquals(1, matches.length);
    
    //tests for Edward's bug
    matches = rule.match(langTool
        .getAnalyzedSentence("This is a test with an apostrophe &'."));
    assertEquals(1, matches.length);
    matches = rule.match(langTool
        .getAnalyzedSentence("&'"));
    assertEquals(1, matches.length);
    matches = rule.match(langTool
        .getAnalyzedSentence("!'"));
    assertEquals(1, matches.length);
    matches = rule.match(langTool
        .getAnalyzedSentence("What?'"));
    assertEquals(1, matches.length);
    //
    matches = rule.match(langTool
        .getAnalyzedSentence("(This is a test” sentence."));
    assertEquals(2, matches.length);
    matches = rule.match(langTool
        .getAnalyzedSentence("This is a {test sentence."));
    assertEquals(1, matches.length);
    matches = rule.match(langTool
        .getAnalyzedSentence("This [is (a test} sentence."));
    assertEquals(3, matches.length);
  }

  public void testMultipleSentences() throws IOException {
    final JLanguageTool tool = new JLanguageTool(Language.ENGLISH);
    tool.enableRule("EN_UNPAIRED_BRACKETS");

    List<RuleMatch> matches;
    matches = tool
        .check("This is multiple sentence text that contains a bracket:"
            + "[This is bracket. With some text.] and this continues.\n");
    assertEquals(0, matches.size());
    matches = tool
        .check("This is multiple sentence text that contains a bracket:"
            + "[This is bracket. With some text. And this continues.\n\n");
    assertEquals(1, matches.size());
    // now with a paragraph end inside - we get two alarms because of paragraph
    // resetting
    matches = tool
        .check("This is multiple sentence text that contains a bracket. "
            + "(This is bracket. \n\n With some text.) and this continues.");
    assertEquals(2, matches.size());
  }

  
}