Skip to content

Commit f4e170c

Browse files
committed
Add encode methods.
1 parent 4cf2cf8 commit f4e170c

File tree

3 files changed

+23
-24
lines changed

3 files changed

+23
-24
lines changed
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
package com.github.felipexw.util;
22

3+
import java.util.List;
4+
35
/**
46
* Created by felipe.appio on 23/08/2016.
57
*/
68
public abstract class Encoder {
79

8-
public static final String[] VALUES = {
9-
"A", "B", "C", "D", "F", "G", "H", "I", "J",
10-
"K", "L", "M", "N", "O", "P", "Q", "R", "S",
11-
"T", "U", "V", "X", "W", "Y", "Z"};
12-
13-
public abstract int encode(String word);
10+
public static final String[] VALUES = {
11+
"A", "B", "C", "D", "F", "G", "H", "I", "J",
12+
"K", "L", "M", "N", "O", "P", "Q", "R", "S",
13+
"T", "U", "V", "X", "W", "Y", "Z"};
1414

15+
public abstract double[] encodeFromList(List<String> word);
1516

17+
public abstract double encode(String word);
1618
}
Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
package com.github.felipexw.util;
22

3+
import java.util.List;
4+
35
/**
46
* Created by felipe.appio on 23/08/2016.
57
*/
68
public class StringEncoder extends Encoder {
7-
@Override
8-
public int encode(String word) {
9-
int encondedValue = 0;
109

11-
for(int i =0; i < word.length(); i++){
12-
for( byte j = 0; j < VALUES.length; j++){
13-
String c = String.valueOf(word.charAt(i));
14-
if (c.equalsIgnoreCase(VALUES[j]))
15-
encondedValue += (j+1);
16-
}
17-
}
18-
return encondedValue;
10+
@Override public double[] encodeFromList(List<String> words) {
11+
double[] encodedValues = new double[words.size()];
12+
13+
for (int i = 0; i < words.size(); i++) {
14+
String word = words.get(i);
15+
encodedValues[i] = word.hashCode();
1916
}
17+
18+
return encodedValues;
19+
}
20+
21+
@Override public double encode(String word) {
22+
return word.hashCode();
23+
}
2024
}
Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
package com.github.felipexw.classifier.bayes;
2-
31
import org.junit.Test;
42

53
/**
@@ -9,10 +7,5 @@ public class MultinomialNaiveBayesClassifierTest {
97

108
@Test
119
public void it_should_fail(){
12-
for(int i =0; i < 2; i++){
13-
String str = String.valueOf(i);
14-
System.out.println(str.hashCode());
15-
}
16-
1710
}
1811
}

0 commit comments

Comments
 (0)