(test): test expected behavior
parent
6acfd417e4
commit
a5a0dede86
|
|
@ -47,7 +47,7 @@ public class Detector {
|
|||
* @param bias constant to adjust the perceptron
|
||||
* @return sum of all weighted word counts
|
||||
*/
|
||||
double calcSum(Map<String, Integer> inputText, double[] weights, double bias){
|
||||
public static double calcSum(Map<String, Integer> inputText, double[] weights, double bias){
|
||||
// TODO: loop thru the map and add the (word count / total words) * weight to it
|
||||
// After the loop, increment the sum by the bias
|
||||
return 0.0d;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package de.nicode3141.genredct;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class GenreData {
|
||||
|
|
@ -7,19 +8,20 @@ public class GenreData {
|
|||
/**
|
||||
* This method gets all books and their corresponding label
|
||||
* @param csvPath Path of the labels.csv file
|
||||
* @return Map key: genre, value: path
|
||||
* @return Map key: genre, value: paths
|
||||
*/
|
||||
public static Map<String, String> loadGenres(String csvPath){
|
||||
// TODO: Loop thru all paths and return a Map of <label, path>
|
||||
public static Map<String, List<String>> loadGenres(String csvPath){
|
||||
// TODO: Loop thru all paths and return a Map of <label, paths>
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts all words against the common vocab and categorizes them to their genre.
|
||||
* @param texts label, path of the genre texts
|
||||
* @param vocabulary common top X words to count against
|
||||
* @return Map key: genre, value: (Map: key: word, value: count)
|
||||
*/
|
||||
public static Map<String, Map<String, Integer>> countTrainData(Map<String, String> texts){
|
||||
public static Map<String, List<Map<String, Integer>>> countTrainData(Map<String, List<String>> texts, String[] vocabulary){
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -29,7 +31,7 @@ public class GenreData {
|
|||
* @param limit only counts the top (limit) words
|
||||
* @return LinkedMap key: word, value: count
|
||||
*/
|
||||
public static Map<String, Integer> countWords(String paths[], int limit){
|
||||
public static Map<String, Integer> countWords(String[] paths, int limit){
|
||||
// TODO: Scan texts line by line and count already added Words.
|
||||
// If word was not present, add it to the Map.
|
||||
// After that, sort the Map. Simple with ArrayList sort()
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
import de.nicode3141.Main;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
public class AuthorTests {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package genredct;
|
||||
|
||||
import de.nicode3141.genredct.Detector;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class DetectorTests {
|
||||
@DisplayName("Calculate Sum")
|
||||
@Test
|
||||
public void testCalcSum(){
|
||||
// For the text: The locked room held three suspects, yet nobody held keys.
|
||||
int totalWords = 10;
|
||||
Map<String, Integer> wordCounts = new HashMap<>();
|
||||
wordCounts.put("the", 1);
|
||||
wordCounts.put("suspects", 1);
|
||||
wordCounts.put("nobody", 1);
|
||||
wordCounts.put("a", 0);
|
||||
wordCounts.put("another", 0);
|
||||
wordCounts.put("after", 0);
|
||||
|
||||
double weigths[] = {0.1d, 0.0d, -1.2d, 3.4d, 5,9d, 0.0d};
|
||||
double bias = 0.0d;
|
||||
double sum = -0.11d;
|
||||
assertEquals(sum, Detector.calcSum(wordCounts, weigths, bias));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
package genredct;
|
||||
|
||||
import de.nicode3141.genredct.GenreData;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class GenreDataTests {
|
||||
|
||||
@DisplayName("Test Training Word Count against vocabulary")
|
||||
@Test
|
||||
public void testCountTrainInputString(){
|
||||
String[] vocabulary = {"the, suspects, nobody, a, another, after"};
|
||||
|
||||
List<String> texts = new ArrayList<>();
|
||||
texts.add("The locked room held three suspects, yet nobody held keys.");
|
||||
Map<String, List<String>> textGenres = new HashMap<>();
|
||||
textGenres.put("mystery", texts);
|
||||
|
||||
Map <String, Integer> expectedWordCount = new HashMap<>();
|
||||
expectedWordCount.put("the", 1);
|
||||
expectedWordCount.put("suspects", 1);
|
||||
expectedWordCount.put("nobody", 1);
|
||||
expectedWordCount.put("a", 0);
|
||||
expectedWordCount.put("another", 0);
|
||||
expectedWordCount.put("after", 0);
|
||||
|
||||
List<Map<String, Integer>> expectedWordCounts = new ArrayList<>();
|
||||
expectedWordCounts.add(expectedWordCount);
|
||||
Map<String, List<Map<String, Integer>>> expected = new HashMap<>();
|
||||
expected.put("mystery", expectedWordCounts);
|
||||
|
||||
assertEquals(expected, GenreData.countTrainData(textGenres, vocabulary));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue