Skip to content
This repository was archived by the owner on May 7, 2021. It is now read-only.

Commit 5e61626

Browse files
committed
Addressing the not-serializable issue
Addressing #12 („Classifier not serializable“)
1 parent f29c1af commit 5e61626

File tree

5 files changed

+38
-19
lines changed

5 files changed

+38
-19
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Then, treat it as any other dependency.
2626
<dependency>
2727
<groupId>com.github.ptnplanet</groupId>
2828
<artifactId>Java-Naive-Bayes-Classifier</artifactId>
29-
<version>1.0.6</version>
29+
<version>1.0.7</version>
3030
</dependency>
3131
```
3232

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.github.ptnplanet</groupId>
88
<artifactId>Java-Naive-Bayes-Classifier</artifactId>
9-
<version>1.0.6</version>
9+
<version>1.0.7</version>
1010

1111
<dependencies>
1212
<dependency>

src/main/java/de/daslaboratorium/machinelearning/classifier/Classification.java

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
package de.daslaboratorium.machinelearning.classifier;
22

3+
import java.io.Serializable;
34
import java.util.Collection;
45

56
/**
6-
* A basic wrapper reflecting a classification. It will store both featureset
7+
* A basic wrapper reflecting a classification. It will store both featureset
78
* and resulting classification.
89
*
910
* @author Philipp Nolte
1011
*
11-
* @param <T> The feature class.
12-
* @param <K> The category class.
12+
* @param <T>
13+
* The feature class.
14+
* @param <K>
15+
* The category class.
1316
*/
14-
public class Classification<T, K> {
17+
public class Classification<T, K> implements Serializable {
18+
19+
/**
20+
* Generated Serial Version UID (generated for v1.0.7).
21+
*/
22+
private static final long serialVersionUID = -1210981535415341283L;
1523

1624
/**
1725
* The classified featureset.
@@ -32,8 +40,10 @@ public class Classification<T, K> {
3240
* Constructs a new Classification with the parameters given and a default
3341
* probability of 1.
3442
*
35-
* @param featureset The featureset.
36-
* @param category The category.
43+
* @param featureset
44+
* The featureset.
45+
* @param category
46+
* The category.
3747
*/
3848
public Classification(Collection<T> featureset, K category) {
3949
this(featureset, category, 1.0f);
@@ -42,12 +52,14 @@ public Classification(Collection<T> featureset, K category) {
4252
/**
4353
* Constructs a new Classification with the parameters given.
4454
*
45-
* @param featureset The featureset.
46-
* @param category The category.
47-
* @param probability The probability.
55+
* @param featureset
56+
* The featureset.
57+
* @param category
58+
* The category.
59+
* @param probability
60+
* The probability.
4861
*/
49-
public Classification(Collection<T> featureset, K category,
50-
float probability) {
62+
public Classification(Collection<T> featureset, K category, float probability) {
5163
this.featureset = featureset;
5264
this.category = category;
5365
this.probability = probability;
@@ -64,6 +76,7 @@ public Collection<T> getFeatureset() {
6476

6577
/**
6678
* Retrieves the classification's probability.
79+
*
6780
* @return
6881
*/
6982
public float getProbability() {
@@ -84,10 +97,8 @@ public K getCategory() {
8497
*/
8598
@Override
8699
public String toString() {
87-
return "Classification [category=" + this.category
88-
+ ", probability=" + this.probability
89-
+ ", featureset=" + this.featureset
90-
+ "]";
100+
return "Classification [category=" + this.category + ", probability=" + this.probability + ", featureset="
101+
+ this.featureset + "]";
91102
}
92103

93104
}

src/main/java/de/daslaboratorium/machinelearning/classifier/Classifier.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
public abstract class Classifier<T, K> implements IFeatureProbability<T, K>, java.io.Serializable {
2525

2626
/**
27-
* Generated Serial Version UID (generated for v1.0.6).
27+
* Generated Serial Version UID (generated for v1.0.7).
2828
*/
2929
private static final long serialVersionUID = 5504911666956811966L;
3030

src/test/java/de/daslaboratorium/machinelearning/classifier/bayes/BayesClassifierTest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package de.daslaboratorium.machinelearning.classifier.bayes;
22

3+
import java.io.ByteArrayOutputStream;
4+
import java.io.IOException;
5+
import java.io.ObjectOutputStream;
36
import java.util.ArrayList;
47
import java.util.Arrays;
58
import java.util.Collection;
@@ -67,4 +70,9 @@ public void testStringClassificationInDetails() {
6770
Assert.assertEquals(0.0234375, list.get(1).getProbability(), EPSILON);
6871
}
6972

70-
}
73+
@Test
74+
public void testSerialization() throws IOException {
75+
76+
new ObjectOutputStream(new ByteArrayOutputStream()).writeObject(bayes);
77+
}
78+
}

0 commit comments

Comments
 (0)