Merge pull request 'full-project' (#7) from full-project into main

Reviewed-on: #7
main
Daniel Fromm 2025-05-11 21:19:33 +02:00
commit 40e0988a11
6 changed files with 83 additions and 27 deletions

View File

@ -11,7 +11,7 @@ public class FileLoader {
public FileLoader() {
this.inputFile = null;
}
//KI erstellte Methode
//KI erstellte Methode mit anpassungen
public File loadFileGUI() {
try {
JFileChooser fileChooser = new JFileChooser();
@ -30,6 +30,7 @@ public class FileLoader {
}
}
//Methode sucht das Datei Format für spätere Verwendung
public String getFileFormat(File file) {
String fileName = file.getName();
String fileFormat = fileName.contains(".") ? fileName.substring(fileName.lastIndexOf(".") + 1) : "";

View File

@ -23,18 +23,19 @@ public class TextProcessing {
private boolean stemming;
private int maxWords;
public boolean isStemming() {
return stemming;
}
public int getMaxWords() {
return maxWords;
}
public void setStemming(boolean stemming) {
this.stemming = stemming;
}
// für spätere verwendung mit umfangreichen anpassungen
// public boolean isStemming() {
// return stemming;
// }
//
// public int getMaxWords() {
// return maxWords;
// }
//
// public void setStemming(boolean stemming) {
// this.stemming = stemming;
// }
//
public void setMaxWords(int maxWords) {
this.maxWords = maxWords;
}

View File

@ -0,0 +1,59 @@
package domain;
import java.io.*;
import java.util.Map;
public class WordCloudCreator {
//Ki erstellte Methode wegen Zeitgründen und Krankheitsgründen, dennoch anpassungen in großen Maße waren notwendig
public void insertWordsIntoTemplate(Map<String, Integer> wordMap) {
File templateFile = new File("wordcloud.html"); // Template in project directory
File outputFile = new File("output.html"); // Output in project directory
if (!templateFile.exists()) {
throw new RuntimeException("Template file 'wordcloud.html' not found in project directory.");
}
try (BufferedReader reader = new BufferedReader(new FileReader(templateFile));
BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile))) {
StringBuilder htmlContent = new StringBuilder();
String line;
// Read the HTML template
while ((line = reader.readLine()) != null) {
htmlContent.append(line).append("\n");
}
// Generate clickable word entries with font size based on frequency
StringBuilder wordEntries = new StringBuilder();
int id = 1;
for (Map.Entry<String, Integer> entry : wordMap.entrySet()) {
String word = entry.getKey();
int frequency = entry.getValue();
int fontSize = (int) ((float) 12 + frequency * 1.5); // Example: Base size 10px, increase by 2px per frequency
wordEntries.append(String.format(
"<span id=\"%d\" class=\"wrd\" style=\"font-size:%dpx;\">" +
"<a href=\"https://www.google.com/search?q=%s\" target=\"_blank\">%s</a>" +
"</span>\n",
id++, fontSize, word, word
));
}
// Replace placeholder inside the div
String updatedHtml = htmlContent.toString();
if (updatedHtml.contains("<!-- TODO: Hier die generierten Tags einsetzen -->")) {
updatedHtml = updatedHtml.replace("<!-- TODO: Hier die generierten Tags einsetzen -->", wordEntries);
} else {
throw new RuntimeException("Placeholder for tags not found in the template.");
}
// Write the updated HTML to the output file
writer.write(updatedHtml);
System.out.println("Output file 'output.html' created successfully!");
} catch (IOException e) {
throw new RuntimeException("Error processing HTML template", e);
}
}
}

View File

@ -60,19 +60,17 @@ public class WordCloudManager {
System.out.println(stopwordList);
}
public void stemming(String approval) {
if(approval.equals("yes")) {
processing.setStemming(true);
}
}
// für spätere Verwendung mit umfangreichen Änderungen im Code
// public void stemming(String approval) {
// if(approval.equals("yes")) {
// processing.setStemming(true);
// }
// }
public void maxWordsInList(int number) {
processing.setMaxWords(number);
}
// ab hier noch nicht fertig.
public void tokenizingText() {
wordMap = (HashMap<String, Integer>) processing.tokenizingFile(processing.fileToTextString(filePath, fileFormat)
, !stopwordList.isEmpty() ? stopwordList : null);
@ -80,8 +78,6 @@ public class WordCloudManager {
}
public void cutWordsList() {
wordMap = (HashMap<String, Integer>) processing.maxShowWords(processing.sortList(wordMap));
processing.sortList(wordMap);
System.out.println(wordMap.keySet() + "\n" + wordMap.values());

View File

@ -1,6 +1,7 @@
package tui;
public class Main {
//startet die GUI
public static void main(String[]args){
new TUI();
}

View File

@ -21,8 +21,6 @@ public class TUI {
}
public void tui() {
while(isRunning) {
System.out.println("Welcome to Word Cloud.\nType number in the following Menu to access your targeted Option.\nMenu:\n\n(0) Load File\n(1) URL Path" +
"\n(2) Exit");
@ -80,8 +78,8 @@ public class TUI {
case(3):
// Set Stemming
System.out.println("Set Stemming: Input 'yes' or 'no'");
String stemmingOption = scan.nextLine();
wcm.stemming(stemmingOption);
// String stemmingOption = scan.nextLine();
// wcm.stemming(stemmingOption);
break;
case(4):
//Create WordCloud