(plan): updated todos and interfaces

master
nicode3141 2026-11-12 16:32:27 +01:00
parent fbe88f01b9
commit 6acfd417e4
4 changed files with 75 additions and 18 deletions

View File

@ -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
}
}

View File

@ -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<String, Double[]> 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<String, Integer>[] inputText, int[] label){
double[] trainModel(Map<String, Map<String, Integer>>[] 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<String, Integer> inputText){
double[] predictGenre(Map<String, Integer> inputText, double[] weights, double bias){
// TODO: Fixed size array for each genre
// For each genre calcSum
return null;

View File

@ -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<String, Map<String, Integer>> countTrainData(Map<String, String> 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<String, Integer> countWords(String path, int limit){
// TODO: Scan text line by line and count already added Words.
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()
// 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<String, Integer> countCommonWords(String path, String[] vocabulary){
// TODO: Scan text line by line and count words from vocabulary.
return null;
}
}

View File

@ -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());
}
}