Skip to content

Commit

Permalink
NoJira: Fix the codestyle violations in NameSampleTypeFilterTest, set…
Browse files Browse the repository at this point in the history
… severity to 'error' for indent violations; closes apache#175
  • Loading branch information
smarthi committed Apr 20, 2017
1 parent 8fb1341 commit 041507d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 62 deletions.
2 changes: 1 addition & 1 deletion checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
<property name="throwsIndent" value="4"/>
<property name="lineWrappingIndentation" value="4"/>
<property name="arrayInitIndent" value="2"/>
<property name="severity" value="warning"/>
<property name="severity" value="error"/>
</module>
<module name="EmptyCatchBlock">
<property name="exceptionVariableName" value="expected|ignore"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand Down Expand Up @@ -35,68 +35,68 @@

public class NameSampleTypeFilterTest {

private static NameSampleTypeFilter filter;
private static NameSampleTypeFilter filter;

private static final String text = "<START:organization> NATO <END> Secretary - General " +
"<START:person> Anders Fogh Rasmussen <END> made clear that despite an intensifying " +
"insurgency and uncertainty over whether <START:location> U . S . <END> President " +
"<START:person> Barack Obama <END> will send more troops , <START:location> NATO <END> " +
"will remain in <START:location> Afghanistan <END> .";
private static final String text = "<START:organization> NATO <END> Secretary - General " +
"<START:person> Anders Fogh Rasmussen <END> made clear that despite an intensifying " +
"insurgency and uncertainty over whether <START:location> U . S . <END> President " +
"<START:person> Barack Obama <END> will send more troops , <START:location> NATO <END> " +
"will remain in <START:location> Afghanistan <END> .";

private static final String person = "person";
private static final String organization = "organization";
private static final String person = "person";
private static final String organization = "organization";

@Test
public void testNoFilter() throws IOException {
@Test
public void testNoFilter() throws IOException {

final String[] types = new String[] {};
final String[] types = new String[] {};

filter = new NameSampleTypeFilter(types, sampleStream(text));
filter = new NameSampleTypeFilter(types, sampleStream(text));

NameSample ns = filter.read();
NameSample ns = filter.read();

Assert.assertEquals(0, ns.getNames().length);
Assert.assertEquals(0, ns.getNames().length);

}
}

@Test
public void testSingleFilter() throws IOException {
@Test
public void testSingleFilter() throws IOException {

final String[] types = new String[] {organization};
final String[] types = new String[] {organization};

filter = new NameSampleTypeFilter(types, sampleStream(text));
filter = new NameSampleTypeFilter(types, sampleStream(text));

NameSample ns = filter.read();
NameSample ns = filter.read();

Assert.assertEquals(1, ns.getNames().length);
Assert.assertEquals(organization, ns.getNames()[0].getType());
Assert.assertEquals(1, ns.getNames().length);
Assert.assertEquals(organization, ns.getNames()[0].getType());

}
}

@Test
public void testMultiFilter() throws IOException {
@Test
public void testMultiFilter() throws IOException {

final String[] types = new String[] {person, organization};
final String[] types = new String[] {person, organization};

filter = new NameSampleTypeFilter(types, sampleStream(text));
filter = new NameSampleTypeFilter(types, sampleStream(text));

NameSample ns = filter.read();
NameSample ns = filter.read();

Map<String, List<Span>> collect = Arrays.stream(ns.getNames())
.collect(Collectors.groupingBy(Span::getType));
Assert.assertEquals(2, collect.size());
Assert.assertEquals(2, collect.get(person).size());
Assert.assertEquals(1, collect.get(organization).size());
Map<String, List<Span>> collect = Arrays.stream(ns.getNames())
.collect(Collectors.groupingBy(Span::getType));
Assert.assertEquals(2, collect.size());
Assert.assertEquals(2, collect.get(person).size());
Assert.assertEquals(1, collect.get(organization).size());

}
}

private ObjectStream<NameSample> sampleStream(String sampleText) throws IOException {
private ObjectStream<NameSample> sampleStream(String sampleText) throws IOException {

InputStreamFactory in = () -> new ByteArrayInputStream(sampleText.getBytes(StandardCharsets.UTF_8));
InputStreamFactory in = () -> new ByteArrayInputStream(sampleText.getBytes(StandardCharsets.UTF_8));

return new NameSampleDataStream(
new PlainTextByLineStream(in, StandardCharsets.UTF_8));
return new NameSampleDataStream(
new PlainTextByLineStream(in, StandardCharsets.UTF_8));

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,11 @@ public void testConstructors() throws Exception {
new TrainingParameters(build("key1=val1,key2=val2,key3=val3"));

TrainingParameters tp2 = new TrainingParameters(
new ByteArrayInputStream("key1=val1\nkey2=val2\nkey3=val3\n".getBytes())
new ByteArrayInputStream("key1=val1\nkey2=val2\nkey3=val3\n".getBytes())
);

TrainingParameters tp3 = new TrainingParameters(tp2);

/*
Assert.assertEquals(3, tp1.getSettings().size());
Assert.assertEquals(3, tp3.getSettings().size());
Assert.assertEquals(tp1.getStringParameter("key1", "v11"),
tp3.getStringParameter("key1", "v22")); // use different defaults
Assert.assertEquals(tp1.getStringParameter("key2", "v11"),
tp3.getStringParameter("key2", "v22")); // use different defaults
Assert.assertEquals(tp1.getStringParameter("key2", "v11"),
tp3.getStringParameter("key2", "v22")); // use different defaults
*/
assertEquals(tp1, tp2);
assertEquals(tp2, tp3);
}
Expand All @@ -60,14 +50,14 @@ public void testDefault() {
Assert.assertEquals(4, tr.getSettings().size());
Assert.assertEquals("MAXENT", tr.algorithm());
Assert.assertEquals(EventTrainer.EVENT_VALUE,
tr.getStringParameter(TrainingParameters.TRAINER_TYPE_PARAM,
"v11")); // use different defaults
tr.getStringParameter(TrainingParameters.TRAINER_TYPE_PARAM,
"v11")); // use different defaults
Assert.assertEquals(100,
tr.getIntParameter(TrainingParameters.ITERATIONS_PARAM,
200)); // use different defaults
tr.getIntParameter(TrainingParameters.ITERATIONS_PARAM,
200)); // use different defaults
Assert.assertEquals(5,
tr.getIntParameter(TrainingParameters.CUTOFF_PARAM,
200)); // use different defaults
tr.getIntParameter(TrainingParameters.CUTOFF_PARAM,
200)); // use different defaults
}

@Test
Expand Down Expand Up @@ -131,7 +121,7 @@ public void testPutGet() {
private static Map<String, String> buildMap(String str) {
String[] pairs = str.split(",");
Map<String, String> map = new HashMap<>(pairs.length);
for (String pair: pairs) {
for (String pair : pairs) {
String[] keyValue = pair.split("=");
map.put(keyValue[0], keyValue[1]);
}
Expand All @@ -148,7 +138,7 @@ private static void assertEquals(Map<String, String> map1, Map<String, String> m
Assert.assertNotNull(map1);
Assert.assertNotNull(map2);
Assert.assertEquals(map1.size(), map2.size());
for (String key: map1.keySet()) {
for (String key : map1.keySet()) {
Assert.assertEquals(map1.get(key), map2.get(key));
}
}
Expand All @@ -161,8 +151,7 @@ private static void assertEquals(Map<String, String> map, TrainingParameters act
private static void assertEquals(TrainingParameters expected, TrainingParameters actual) {
if (expected == null) {
Assert.assertNull(actual);
}
else {
} else {
assertEquals(expected.getSettings(), actual);
}
}
Expand Down

0 comments on commit 041507d

Please sign in to comment.