Skip to content

Commit 000f06c

Browse files
committed
metafacture-statistics/ (main): Fix Checkstyle violations.
1 parent 54bd7a9 commit 000f06c

File tree

8 files changed

+48
-54
lines changed

8 files changed

+48
-54
lines changed

metafacture-statistics/src/main/java/org/metafacture/statistics/AbstractCountProcessor.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.metafacture.statistics;
1716

18-
import java.util.Hashtable;
19-
import java.util.Map;
20-
import java.util.regex.Pattern;
17+
package org.metafacture.statistics;
2118

2219
import org.metafacture.framework.ObjectReceiver;
2320
import org.metafacture.framework.helpers.DefaultObjectPipe;
2421
import org.metafacture.framework.objects.Triple;
2522

23+
import java.util.Hashtable;
24+
import java.util.Map;
25+
import java.util.regex.Pattern;
26+
2627
/**
2728
* Base class for operating on count data. The expected inputs are triples
2829
* containing as subject the variable name and as object the count. Marginal
@@ -33,7 +34,6 @@
3334
*/
3435
public abstract class AbstractCountProcessor extends DefaultObjectPipe<Triple, ObjectReceiver<Triple>> {
3536

36-
3737
private static final Pattern KEY_SPLIT_PATTERN = Pattern.compile("&", Pattern.LITERAL);
3838

3939
private static final String MARGINAL_PREFIX = "1:";
@@ -67,7 +67,8 @@ public final void process(final Triple triple) {
6767
marginals.put(triple.getSubject().substring(2), Integer.valueOf(marginal));
6868
}
6969

70-
} else {
70+
}
71+
else {
7172
inHeader = false;
7273
if (!triple.getSubject().startsWith(JOINT_PREFIX)) {
7374
throw new IllegalArgumentException("Joint counts must start with '2:'");
@@ -84,12 +85,11 @@ public final void process(final Triple triple) {
8485
}
8586
}
8687

87-
protected abstract void processCount(final String varA, final String varB, final int countA, final int countB,
88-
final int countAandB);
88+
protected abstract void processCount(String varA, String varB, int countA, int countB, int countAandB);
8989

9090
private int getMarginal(final String string) {
9191
final Integer value = marginals.get(string);
92-
if(null==value){
92+
if (null == value) {
9393
return 0;
9494
}
9595
return value.intValue();
@@ -104,7 +104,6 @@ protected final void onResetStream() {
104104

105105
protected void reset() {
106106
// nothing to do
107-
108107
}
109108

110109
@Override
@@ -115,7 +114,6 @@ protected final void onCloseStream() {
115114

116115
protected void close() {
117116
// nothing to do
118-
119117
}
120118

121119
}

metafacture-statistics/src/main/java/org/metafacture/statistics/CooccurrenceMetricCalculator.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,18 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.metafacture.statistics;
1716

18-
import java.util.ArrayList;
19-
import java.util.List;
17+
package org.metafacture.statistics;
2018

2119
import org.metafacture.framework.FluxCommand;
2220
import org.metafacture.framework.annotations.Description;
2321
import org.metafacture.framework.annotations.In;
2422
import org.metafacture.framework.annotations.Out;
2523
import org.metafacture.framework.objects.Triple;
2624

25+
import java.util.ArrayList;
26+
import java.util.List;
27+
2728
/**
2829
* Calculates values for various co-occurrence metrics. The expected inputs are
2930
* triples containing as subject the var name and as object the count. Marginal
@@ -32,8 +33,8 @@
3233
*
3334
* @author Markus Michael Geipel
3435
*/
35-
@Description("Calculates values for various cooccurrence metrics. The expected inputs are triples containing as subject the var name and as object the count. "
36-
+ "Marginal counts must appear first, joint counts second. Marinal counts must be written as 1:A, Joint counts as 2:A&B")
36+
@Description("Calculates values for various cooccurrence metrics. The expected inputs are triples containing as subject the var name and as object the count. " +
37+
"Marginal counts must appear first, joint counts second. Marinal counts must be written as 1:A, Joint counts as 2:A&B")
3738
@In(Triple.class)
3839
@Out(Triple.class)
3940
@FluxCommand("calculate-metrics")
@@ -51,8 +52,7 @@ enum Metric {
5152
final double o22 = total - countAandB;
5253
final double d = (countAandB * o22) - (o12 * o21);
5354

54-
final double x2 = total * Math.pow(d, 2)
55-
/ ((countAandB + o12) * (countAandB + o21) * (o12 + o22) * (o21 + o22));
55+
final double x2 = total * Math.pow(d, 2) / ((countAandB + o12) * (countAandB + o21) * (o12 + o22) * (o21 + o22));
5656
return x2 * Math.signum(d);
5757
}
5858
},
@@ -87,36 +87,34 @@ enum Metric {
8787
JACCARD {
8888
@Override
8989
double calculate(final int countA, final int countB, final int countAandB, final int total) {
90-
return countAandB / (double)(countA + countB - countAandB);
90+
return countAandB / (double) (countA + countB - countAandB);
9191
}
9292
};
9393

94-
abstract double calculate(final int countA, final int countB, final int countAandB, final int total);
94+
abstract double calculate(int countA, int countB, int countAandB, int total);
9595
}
9696

9797
private static final int MIN_COUNT = 5;
9898

9999
private final List<Metric> metrics = new ArrayList<Metric>();
100100

101101
public CooccurrenceMetricCalculator(final String allMetrics) {
102-
final String[] metrics = allMetrics.split("\\s*,\\s*");
103102
setMinCount(MIN_COUNT);
104-
for (String metric : metrics) {
105-
this.metrics.add(Metric.valueOf(metric));
103+
for (final String metric : allMetrics.split("\\s*,\\s*")) {
104+
metrics.add(Metric.valueOf(metric));
106105
}
107106
}
108107

109108
public CooccurrenceMetricCalculator(final Metric... metrics) {
110109
setMinCount(MIN_COUNT);
111-
for (Metric metric : metrics) {
110+
for (final Metric metric : metrics) {
112111
this.metrics.add(metric);
113112
}
114113
}
115114

116115
@Override
117-
protected void processCount(final String varA, final String varB, final int countA, final int countB,
118-
final int countAandB) {
119-
for (Metric metric : metrics) {
116+
protected void processCount(final String varA, final String varB, final int countA, final int countB, final int countAandB) {
117+
for (final Metric metric : metrics) {
120118
final double value = metric.calculate(countA, countB, countAandB, getTotal());
121119
getReceiver().process(new Triple(varA + "&" + varB, metric.toString(), String.valueOf(value)));
122120
}

metafacture-statistics/src/main/java/org/metafacture/statistics/Counter.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.metafacture.statistics;
1718

1819
import org.metafacture.framework.FluxCommand;
@@ -42,6 +43,9 @@ public final class Counter extends DefaultStreamPipe<StreamReceiver> {
4243
private int numEntities;
4344
private int numLiterals;
4445

46+
public Counter() {
47+
}
48+
4549
/**
4650
* @return the numRecords
4751
*/
@@ -67,7 +71,7 @@ public int getNumLiterals() {
6771
public void startRecord(final String identifier) {
6872
assert !isClosed();
6973
++numRecords;
70-
if(getReceiver() != null) {
74+
if (getReceiver() != null) {
7175
getReceiver().startRecord(identifier);
7276
}
7377
}
@@ -76,7 +80,7 @@ public void startRecord(final String identifier) {
7680
public void startEntity(final String name) {
7781
assert !isClosed();
7882
++numEntities;
79-
if(getReceiver() != null) {
83+
if (getReceiver() != null) {
8084
getReceiver().startEntity(name);
8185
}
8286
}
@@ -85,21 +89,21 @@ public void startEntity(final String name) {
8589
public void literal(final String name, final String value) {
8690
assert !isClosed();
8791
++numLiterals;
88-
if(getReceiver() != null) {
92+
if (getReceiver() != null) {
8993
getReceiver().literal(name, value);
9094
}
9195
}
9296

9397
@Override
9498
public void endRecord() {
95-
if(getReceiver() != null) {
99+
if (getReceiver() != null) {
96100
getReceiver().endRecord();
97101
}
98102
}
99103

100104
@Override
101105
public void endEntity() {
102-
if(getReceiver() != null) {
106+
if (getReceiver() != null) {
103107
getReceiver().endEntity();
104108
}
105109
}
@@ -113,11 +117,7 @@ public void onResetStream() {
113117

114118
@Override
115119
public String toString() {
116-
String streamClosed = "";
117-
if (isClosed()) {
118-
streamClosed =" Stream has been closed.";
119-
}
120-
120+
final String streamClosed = isClosed() ? " Stream has been closed." : "";
121121
return "counted " + numRecords + " records, " + numEntities + " entities, " + numLiterals + " literals." + streamClosed;
122122
}
123123
}

metafacture-statistics/src/main/java/org/metafacture/statistics/Histogram.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.metafacture.statistics;
1718

19+
import org.metafacture.framework.helpers.DefaultStreamReceiver;
20+
1821
import java.util.Collections;
1922
import java.util.HashMap;
2023
import java.util.Map;
2124

22-
import org.metafacture.framework.helpers.DefaultStreamReceiver;
23-
24-
2525
/**
2626
* Counts entity names, literal names, or literal values.
2727
*
@@ -36,7 +36,6 @@ public final class Histogram extends DefaultStreamReceiver {
3636
private String countField;
3737

3838
public Histogram() {
39-
super();
4039
}
4140

4241
/**
@@ -45,7 +44,6 @@ public Histogram() {
4544
* @param countField name of the field whose content is counted
4645
*/
4746
public Histogram(final String countField) {
48-
super();
4947
setCountField(countField);
5048
}
5149

metafacture-statistics/src/main/java/org/metafacture/statistics/UniformSampler.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,8 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.metafacture.statistics;
1716

18-
import java.util.ArrayList;
19-
import java.util.List;
20-
import java.util.Random;
17+
package org.metafacture.statistics;
2118

2219
import org.metafacture.framework.FluxCommand;
2320
import org.metafacture.framework.ObjectReceiver;
@@ -26,6 +23,9 @@
2623
import org.metafacture.framework.annotations.Out;
2724
import org.metafacture.framework.helpers.DefaultObjectPipe;
2825

26+
import java.util.ArrayList;
27+
import java.util.List;
28+
import java.util.Random;
2929

3030
/**
3131
* Draws a uniform sample of records from the input stream.
@@ -50,35 +50,32 @@ public final class UniformSampler<T> extends
5050
private long count;
5151

5252
public UniformSampler(final int sampleSize) {
53-
super();
5453
this.sampleSize = sampleSize;
5554
sample = new ArrayList<T>(sampleSize);
5655
}
5756

58-
5957
public UniformSampler(final String sampleSize) {
6058
this(Integer.parseInt(sampleSize));
6159
}
6260

63-
6461
public int getSampleSize() {
6562
return sampleSize;
6663
}
6764

68-
6965
public void setSeed(final long seed) {
7066
random.setSeed(seed);
7167
}
7268

7369
@Override
7470
public void process(final T obj) {
7571
assert !isClosed();
76-
assert null!=obj;
72+
assert null != obj;
7773
count += 1;
7874
if (sample.size() < sampleSize) {
7975
sample.add(obj);
80-
} else {
81-
final double p = sampleSize / (double)count;
76+
}
77+
else {
78+
final double p = sampleSize / (double) count;
8279
if (random.nextDouble() < p) {
8380
sample.set(random.nextInt(sampleSize), obj);
8481
}
@@ -87,7 +84,7 @@ public void process(final T obj) {
8784

8885
@Override
8986
protected void onCloseStream() {
90-
for(T obj : sample) {
87+
for (final T obj : sample) {
9188
getReceiver().process(obj);
9289
}
9390
sample.clear();

metafacture-statistics/src/test/java/org/metafacture/statistics/CooccurrenceMetricCalculatorTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.metafacture.statistics;
1718

1819
import static org.junit.Assert.assertEquals;

metafacture-statistics/src/test/java/org/metafacture/statistics/HistogramTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.metafacture.statistics;
1718

1819
import static org.junit.Assert.assertEquals;

metafacture-statistics/src/test/java/org/metafacture/statistics/UniformSamplerTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.metafacture.statistics;
1718

1819
import static org.mockito.Mockito.inOrder;

0 commit comments

Comments
 (0)