diff --git a/src/main/java/de/nicode3141/Main.java b/src/main/java/de/nicode3141/Main.java index a6b06d8..290e129 100644 --- a/src/main/java/de/nicode3141/Main.java +++ b/src/main/java/de/nicode3141/Main.java @@ -1,11 +1,18 @@ package de.nicode3141; +/** + * Copyright 2026 Nicolas Pfeifer nicodenetworks.com + * - + * This class is mainly for handling user dialog in the console + */ public class Main { public static void main(String[] args){ - - } + // User Dialog - public static int testTest(){ - return 1; + // Start training + // List params and weights + + // User input text + // Predict genre } } diff --git a/src/main/java/de/nicode3141/genredct/Detector.java b/src/main/java/de/nicode3141/genredct/Detector.java index c8e0586..e48836a 100644 --- a/src/main/java/de/nicode3141/genredct/Detector.java +++ b/src/main/java/de/nicode3141/genredct/Detector.java @@ -1,9 +1,45 @@ package de.nicode3141.genredct; import java.util.Map; +import java.util.Objects; public class Detector { + private final int weightsCount = 500; + private Map modelData; + private final String[] vocabulary; + + /** + * Starts the training with provided data + * @param csvPath path of the csv containing all texts + * @return created weights for each genre + bias + */ + public Detector(String csvPath, String vocabulary) { + // Build common vocabulary + // Get labels and WordCounts from countTrainData() + // trainModel with labels and WordCount + // returns weights + this.modelData = null; + this.vocabulary = new String[weightsCount]; + } + + /** + * Stores the training data as a .bin file + * @param pathTo where to store .bin + */ + public void exportModel(String pathTo){ + // TODO: use BufferedOutputStream + // For each element in the map, write Key, write weights, write bias + } + + /** + * Imports the training data from a .bin file + * @param pathTo where .bin is located + */ + public void importModel(String pathTo){ + // TODO: use BufferedInputStream + } + /** * Calculates the sum of weighted word counts for a text * @param inputText word count to the common vocabulary @@ -20,10 +56,9 @@ public class Detector { /** * Adjust the weights of a genre for correct result * @param inputText word count of all texts to the common vocabulary - * @param label 0 if text isn't part of current genre, 1 if it is * @return final weights for a genre */ - double[] trainModel(Map[] inputText, int[] label){ + double[] trainModel(Map>[] inputText){ // TODO: Start with all weights = 0.0, bias = 0.0 // Then loop thru multiple epochs: // Loop thru all texts, calculate the sum @@ -36,9 +71,11 @@ public class Detector { /** * Predicts which genre the text belongs to * @param inputText word count of the text to test to the common vocabulary + * @param weights weights array for current genre + * @param bias bias for current genre * @return array with value for each genre, contains the calculated sum */ - double[] predictGenre(Map inputText){ + double[] predictGenre(Map inputText, double[] weights, double bias){ // TODO: Fixed size array for each genre // For each genre calcSum return null; diff --git a/src/main/java/de/nicode3141/genredct/GenreData.java b/src/main/java/de/nicode3141/genredct/GenreData.java index bf69477..0770420 100644 --- a/src/main/java/de/nicode3141/genredct/GenreData.java +++ b/src/main/java/de/nicode3141/genredct/GenreData.java @@ -1,6 +1,5 @@ package de.nicode3141.genredct; -import java.util.List; import java.util.Map; public class GenreData { @@ -16,13 +15,22 @@ public class GenreData { } /** - * Counts top X words of a textfile - * @param path source plain textfile + * Counts all words against the common vocab and categorizes them to their genre. + * @param texts label, path of the genre texts + * @return Map key: genre, value: (Map: key: word, value: count) + */ + public static Map> countTrainData(Map texts){ + return null; + } + + /** + * Counts top X words of all textfiles + * @param paths source plain textfiles * @param limit only counts the top (limit) words * @return LinkedMap key: word, value: count */ - public static Map countWords(String path, int limit){ - // TODO: Scan text line by line and count already added Words. + public static Map 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() // The ArrayList could contain the entrySet of the Map @@ -30,4 +38,15 @@ public class GenreData { // LinkedHashMap would make sense here, because of the ordering return null; } + + /** + * Counts top X words which are in the vocabulary of a textfile + * @param path source plain textfile + * @param vocabulary words to count + * @return LinkedMap key: word, value: count + */ + public static Map countCommonWords(String path, String[] vocabulary){ + // TODO: Scan text line by line and count words from vocabulary. + return null; + } } diff --git a/src/test/java/AuthorTests.java b/src/test/java/AuthorTests.java index fccc735..a6fe164 100644 --- a/src/test/java/AuthorTests.java +++ b/src/test/java/AuthorTests.java @@ -7,10 +7,4 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; public class AuthorTests { - - @DisplayName("Test Test") - @Test - public void testTest() { - assertEquals(1, Main.testTest()); - } }