95 lines
3.2 KiB
Java
95 lines
3.2 KiB
Java
package genredct;
|
|
|
|
import de.nicode3141.genredct.Detector;
|
|
import de.nicode3141.genredct.GenreData;
|
|
import de.nicode3141.genredct.TextCounts;
|
|
import org.junit.jupiter.api.DisplayName;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
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);
|
|
TextCounts textCounts = new TextCounts(wordCounts, 10);
|
|
|
|
double[] weigths = {0.1d, 0.0d, -1.2d, 3.4d, 5.0d,9d, 0.0d};
|
|
double bias = 0.0d;
|
|
double sum = -0.11d;
|
|
assertEquals(sum, Detector.calcSum(textCounts, weigths, bias));
|
|
}
|
|
|
|
@DisplayName("Loads Genres")
|
|
@Test
|
|
public void testGenresLoad(){
|
|
GenreData.loadGenres("data/labels.csv");
|
|
}
|
|
|
|
@DisplayName("Count All Words")
|
|
@Test
|
|
public void testLoadAllWords(){
|
|
Map<String, List<String>> genreData = GenreData.loadGenres("data/labels.csv");
|
|
List<String> allPaths = genreData.values()
|
|
.stream()
|
|
.flatMap(List::stream)
|
|
.toList();
|
|
|
|
System.out.println("Genres: " + genreData.size());
|
|
System.out.println("Total paths: " + allPaths);
|
|
Map <String, Integer> vocabulary = GenreData.countWords(allPaths, 500);
|
|
}
|
|
|
|
@DisplayName("Count Words against Vocabulary")
|
|
@Test
|
|
public void testCountWords(){
|
|
Map<String, List<String>> genreData = GenreData.loadGenres("data/labels.csv");
|
|
List<String> allPaths = genreData.values()
|
|
.stream()
|
|
.flatMap(List::stream)
|
|
.toList();
|
|
|
|
System.out.println("Genres: " + genreData.size());
|
|
System.out.println("Total paths: " + allPaths);
|
|
Map <String, Integer> vocabulary = GenreData.countWords(allPaths, 500);
|
|
|
|
TextCounts textCounts = GenreData.countCommonWords("data/train/adventure/2154_around-the-world-in-eighty-days-junior-deluxe-edit.txt", vocabulary.keySet());
|
|
}
|
|
|
|
@DisplayName("Count training words against Vocabulary")
|
|
@Test
|
|
public void testCountTrainingWords(){
|
|
Map<String, List<String>> genreData = GenreData.loadGenres("data/labels.csv");
|
|
List<String> allPaths = genreData.values()
|
|
.stream()
|
|
.flatMap(List::stream)
|
|
.toList();
|
|
|
|
System.out.println("Genres: " + genreData.size());
|
|
System.out.println("Total paths: " + allPaths);
|
|
Map <String, Integer> vocabulary = GenreData.countWords(allPaths, 500);
|
|
|
|
Map<String, List<TextCounts>> trainingCounts = GenreData.countTrainData(genreData, vocabulary.keySet());
|
|
}
|
|
|
|
@DisplayName("Test Detector Contructor")
|
|
@Test
|
|
public void testDetector(){
|
|
Detector genreDetector = new Detector("data/labels.csv");
|
|
IO.println(genreDetector.modelData);
|
|
}
|
|
}
|